gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 21:03:26 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com