Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it ok to restart browser between specs in Integration Tests?

We have number or Protractor/Jasmine specs for our AngularJS-based project. Is it ok to do:

afterAll(function(){
   browser.restart();
}

to clean up things between specs?

like image 572
Artem Vorobyev Avatar asked Oct 31 '22 12:10

Artem Vorobyev


1 Answers

There is a built-in setting - restartBrowserBetweenTests:

// If true, protractor will restart the browser between each test.
// CAUTION: This will cause your tests to slow down drastically.
restartBrowserBetweenTests: false,

As it says in the comment - this leads to slowing down your tests - make sure there is a real reason to restart the browser between tests. Note that the setting means restarting browser with each it(), not describe().

Note that internally restart() forks an existing driver instance, quits the current driver and reinitializes all the globals - browser, element, $ etc.

There could be different needs to restart the browser/driver in between of the tests - for instance, previously created cookies would be completely lost/removed. For instance, this may allow not logging out explicitly after each test to save time (not sure if this is good in general).


So as a shortcut (till I will not find the real issue with promises) I want to just restart browser after each spec. I understand that it is a wrong approach in general, but want to use it as a temporary solution.

As a temporary solution in your case, to enforce test isolation, I think it's okay to restart the browser after every test suite. But, make sure you don't share any variables through the globally available browser object - in every test, you'll get a brand new browser.


By the way, you may also try enforcing the browser's private/incognito mode:

multiCapabilities: [
    {
        browserName: "chrome",
        chromeOptions: {
            args: ["incognito", "disable-extensions"]
        },
     }
],
like image 77
alecxe Avatar answered Nov 09 '22 12:11

alecxe