29

We would love to adopt Nightwatch.js for testing on browsers, but we're stuck on one major caveat: at the time of this writing, Nightwatchjs does not support running different tests using the same browser session. In short, it means that:

  • Creating the browser session is handled by the Nightwatch module from lib/index.js, in the startSession function;
  • Killing the browser would correspond to the delete command place in the Selenium action queue in the terminate function of that module;
  • A new Nightwatch client is created at every test run, which happens every time we load a different test file;

According to this source, it is possible to reuse the current browser session in Selenium, instead of opening a new window.

Has anyone managed to fix this problem in Nightwatch?

Here's the feature request on Github, which was requested on Mar 31, 2014 and is still open.

Another approach would be to circumvent the problem altogether by getting Nightwatch to merge all different files into one Test Suite, but that seems to be harder to solve than the problem with sessions...

Community
  • 1
  • 1
Wallace Sidhrée
  • 9,305
  • 6
  • 43
  • 55
  • 3
    I have come up with a solution that runs all the tests in one browser session. It does not solve the problem but it did the trick for me: https://github.com/dreamyguy/sidhree-com/commit/67d5a492a6e5d895a33905868d5298d57b352e9d The idea is to flatten all tests to one folder, require every file in a single one and run Nightwatch against that file. In this case `./bin/nightwatch --test tests/browser/nightwatch.js`. – Wallace Sidhrée Mar 08 '16 at 21:28
  • For running different tests, you can use nightwatch-cucumber, you can set up scenarios, so the whole session can has many scenarios(each one is a test) :https://github.com/mucsi96/nightwatch-cucumber/ , and it does all tests in a browser session. – Raymond Aug 21 '17 at 06:12
  • Possible duplicate of [Reuse the browser session for Selenium WebDriver for Nightwatch.js tests](https://stackoverflow.com/questions/27026363/reuse-the-browser-session-for-selenium-webdriver-for-nightwatch-js-tests) – Stratos Ion Feb 02 '18 at 13:40
  • what @WallaceSidhrée suggested did the trick case. congrats! – Panos Vakalopoulos Oct 30 '18 at 14:42
  • Do you need to run your tests in an already open browser? – JRichardsz Nov 07 '20 at 04:55

0 Answers0