简体   繁体   English

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

[英]How to wait until angular execute in TestCafe?

I want to wait for angular go to a stable state after some action in the app.我想在应用程序中执行一些操作后等待角度进入稳定状态。 I found that angular has window.getAllAngularTestabilities() and isStable function()我发现 angular 有window.getAllAngularTestabilities()和 isStable function()

I tied to use it using TestCafe Client Function but this property is not recognized by TestCafe.我使用 TestCafe Client Function 来使用它,但 TestCafe 无法识别此属性。

Do you have any idea how to deal with it?你知道如何处理吗?

I think you can check the https://github.com/DevExpress/testcafe-angular-selectors repository.我想你可以查看https://github.com/DevExpress/testcafe-angular-selectors存储库。 It has built-in mechanisms for waiting the Angular它具有等待 Angular 的内置机制

The ClientFunction code can be executed before all other scripts on the page. ClientFunction代码可以在页面上的所有其他脚本之前执行。 Likely, Angular doesn't have enough time to complete initialization in this case.在这种情况下,Angular 可能没有足够的时间来完成初始化。 Try to use the following code for your page:尝试为您的页面使用以下代码:

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();
   // ...
});
 

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

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