Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor - empty local storage

I'm using Protractor (with Jasmine) to test my AngulaJs application.

As result of some of my action I get some data saved in the localStorage. Now I need to test other case, so I need to empty my storage (or better delete only some items) but If I try to run:

browser.executeScript('localStorage.removeItem("config");'); 

I get the following error:

UnknownError: <unknown>: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.   (Session info: chrome=35.0.1916.153)   (Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.2 x86_64) 

Any idea on how to solve?

Thanks in advance

like image 794
teone Avatar asked Jun 13 '14 12:06

teone


1 Answers

Another potential solution is to put any state clearing in an afterEach, which will run after any test is run: (see https://github.com/angular/protractor/issues/188)

afterEach(function() {     browser.executeScript('window.sessionStorage.clear();');     browser.executeScript('window.localStorage.clear();'); }); 
like image 85
Anthony Panozzo Avatar answered Sep 23 '22 18:09

Anthony Panozzo