2

在为网站编写自动化测试时,我得到了以下非常奇怪的错误,这里是相关的代码行:

  68    let selected
  69    if( params.includes('-RB') ){
  70         let books = Selector('.actions > .link-learn > div').withText('VIEW PRODUCT')
  71         const index = books.count
  72         selected = books.nth( Math.floor(Math.random() * index) );
  73     }

testcafe 在第 72 行提出以下投诉。

 "index" argument is expected to be a number, but it was number.

并且在我的程序中没有以名称编号命名的字符串、变量等。那么这个错误是什么意思,也许这个错误应该抛出一个稍微更清楚的不同消息。

谢谢

4

1 回答 1

5

你错过await了 71 号线。一定是

const index = await books.count

如果没有await,您将获得一个 Promise 包装器,而不是实际的count属性。在下一行,Promise 在表达式中变成NaN(不是数字) 。Math.random() * index类型验证失败,因为NaN不是一个有效的数字,而是在 JavaScript 中NaN属于该number类型,在错误信息中报告。这就是错误报告有愚蠢expected to be a number, but it was number信息的原因。

感谢您的反馈并帮助我捕获错误,我已经创建了一个关于它的问题:https ://github.com/DevExpress/testcafe/issues/2470 。我想我们会在下一个版本中修复它。

于 2018-05-30T07:47:45.883 回答