Set an item from localStorage in a protractor test(在量角器测试中从 localStorage 设置项目)
问题描述
describe('The feature', function() {
beforeEach(function () {
browser.executeScript('localStorage.setItem("key","value");');
});
it('should do this', function() {
});
});
但是当使用 chromedriver 2.10 和 chrome 37 对 selenium 运行测试时出现此错误
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)
知道问题出在哪里吗?
推荐答案
根据 在量角器测试中从 localStorage 中删除一个项目,当您尝试访问 localStorage 而不点击浏览器时会发生这种情况(例如,browser.get
) 在您使用 Chrome 驱动程序时首先.解决方案似乎是首先点击浏览器(可能是您的根页面)以在 Chrome 中加载一个页面,以便您可以操作 localStorage.这至少是我为我们的项目所做的.希望这会有所帮助!
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!
这篇关于在量角器测试中从 localStorage 设置项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在量角器测试中从 localStorage 设置项目


基础教程推荐
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- Chart.js 在线性图表上拖动点 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01