【问题标题】:Protractor testing with ngStorage使用 ngStorage 进行量角器测试
【发布时间】:2015-03-22 09:19:23
【问题描述】:

我正在使用 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)
  })
})

结果:

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() 会清除本地存储。有没有办法保留它或另一种方法来测试相同的东西?

【问题讨论】:

    标签: javascript angularjs testing protractor ng-storage


    【解决方案1】:

    我也遇到过同样的问题,但我认为这与 browser.refresh() 的行为无关。 ngStorage 实际上更新 localStorage 中的内容似乎存在时间问题。

    您可以在https://github.com/gsklee/ngStorage/blob/master/ngStorage.js#L205 中看到ngStorage 在$rootScope 发生更改后等待100 毫秒才能实际保存到localStorage

    我所看到的与此非常一致:有时被解雇的项目在重新加载后仍然隐藏,有时则不会。如果我在刷新调用之前添加一个明确的browser.waitForAngular(),测试会更频繁地通过,但不是每次都通过。到目前为止,我发现的最可靠的事情是在通过ngStorage 更改localStorage 的每个操作之后添加一个明确的browser.sleep(125);。顺便说一句,这似乎是ngStorage 在它自己的测试中使用的方法。

    值得注意的是,ngStorage 中的 onbeforeunload 处理程序应该处理这种特殊情况,但在调用 browser.refresh() 时似乎没有这样做。

    【讨论】:

    猜你喜欢
    • 2015-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多