Joã*_*ira 5 javascript testing frontend angularjs protractor
我刚开始使用angularjs并需要一些帮助.我正在使用ngStorage来处理AngularJS应用程序中的本地存储和量角器到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)
})
})
Run Code Online (Sandbox Code Playgroud)
结果:
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)
Run Code Online (Sandbox Code Playgroud)
我认为browser.refresh()会清除本地存储.有办法保持它或其他方式测试同样的事情?
谢谢你的进步.
我也遇到过同样的问题,但我认为这与行为无关browser.refresh()。看起来ngStorage实际更新内容存在时间问题localStorage。
您可以在https://github.com/gsklee/ngStorage/blob/master/ngStorage.js#L205中看到,ngStorage在 $rootScope 更改后等待 100 毫秒才能实际保存到localStorage.
我所看到的与此非常一致:有时被驳回的项目在重新加载后仍然隐藏,有时则不然。如果我在刷新调用之前显式放置browser.waitForAngular(),测试会更频繁地通过,但不是每次都会通过。到目前为止,我发现的最可靠的事情是在browser.sleep(125);通过. 顺便说一句,这似乎是它自己的测试中使用的方法。localStoragengStoragengStorage
值得注意的是,onbeforeunload处理程序ngStorage应该处理这种特殊情况,但在browser.refresh()调用时似乎没有这样做正确的事情。
| 归档时间: |
|
| 查看次数: |
193 次 |
| 最近记录: |