I need to open a new web driver after every describe (e2e test i run)
The reason is that i need to clear my browser cache (not cookies),
Every time i try to use ptor.quit()
/ browser.driver.quit()
, i get this exception:
"Error: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used."
I need to open a new web driver after every describe (e2e test i run)
The reason is that i need to clear my browser cache (not cookies),
Every time i try to use ptor.quit()
/ browser.driver.quit()
, i get this exception:
Share Improve this question edited Sep 5, 2015 at 9:38 giri-sh 6,9622 gold badges27 silver badges50 bronze badges asked Feb 2, 2014 at 15:25 friemanfrieman 312 silver badges4 bronze badges 2"Error: This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used."
-
5
If you are testing on chrome, you could try to run it in incognito mode.
capabilities: { 'browserName': 'chrome', 'chromeOptions': { 'args': ['incognito'] } }
– gontard Commented Feb 3, 2014 at 8:58 - 2 Careful if you need to take screenshots, etc. Incognito may block some functionality on account of the privacy features. – Wes Johnson Commented Dec 1, 2014 at 14:55
2 Answers
Reset to default 3You shouldn't start new webDriver session after each describe
, but in turn use afterAll()
functionality that Jasmine provides which runs after all specs in describe are finished running. In other words afterAll()
runs after each describe and will suffice your need. Do not quit after all your specs are pleted in a describe as it stops the webdriver execution itself. Here's how to do it -
afterAll(function() {
browser.executeScript('window.sessionStorage.clear();'); //clear session
browser.executeScript('window.localStorage.clear();'); //clear local storage
});
May be you want to empty browser's local storage?
afterEach(function() {
browser.executeScript('window.sessionStorage.clear();');
browser.executeScript('window.localStorage.clear();');
});`