简体   繁体   English

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

[英]TestCafe gets stuck when using await async in expect assertion

I'm using TestCafe and have the following code in the test which doesn't work:我正在使用 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));
});

The problem with the above code is that TestCafe says "Waiting for the element to appear" even before it hits the first line of the test and then gets stuck forever.上面代码的问题在于 TestCafe 甚至在它到达测试的第一行之前就说“等待元素出现”,然后永远卡住。 I have no idea why this happens.我不知道为什么会发生这种情况。

When I make the following change to the above test, then it works:当我对上述测试进行以下更改时,它会起作用:

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);
});

Is there an easy way to prevent TestCafe from getting stuck?有没有一种简单的方法可以防止 TestCafe 卡住?

And idea why it gets stuck in the first place?以及为什么它首先被卡住?

The best practice is to put enumerated values in the actual field.最佳做法是将枚举值放在实际字段中。 When you use the Selector's DOM node state property or client function promise as an actual value in an assertion, TestCafe activates the smart assertion query mechanism.当您使用Selector 的 DOM 节点状态属性客户端函数承诺作为断言中的实际值时,TestCafe 会激活智能断言查询机制。 This mechanism makes your test stable - see more about it in the TestCafe documentation .这种机制使您的测试稳定 - 请参阅TestCafe 文档中的更多信息 So please rewrite your test the following way:因此,请按以下方式重写您的测试:

test('Verify contents of allocation', async (t) => {
  await t
    .click(accountManager.selectAccount(inputData.testAccount))
    .click(homePage.icon)
    .expect(dash.getPersonCount(inputData.totalAllocation)).eql(7);
});

The problem in your first example with the await keyword in the expect method relates to the execution of dash.getPersonCount(inputData.totalAllocation) before the test because this await breaks the test's chain.您的第一个示例中的await关键字在expect方法中的问题与测试之前dash.getPersonCount(inputData.totalAllocation)的执行有关,因为此await中断了测试链。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM