One convenient built-in option is the restartBrowserBetweenTests
setting:
// Setting this to true will restart the browser between each test, slowing down the testing process.
// Use caution and ensure there is a valid reason for restarting the browser between tests.
restartBrowserBetweenTests: false,
Keep in mind that restarting the browser with each it()
block, not describe()
.
The internal function restart()
forks an existing driver instance, quits the current driver, and reinitializes all global objects like browser
, element
, and $
.
There may be various reasons to restart the browser/driver during tests, such as clearing previously set cookies. This approach could potentially save time by avoiding explicit logouts after every test.
In the meantime, I plan to restart the browser after each spec until I resolve my issues with promises. Although it's not the best practice, I see it as a temporary fix.
If temporarily restarting the browser after each test suite helps maintain test isolation in your scenario, it can be acceptable. Just ensure you don't rely on globally shared variables accessed through the browser
object, as each test will have a fresh browser
instance.
You might also experiment with enabling the browser's private or incognito mode:
multiCapabilities: [
{
browserName: "chrome",
chromeOptions: {
args: ["incognito", "disable-extensions"]
},
}
],