量角器 - 清空本地存储 [英] Protractor - empty local storage

查看:18
本文介绍了量角器 - 清空本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Protractor(与 Jasmine)来测试我的 AngulaJs 应用程序.

I'm using Protractor (with Jasmine) to test my AngulaJs application.

由于我的一些操作,我得到了一些保存在 localStorage 中的数据.现在我需要测试其他情况,所以我需要清空我的存储空间(或者最好只删除一些项目)但是如果我尝试运行:

As result of some of my action I get some data saved in the localStorage. Now I need to test other case, so I need to empty my storage (or better delete only some items) but If I try to run:

browser.executeScript('localStorage.removeItem("config");');

我收到以下错误:

UnknownError: <unknown>: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.
  (Session info: chrome=35.0.1916.153)
  (Driver info: chromedriver=2.10.267517,platform=Mac OS X 10.9.2 x86_64)

你知道怎么解决吗?

提前致谢

推荐答案

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

Another potential solution is to put any state clearing in an afterEach, which will run after any test is run: (see https://github.com/angular/protractor/issues/188)

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

这篇关于量角器 - 清空本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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