Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: Open new webdriver after every describe?

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."

like image 860
frieman Avatar asked Nov 26 '25 13:11

frieman


2 Answers

You 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 completed 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
});
like image 71
giri-sh Avatar answered Nov 28 '25 04:11

giri-sh


May be you want to empty browser's local storage?

afterEach(function() {
    browser.executeScript('window.sessionStorage.clear();');
    browser.executeScript('window.localStorage.clear();');
});`
like image 20
Artem Jackson Avatar answered Nov 28 '25 03:11

Artem Jackson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!