Protractor 应该查看 Chrome 的本地存储吗?

Should Protractor See Chrome's Local Storage?

我运行一个量角器测试(非常不相关的例子):

describe('Test something.', function(){
    it('Should do something', function(){
        browser.get('http://localhost:22222/something');
    });
})

这会将我带到我们的登录页面而不是 'something' 页面(检查本地存储中的令牌,但没有找到)。我已经登录并且在 Chrome 上的 LS 中有信息。我不明白为什么测试看不到它 - 我认为 Chrome 驱动程序 运行 在实际 Chrome 上,所以它应该使用与 [=] 相同的本地存储17=]...因为它是,你知道...Chrome。

it IS the same Chrome that I run 'by hand,' it DOES share local storage?

不,当您 运行 protractor 最初启动时 Chrome 是一个 "brand-new" 干净的 Chrome,具有空的本地存储、空的 cookie 等。

但是,您始终可以使用以下 "helper" 对象验证和管理本地存储:

"use strict";

var LocalStorage = function () {
    this.getValue = function (key) {
        return browser.executeScript("return window.localStorage.getItem('" + key + "');");
    };

    this.get = function () {
        browser.executeScript("return window.localStorage;");
    };

    this.clear = function () {
        browser.executeScript("return window.localStorage.clear();");
    };
};

module.exports = new LocalStorage();

另见:

  • Protractor - empty local storage