我正在使用 TestCafe 并且在测试中有以下代码不起作用:
test('Verify contents of allocation', async (t) => {
await t
.click(accountManager.selectAccount(inputData.testAccount))
.click(homePage.icon)
.expect(7)
.eql(await dash.getPersonCount(inputData.totalAllocation));
});
上面代码的问题是 TestCafe 甚至在它到达测试的第一行之前就说“等待元素出现”然后永远卡住。我不知道为什么会这样。
当我对上述测试进行以下更改时,它就起作用了:
test('Verify contents of allocation', async (t) => {
await t
.click(accountManager.selectAccount(inputData.testAccount))
.click(homePage.icon);
const test = await dash.getPersonCount(inputData.totalAllocation);
await t
.expect(7)
.eql(test);
});
有没有一种简单的方法可以防止 TestCafe 卡住?
知道为什么它首先会卡住吗?
最佳答案
最佳做法是将枚举值放在实际字段中。当您使用 Selector's DOM node state property或 client function promise 作为断言中的实际值,TestCafe 激活智能断言查询机制。这种机制使您的测试稳定 - 在 TestCafe documentation 中查看更多信息. 因此,请按以下方式重写您的测试:
test('Verify contents of allocation', async (t) => {
await t
.click(accountManager.selectAccount(inputData.testAccount))
.click(homePage.icon)
.expect(dash.getPersonCount(inputData.totalAllocation)).eql(7);
});
在 expect
方法中使用 await
关键字的第一个示例中的问题与执行 dash.getPersonCount(inputData.totalAllocation)
在测试之前,因为这个 await
打断了测试链。
关于javascript - 在期望断言中使用 await async 时,TestCafe 卡住了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57527461/