我正在使用 ngStorage
处理 AngularJS 应用中的本地存储和 Protractor 到 e2e 规范。
describe('Test', function() {
beforeEach(function () {
browser.driver.manage().window().setSize(1280, 1024)
browser.get('http://localhost:9000/#/test/first-test')
})
it("keeps the alternative marked", function () {
element(by.id('element')).click()
browser.refresh()
expect(element(by.id('element')).isSelected()).toBe(true)
})
})
结果:
1) Test keeps the alternative marked
Message:
Expected false to be true.
Stacktrace:
Error: Failed expectation
at [object Object].<anonymous> (path/spec/test_spec.js:12:52)
我认为 browser.refresh()
会清除本地存储。有没有办法保留它或其他方法来测试同样的东西?
最佳答案
我一直遇到同样的问题,但我认为这与 browser.refresh()
行为无关。 ngStorage
似乎存在时间问题,实际上更新了 localStorage
中的内容。
可以在https://github.com/gsklee/ngStorage/blob/master/ngStorage.js#L205中看到ngStorage
在 $rootScope 上发生更改后等待 100 毫秒以实际保存到 localStorage
。
我所看到的与此非常一致:有时关闭的项目在重新加载后仍然隐藏,有时则不然。如果我在刷新调用之前放置一个明确的 browser.waitForAngular()
,测试会更频繁地通过,但不是每次都通过。到目前为止,我发现的最可靠的方法是在通过 ngStorage
。顺便说一下,这似乎是 ngStorage
在它自己的测试中使用的方法。
值得注意的是 ngStorage
中的 onbeforeunload
处理程序应该处理这种特殊情况,但在 browser.refresh 时似乎没有这样做是正确的()
被调用。
关于javascript - 使用 ngStorage 进行 Protractor 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28108148/