Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
821 views
in Technique[技术] by (71.8m points)

angularjs - Remove an item from localStorage in a protractor test

I am trying to remove an entry in the localStorage from a protractor test

describe('The feature', function() {

  beforeEach(function() {
    browser.executeScript('localStorage.removeItem("key");');
  });

  it('should do this', function() {

  });
});

but i get this error when the test is run in chrome

UnknownError: <unknown>: Access to 'localStorage' is denied for this document. Storage is disabled inside 'data:' URLs.
  (Session info: chrome=32.0.1700.77)
  (Driver info: chromedriver=2.8.241036,platform=Mac OS X 10.9.0 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 436 milliseconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:11:15'
System info: host: 'MyPC.local', ip: '192.168.1.1', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.9', java.version: '1.7.0_45'
Session ID: 23c01c8f756c653a6345e4b2f20c06e5
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=MAC, acceptSslCerts=true, javascriptEnabled=true, browserName=chrome, chrome={userDataDir=/var/folders/9h/6j5pzftn4sxdw3rt25ffrqx80000gn/T/.org.chromium.Chromium.xrCG1d}, rotatable=false, locationContextEnabled=true, version=32.0.1700.77, takesHeapSnapshot=true, cssSelectorsEnabled=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false, nativeEvents=true, webStorageEnabled=true, applicationCacheEnabled=false, takesScreenshot=true}]
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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();');
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...