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?
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"]
},
}
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With