量角器 - 清除LocalStorage到Spec的丢失连接

时间:2017-02-16 01:56:15

标签: javascript selenium-webdriver protractor angular-local-storage

我正在使用window.localStorage.removeItem("name of localStorage variable you want to remove");删除规范中的两个不同的localStorage密钥,它们已成功删除。

下一步是进入我的应用程序的另一个页面以显示一个对话框,要求您因会话丢失而再次登录,但使用量角器执行此操作即使正确清除localStorage键也不行,但是手动完成(删除它们给出右键单击和删除),它会工作并弹出对话框。

可能是什么问题?

2 个答案:

答案 0 :(得分:0)

考虑完全擦除cookie,本地和会话存储,而不是仅擦除2个键。

browser.manage().deleteAllCookies();
browser.executeScript('window.sessionStorage.clear(); window.localStorage.clear();')

答案 1 :(得分:0)

您的网站似乎存储了不同域名或httponly Cookie的Cookie。

Webdriver只能删除您当前所在的同一域的Cookie。因此,如果您的API为您提供了一些authtoken - 它将不会被删除,因为它存储在不同的域中。 HTTPonly cookie也是如此。

selectEnrollment.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(selectEnrollment.isChecked()) {
                  mThis.updateState(1);
                } else {
                  mThis.updateState(-1);
                }
        });

我建议您导航到API网址,并在那里调用HttpOnly cookie An HttpOnly cookie cannot be accessed by client-side APIs, such as JavaScript. This restriction eliminates the threat of cookie theft via cross-site scripting (XSS). However, the cookie remains vulnerable to cross-site tracing (XST) and cross-site request forgery (XSRF) attacks. A cookie is given this characteristic by adding the HttpOnly flag to the cookie. 方法或在您的网站上手动注销