javascript - TestCafe - 断言不起作用(测试的对象必须是数组等)

标签 javascript testing automated-tests assertion testcafe

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

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

我的脚本有问题还是什么?

最佳答案

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

关于javascript - TestCafe - 断言不起作用(测试的对象必须是数组等),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58971694/

相关文章:

javascript - 从外部 iframe 启动全屏

Javascript 函数未在所需字段中给出算术值

JavaScript : how to use delegate on each dynamically added div

java - 在多台远程机器上运行并行 junit 测试

xcode - ld : symbol(s) not found for architecture i386 Xcode unit tests

python:测试输出(...不是单元测试?)

selenium - 如何复制浏览器崩溃以进行自动化测试

javascript - VueJS : `v-for` not rendering elements

python - 为 `mock.patch` 制作包装器

testing - 我如何断言接受 JUnit 中的多个可能值之一