Reputation: 2031
During automated testing of a typical SPA page should the browser be closed after each scenario run by selenium e2e tests or should it remain open?
The pro I see in closing and opening the browser after each larger scenario is that the context is fresh and there should be no problems like caching issues or other dependencies etc. However maybe it's enough to do a hard refresh instead of closing the browser?
The pro in leaving browser window open is the speed of e2e tests in overall - closing browser and starting fresh session always takes time, in our case the difference between both is 20% faster when leaving browser open.
My question is: are there any other potential problems when leaving the browser open and running all tests in one browser session?
Upvotes: 0
Views: 854
Reputation: 16
I hope below options may help you.
driver.close()
.driver.manage().deleteAllCookies();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
capabilities.setCapability("chrome.switches", Arrays.asList("--incognito"));
Upvotes: 0
Reputation: 4336
I am doing it myself by closing the browser and starting a fresh one each run. Like you said it will provide you with a fresh context. Another reason for this is that I can set custom settings for each testcase. In my case I am performing a lot of downloads. I'm making sure each testcase does the download to its own folder by changing the firefox/chrome settings before each testcase.
Another major reason why I'm closing and opening the browser after each run is that it allows you to run your tests in parallel. This is not possible when using a single browser for all your testcases. Your tests will be even faster than the 20% when you don't close the browser if you run then im parallel.
Upvotes: 2