【问题标题】:TestCafe - assertions not working (object tested must be an array etc.)TestCafe - 断言不起作用(测试的对象必须是数组等)
【发布时间】:2020-03-17 04:40:47
【问题描述】:

我有一个非常简单的断言:

const mappingInput = 'input[data-test="appMS_mappingSite_inputField"]';
const mappingInputValue = "*";
.expect(mappingInput.value).contains(mappingInputValue, 'input contains *', { timeout: 500 })

但是当我运行测试时它失败了(尽管我知道 input.value 包含“*”。

错误信息如下:

AssertionError: input contains *: object tested must be an array, a
      map, an object, a set, a string, or a weakset, but undefined given

我的脚本有什么问题吗?

【问题讨论】:

    标签: javascript testing automated-tests assertion testcafe


    【解决方案1】:

    问题在于mappingInput 常量是一个字符串。字符串类型没有value 属性,因此表达式mappingInput.value 将始终返回undefined。 如果您使用 TestCafe,您可以通过Selector API 访问测试页面上的输入值。以下示例可能适合您的需求:https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/using-selectors.html#define-assertion-actual-value

    【讨论】:

    • 很抱歉回复晚了,但正忙于工作。它工作得非常完美。谢谢。
    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 2011-11-18
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2020-11-14
    相关资源
    最近更新 更多