問(wèn)題描述
describe('The feature', function() {
beforeEach(function () {
browser.executeScript('localStorage.setItem("key","value");');
});
it('should do this', function() {
});
});
但是當(dāng)使用 chromedriver 2.10 和 chrome 37 對(duì) selenium 運(yùn)行測(cè)試時(shí)出現(xiàn)此錯(cuò)誤
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)
知道問(wèn)題出在哪里嗎?
推薦答案
根據(jù) 在量角器測(cè)試中從 localStorage 中刪除一個(gè)項(xiàng)目,當(dāng)您嘗試訪問(wèn) localStorage 而不點(diǎn)擊瀏覽器時(shí)會(huì)發(fā)生這種情況(例如,browser.get
) 在您使用 Chrome 驅(qū)動(dòng)程序時(shí)首先.解決方案似乎是首先點(diǎn)擊瀏覽器(可能是您的根頁(yè)面)以在 Chrome 中加載一個(gè)頁(yè)面,以便您可以操作 localStorage.這至少是我為我們的項(xiàng)目所做的.希望這會(huì)有所幫助!
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!
這篇關(guān)于在量角器測(cè)試中從 localStorage 設(shè)置項(xiàng)目的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!