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

Keep browser instance open #12

Closed
louiscbotha opened this issue Nov 19, 2015 · 27 comments
Closed

Keep browser instance open #12

louiscbotha opened this issue Nov 19, 2015 · 27 comments

Comments

@louiscbotha
Copy link

Currently, new browser instances are opened and closed per feature. How do I force the browser session to stay open and for the features to reuse the same browser session?

Usually, one could add the background section to setup the scenario (login etc.) but your implementation doesn't seem to support background data.

@mucsi96
Copy link
Owner

mucsi96 commented Nov 19, 2015

I think this is a limitation of Selenium itself. Reusing Selenium session is considered a bad practice :( Because of session failure case.

@louiscbotha
Copy link
Author

Keeping the browser session open between features works perfectly with Nightwatch and Yadda. Take a look at https://github.com/kjelloe/Yadda-NightwatchJS. This also uses selenium with the chrome driver and works

@mucsi96
Copy link
Owner

mucsi96 commented Nov 20, 2015

That's great news! thanks. I will try to fix this

@mucsi96
Copy link
Owner

mucsi96 commented Nov 26, 2015

I checked the Yadda-NightwatchJS integration. I think it is not perfect because it is mapping all feature files into a single nightwatch test. This will give strange output from Nightwatch This implementation is mapping multiple feature files to multiple Nightwatch tests. That's why keeping browser instance open depends on a Nightwatch issue nightwatchjs/nightwatch#117

@louiscbotha
Copy link
Author

Wouldn't it be better to allow for this via a config setting? This could temporarily solve the issue for some people but won't necessarily be the most ideal fix.

@volodya1805
Copy link

hey Igor. Any luck with that issue?

@mucsi96
Copy link
Owner

mucsi96 commented Jan 21, 2016

Not yet :( But for speed up I suggest to try paralell test execution.

"test_workers": true 

More details here

@volodya1805
Copy link

Yeah i know about paralell test execution, but that's the only one blocker why we don't use this module.

@volodya1805
Copy link

Igor, can you please give me an update on that. If you are not going to fix that in the near feature we are going to search any other solution instead of using your nightwatch + cucmber integration.

@mucsi96
Copy link
Owner

mucsi96 commented Jan 26, 2016

I started to work on this. I can see two possible solutions for this:

For cucumber runner mode we can create an additional option to use single browser session like in https://github.com/kjelloe/Yadda-NightwatchJS

What do you think?

@volodya1805
Copy link

I think it's ok since we can use browser stack for parallel execution - right?

@mucsi96
Copy link
Owner

mucsi96 commented Jan 26, 2016

Ok. I plan to fix it this week.

@volodya1805
Copy link

if it quick fix - please add a check for now: if we execute the latest scenario from the current feature in this case close browser otherwise keep browser instance open

@volodya1805
Copy link

because right now instances are opened and closed per every screnario in the feature. Is it expected?

@mucsi96
Copy link
Owner

mucsi96 commented Jan 26, 2016

Yes because .end() is added after every scenario in the feature. This causes the problem nightwatchjs/nightwatch#117 (comment)

@anatoliyarkhipov
Copy link

Sorry if it's not a correct place for the question, but I think it's somehow related. Is there a way to keep nightwatch always run? Something like "live" or "interactive" mode, where Nightwatch can re-run the tests without rerunning everything else (Selenium, browser).

@mucsi96
Copy link
Owner

mucsi96 commented Dec 18, 2016

Hi! I am not sure I understand you correctly. Do you think about a REPL like executing node from terminal? Where you entera nightwatch command, hit Enter and it will be executed inbrowser using selenium?

@anatoliyarkhipov
Copy link

No, sorry. Let me try to explain. In this thread you made it possible to not close the browser after every scenario. It's very cool, it speeds up the tests.

And I want to go further, something like "watch" mode from unit tests frameworks, when they don't stop the process after running all tests but waits for files changes. In case of Nightwatch it means that it doesn't run Selenium and browser every time when I need to run the tests but keeps them opened.

Does it make sense?

@anatoliyarkhipov
Copy link

The main problem for me is slow start. When I'm working on a single test it prevents me from running it often. The test itself takes ~3 seconds but starting of it takes ~12 seconds. The most part of this time is the browser opening. It's why I'm asking about something like "watch" mode.

I tried to start Selenium in a parallel process, but it doesn't help, because Nightwatch is still opening the browser on every run.

It looks like I'm missing something obvious.

@anatoliyarkhipov
Copy link

Okay, I created an express proxy between Nightwatch and Selenium, and I cache the first created session while the proxy is running. So I can reuse the same browser window between test runs. It's still taking some time for running the Nightwatch itself, but the current situation is much better. My problem has gone, sorry for bothering 😅

@mucsi96
Copy link
Owner

mucsi96 commented Dec 21, 2016

Wow! Nice. I think creating a watch mode is a very good idea. But I feel that it should be part of the Nightwatch package. Not this one. I am closing this for now

@mucsi96 mucsi96 reopened this Dec 21, 2016
@mucsi96 mucsi96 closed this as completed Dec 21, 2016
@anatoliyarkhipov
Copy link

Actually, after the proxy, I implemented a "watch mode". Now it takes 0 seconds to re-run the tests. But my implementation uses some hacks and relies on the fact, that Runner#run is overloaded by nightwatch-cucumber. So I'm not sure where should I continue this discussion and should I continue it at all. If someone interested, I can split the "watch mode" code from our application code and puslish a repo.

@mucsi96
Copy link
Owner

mucsi96 commented Dec 21, 2016

I think this shoul be part of Nightwatch. But they are not very active now. I have an open pull request for month

@mucsi96
Copy link
Owner

mucsi96 commented Dec 21, 2016

This is the bad barts of open source

@tegomass
Copy link

+1

@cengiz-a
Copy link

I´m fascinated by the idea of a watch mode in nightwatch like nodejss nodemon. That method would save so much time! Could you show /share your solution with that express proxy? Thanks.

@anatoliyarkhipov
Copy link

Unfortunately, I switched my job and don't have access to the code. As I remember the "watch mode" consisted of two parts:

  1. The express proxy. It was pretty simple - it redirected every request to the real Selenium, but if it was a request to create a browser instance, than the proxy checked if it had been already created and returned its session ID if it had
  2. Another part was to override Runner#run and that was full of dirty hacks which I wouldn't be able to remember now

Actually, for now I use Cypress and it works just fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants