How to restart browser inside tests ?

1,818 views
Skip to first unread message

Doron Haskel

unread,
May 14, 2016, 9:13:56 AM5/14/16
to NightwatchJs
Hi,

Would like to measure page load time inside tests, meaning that I’m running loops for same flow several times and getting time passed.

In order to get a clean browser state I’ve found that it is not enough to clean the cookies (no API for Cache) and need to restart browser.

The problem that there is API for closing the browser but didn’t found how to start it over. It is done only by running a new tests method.

 

Would be happy to get any recommendation for the best approach for cleaning browser state of for starting it over.

 

Thanks in advanced, Doron.

Message has been deleted

Doron Haskel

unread,
May 18, 2016, 4:59:00 AM5/18/16
to NightwatchJs
Is starting Nightwatch browser can be done through tests ? any idea how to clear the browser state ?

Thanks

Doron Haskel

unread,
May 25, 2016, 9:37:54 AM5/25/16
to NightwatchJs
Hi, 

Still looking for advise ... 

Thanks

Eric Mumford

unread,
May 26, 2016, 12:09:38 AM5/26/16
to NightwatchJs
Hi Doron,

Nightwatch uses Selenium Webdriver bindings to create and destroy browser objects in memory. This varies somewhat by the driver you are using (Chromedriver, PhantomJS, Firefox etc) and times vary even more with remote drivers (Browserstack etc).

That being said, it is as easy as calling client.end() on your driver chain and starting up a new client.navigate() chain right underneath it in the same file if you wish. Nightwatch will handle closing out your browser, destroying associated cookies, and starting fresh.

Because this is a reasonably well known feature of Selenium, my suspicion is that your needs exceed these capabilities. When you say page load time, do you mean the time to load the server payload into memory? Do you mean the rendering time in the browser object? Do you mean time until an element is visible or is made hidden on screen? Do you mean something else?

Doron Haskel

unread,
May 26, 2016, 3:45:27 AM5/26/16
to NightwatchJs
Thank you Eric for responding !

I might missing something but can't find Nightwatch command for starting new browser after end(), 'init()'/"url()" are not working and the browser session is not started.

The objective is to measure load time by waiting for the elements that are important in page, I consider the tool overhead but for improvements measurements it can be efficient. 

Doron 

Eric Mumford

unread,
May 26, 2016, 9:56:40 AM5/26/16
to nightw...@googlegroups.com
Here’s an non-optimized example. There are many ways to do what you are describing, but only you will find the way that works best for you.

For the purposes of brevity I have included an imaginary object called YourTimerFunction which contains whatever timing features you want. The lines relevant to your query are bolded. Again, this is one of 50 ways you can accomplish what you’re seeking, I illustrate this example as over-simplified and non-optimized.


‘Launch a new browser for three different pages:': function (client) {
// Use the Nightwatch Page model to make variables out of CSS selectors
var firstPage = client.page.pagedef_firstPageCSSElementVariables();
var secondPage = client.page.pagedef_secondPageCSSElementVariables();
var thirdPage = client.page.pagedef_thirdPageCSSElementVariables();

var myTimer = YourTimerFunction();

myTimer.start();
firstPage
.navigate()
.waitForElementVisible('@buttonYouExpectToSeeRendered', 5000);
myTimer.stop();
myTimer.record(‘First Page response time:’);
client.end();

myTimer.start();
secondPage
.navigate()
.waitForElementVisible('@buttonYouExpectToSeeRendered', 5000);
myTimer.stop();
myTimer.record(’Second Page response time:’);
client.end();

myTimer.start();
thirdPage
.navigate()
.waitForElementVisible('@buttonYouExpectToSeeRendered', 5000);
myTimer.stop();
myTimer.record(’Third Page response time:’);
client.end();

--
You received this message because you are subscribed to a topic in the Google Groups "NightwatchJs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nightwatchjs/typcCit0E3I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nightwatchjs...@googlegroups.com.
To post to this group, send email to nightw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nightwatchjs/947340d0-4c86-4343-9804-94c9c016fd6c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Eric Mumford

unread,
May 26, 2016, 9:59:59 AM5/26/16
to nightw...@googlegroups.com
Another note - based on how you wrap this function, you made need to use javascript callbacks/promises to get the synchronous timing right. That’s not Nightwatch, that’s javascript programming, and you can find examples of that.

Doron Haskel

unread,
May 29, 2016, 3:53:07 AM5/29/16
to NightwatchJs
Thanks a lot Eri !!

I'm using your suggested approach for the times records, the problem that I'm facing is that I can't start the nightwatch object/browser/session after calling browser.end().
the only way I found is to trigger new Nighwatch tests method (tests case).

looking for cmd that initiate browser without moving to a new/different test case.

Doron 

Eric Mumford

unread,
Jun 7, 2016, 12:32:29 AM6/7/16
to NightwatchJs
Can you post code that isn't launching new browsers? Without code it's difficult to guess what thousands of ways your code isn't doing the thing that it could do.
Reply all
Reply to author
Forward
0 new messages