Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid browser restart (Strategies / Pitfalls) #117

Closed
phtrivier opened this issue Mar 31, 2014 · 31 comments
Closed

Avoid browser restart (Strategies / Pitfalls) #117

phtrivier opened this issue Mar 31, 2014 · 31 comments

Comments

@phtrivier
Copy link

Hi

Launching a folder of nightwatch tests modules typically launches a new browser for each test, making them longer than ideal.
Would that make sense to try and launch all tests using the same browser session ? Are there any "known" strategies to avoid this (ceating the browser in a global setUp / tearDown ?)

Thanks

@beatfactor
Copy link
Member

That's not currently possible unfortunately but it would make a valuable addition to have an option to reuse browser session, because in some cases that might not be desired.

@phtrivier
Copy link
Author

Ok, I'll give it a try.

@phtrivier
Copy link
Author

So i'm in the middle of trying stuff, just to see if that would make sense :

  • as far as I understand it, 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 ; my strategy was to try and pass the sessionId and api.capabilities around between two run, and only terminate the session at the very end of the run (not at every test)
  • I managed to pass the sessionId around, but only a single test is run, so maybe selenium stops the browser from another point, I'm still looking

Do you think I'm on the right track ?
Thanks

@phtrivier
Copy link
Author

And investigating a bit more, it seems like closing the selenium session is also done by using the 'end' function in a test (as seen in client-commands.js).

I (naively) tried to avoid calling the 'delete' command, but then the test runner never passes to the rest of the test, I'm not exactly sure why :

Original 'end' function :

end : function(callback) {
      var self = this;
       return this.session('delete', function(result) {
         client.sessionId = null;
         if (typeof callback === 'function') {
           callback.call(self, result);
        }
       });
}

My best guess (not sure what the flow of commands is)

end : function (callback) {

     // simulate calling the callback later
     setTimeout(function () {
            // ideally, I would avoid this, but I can keep the sessionId around to pass it to the
            // next client
            client.sessionId = null;
            if (typeof callback === 'function') {
                callback.call(self, {});
            }
      }, 50);

      // for chaining, although in most of my tests, 'end' is the last function called on the api
      return client.api;
}

@ghost
Copy link

ghost commented Apr 29, 2014

Maybe running tests parallel would increase the speed... In order to do that we need a parallel test runner...

Currently 1 test is 11 secs by me, and opening a new ff tab is 10 secs of 11...

@ghost
Copy link

ghost commented Apr 29, 2014

Hmm according to this: http://sqa.stackexchange.com/questions/1988/selenium-reuse-existing-browser-session-instead-of-opening-new-windows
It is possible to reuse selenium sessions...

@beatfactor
Copy link
Member

Yes, it is possible but it needs to be implemented and made configurable
via an options somewhere.

On Tue, Apr 29, 2014 at 6:07 PM, Jánszky László Lajos <
notifications@github.com> wrote:

Hmm according to this:
http://sqa.stackexchange.com/questions/1988/selenium-reuse-existing-browser-session-instead-of-opening-new-windows
It is possible to reuse selenium sessions...


Reply to this email directly or view it on GitHubhttps://github.com/beatfactor/nightwatch/issues/117#issuecomment-41696141
.

@dennym
Copy link

dennym commented Sep 26, 2014

Any progress on that?

@ryanoasis
Copy link

Any updates? Also how did you accomplish

"my strategy was to try and pass the sessionId and api.capabilities around between two run"

if you don't mind my asking?

@tslater
Copy link

tslater commented Nov 21, 2014

+1

@phtrivier
Copy link
Author

Nope, I don't have any progress to report here (I haven't been working on that for a while.) Sorry.

@mrzmyr
Copy link

mrzmyr commented Feb 10, 2015

+1

3 similar comments
@Limess
Copy link

Limess commented Feb 10, 2015

+1

@limsim
Copy link

limsim commented Feb 10, 2015

+1

@andymost
Copy link

+1

@ryanoasis
Copy link

@beatfactor any updates on when/if this might be coming?

I actually tried to step through the code and try to see how things worked and maybe even attempt to work on this myself but it seemed pretty complex and I don't want to spend time working on something that someone else has plans to do.

@beatfactor
Copy link
Member

Yeah, this would be a cool feature. Maybe you can use the new start_session flag to disable the automatic session creation and create your session independently somehow. Feel free to start working on this if you like.

@nyarenbee
Copy link

👍

@dreamyguy
Copy link

This is the only thing keeping us from adopting Nightwatch on our rig. We think it's awesome but starting a new session for every test file seems overkill and extremely time consuming.

If I only had the kung-fu necessary to get this done... 🙉

Has anyone found a way around this - or managed to run different files through a single Test Suite (which would circumvent the session problem)?

@sknopf
Copy link
Collaborator

sknopf commented Jul 31, 2015

@dreamyguy if keeping run time low is what you're after you can use the new parallel run feature - might be faster than running your tests serially + reusing browser session

@angelatlarge
Copy link

We'd find this a helpful feature as well: we run our tests on CI, and run into port contention between different CI jobs. Having a single selenium session would ensure that once we have a port we can hold on to it.

@finbarmaginn
Copy link

+1

2 similar comments
@mucsi96
Copy link

mucsi96 commented Nov 20, 2015

+1

@sonnenhaft
Copy link

+1

@quantuminformation
Copy link

+1

3 similar comments
@volodya1805
Copy link

+1

@aasierra
Copy link

+1

@GreenGremlin
Copy link

+1

@dreamyguy
Copy link

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:

dreamyguy/sidhree-com@67d5a49

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.

I'll make those requires more elegant by getting all filenames in that folder and iterating through them, instead of explicitly declaring each. Then I think the setup will be pretty robust.

@DutchKevv
Copy link

+1

@beatfactor
Copy link
Member

Thanks everyone for input. This has been open for far too long and no resolution is in sight, so it's time to close.

@nightwatchjs nightwatchjs locked and limited conversation to collaborators Aug 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests