gpt4 book ai didi

angularjs - 在 Protractor 测试中从 localStorage 中删除项目

转载 作者:行者123 更新时间:2023-12-02 22:33:53 27 4
gpt4 key购买 nike

我正在尝试从 Protractor 测试中删除 localStorage 中的条目

describe('The feature', function() {

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

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

});
});

但是当在 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}]

最佳答案

另一个潜在的解决方案是将任何状态清除放在 afterEach 中,它将在运行任何测试后运行:(请参阅 https://github.com/angular/protractor/issues/188 )

afterEach(function() {
browser.executeScript('window.sessionStorage.clear();');
browser.executeScript('window.localStorage.clear();');
});

关于angularjs - 在 Protractor 测试中从 localStorage 中删除项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21259235/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com