如何等待TestCafe中的角度执行?

问题描述 投票:1回答:2

嗨我想在应用程序中执行某些操作后等待角度进入稳定状态。我发现angular有window.getAllAngularTestabilities()和isStable函数()

我使用TestCafe Client Function绑定使用它,但TestCafe无法识别此属性。

你知道如何处理它吗?

testcafe
2个回答
1
投票

我想你可以查看https://github.com/DevExpress/testcafe-angular-selectors存储库。它内置了mechanisms等待Angular


1
投票

ClientFunction代码可以在页面上的所有其他脚本之前执行。可能,在这种情况下,Angular没有足够的时间来完成初始化。尝试为您的页面使用以下代码:

const delay = ms => new Promise(r => setTimeout(r, ms));

const isAngularStable = ClientFunction(() => {
   if(!window.getAllAngularTestabilities)
       return false;

   return window.getAllAngularTestabilities().every(x => x.isStable());
});

const waitUntilAngularIsStable = async () => {
   while(!await isAngularStable())
       await delay(500); 
};

test('Test', async t => {
   await waitUntilAngularIsStable();
   // ...
});


© www.soinside.com 2019 - 2024. All rights reserved.