【问题标题】:Protractor promise not resolving on declaration量角器承诺未解决声明
【发布时间】:2014-11-15 13:04:45
【问题描述】:

当我在不使用 Promise 的情况下执行语句时,它只会返回一个 Promise。

像下面这样不起作用:

devices = element.all(devicesRepeater)
expect(devices.length).toEqual factories.devices.length

但承诺风格有效:

element.all(devicesRepeater).then (devices)->
  expect(devices.length).toEqual factories.devices.length

但它在量角器 API 中显示它应该解析,例如: http://angular.github.io/protractor/#/api?view=ProtractorBy.prototype.

// Returns a promise that resolves to an array var rows = element.all(by.repeater('cat in pets'))

等待也是如此。就像在下面的问题中一样,等待块然后期望调用起作用:

How can I wait for a condition?

而在我的项目中,我必须将所有逻辑都放在 promise 回调块中。

我应该为每个人写一个 then 块还是有办法阻止直到 promise 解决。

【问题讨论】:

  • 希望这能引起注意,即使我使用了expect() ,我也遇到了无法解决的问题。
  • 长度不是 ElementArrayFinder 的属性。使用 count() 代替:devices = element.all(devicesRepeater) expect(devices.count()).toEqual factories.devices.length

标签: protractor


【解决方案1】:

长度不是 ElementArrayFinder 的属性。使用 count() 代替:

devices = element.all(devicesRepeater) expect(devices.count()).toEqual factories.devices.length

【讨论】:

  • 是的,从那以后我一直在使用 count。但是感谢您在此处添加它,以便其他人可以找到答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-14
  • 2016-05-04
  • 2019-07-07
  • 2014-08-08
  • 1970-01-01
  • 2020-03-16
相关资源
最近更新 更多