To get an item from local storage use window.localStorage.getItem()
through executeScript()
:
var value = browser.executeScript("return window.localStorage.getItem('key');");
expect(value).toEqual(expectedValue);
To clear local storage call clear()
:
browser.executeScript("window.localStorage.clear();");
We can also have this helper object/wrapper around the local storage for convenience:
"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();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…