在量角器测试中从localStorage设置项目 [英] Set an item from localStorage in a protractor test

查看:69
本文介绍了在量角器测试中从localStorage设置项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

   });
});

但是当我使用chromedriver 2.10和chrome 37对硒进行测试时,我得到了这个错误

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 ?

推荐答案

根据

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设置项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆