Set an item from localStorage in a protractor test

大憨熊 提交于 2019-11-29 02:58:38

问题


describe('The feature', function() {     
    beforeEach(function () {
       browser.executeScript('localStorage.setItem("key","value");');
    });

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

   });
});

but i get this error when the test is run against selenium with chromedriver 2.10 and chrome 37

Executing: [execute script: window.localStorage.setItem("key","value");, []])
15:31:29.747 WARN - Exception thrown
org.openqa.selenium.WebDriverException: <unknown>: Failed to read the 'localStorage'
property from 'Window': Storage is disabled inside 'data:' URLs.
(Session info: chrome=37.0.2062.120)
(Driver info: chromedriver=2.10.267518,platform=Linux 3.11.0-26-generic x86_64) (WARNING:  
The server did not provide any stacktrace information)

Any idea where the problem cam from ?


回答1:


According to one of the answers at Remove an item from localStorage in a protractor test, this happens when you try to access localStorage without hitting the browser (say, browser.get) first when you are using the Chrome driver. The solution seems to be to hit the browser first (maybe your root page) to get a page loaded in Chrome so that you can manipulate the localStorage. That at least is what I have been doing for our project. Hope this helps!



来源:https://stackoverflow.com/questions/26295844/set-an-item-from-localstorage-in-a-protractor-test

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!