[英]TestCafe gets stuck when using await async in expect assertion
我正在使用 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 的 DOM 節點狀態屬性或客戶端函數承諾作為斷言中的實際值時,TestCafe 會激活智能斷言查詢機制。 這種機制使您的測試穩定 - 請參閱TestCafe 文檔中的更多信息。 因此,請按以下方式重寫您的測試:
test('Verify contents of allocation', async (t) => {
await t
.click(accountManager.selectAccount(inputData.testAccount))
.click(homePage.icon)
.expect(dash.getPersonCount(inputData.totalAllocation)).eql(7);
});
您的第一個示例中的await
關鍵字在expect
方法中的問題與測試之前dash.getPersonCount(inputData.totalAllocation)
的執行有關,因為此await
中斷了測試鏈。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.