javascript - 在期望断言中使用 await async 时,TestCafe 卡住了

标签 javascript testing e2e-testing assertion testcafe

我正在使用 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 propertyclient 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/

相关文章:

ruby - 验证包含值时出现验证错误 :Rails

java - 如何更改 Maven 2/Cobertura 工具目标的默认输出?

java.lang.OutOfMemoryError 与 DOM

angular-cli - 获取并发脚本以完成

javascript - 浏览器渲染和 javascript 执行的同步/异步特性

javascript - mediaelement.js - 如何更改宽度

node.js - 如何获取 RequestLogger 的 json 响应

testing - 服务器的 "skipUncaughtErrors"标志是什么意思?

php - 如何使用 Ajax 函数从 php 服务器获取 session 变量? (PHP HTML JS Ajax)

javascript - 我的 Three.js 应用程序未在移动设备上运行