【问题标题】:Access custom window properties with Testcafe使用 Testcafe 访问自定义窗口属性
【发布时间】:2019-06-20 23:09:39
【问题描述】:

所以在我们的应用程序中,我们有一个名为 reactMap 的自定义窗口属性。因此,当您加载我们的站点并转到控制台并输入“window.reactMap.loaded()”时,它将返回 true 或 false。但是当我尝试在 TestCafe 测试中通过添加:

const mapLoaded = ClientFunction(() => window.reactMap.loaded());

它只是抱怨Property 'reactMap' does not exist on type 'Window'. 如何在 TestCafe 测试中运行那段代码?谢谢

【问题讨论】:

    标签: javascript automated-tests e2e-testing web-testing testcafe


    【解决方案1】:

    这意味着您在应用程序初始化window.reactMap 属性之前执行ClientFunction。尝试如下修改您的测试代码:

    const waitForProperty = ClientFunction(() => {
         return new Promise(function (resolve, reject){
             var intervalId = null;
             var timeoutId = null;
             var checkCondition = function () {
                  return window.reactMap;
             }
    
             timeoutId = window.setTimeout(function () {
                 window.clearInterval(intervalId);            
    
                 if (checkCondition())
                    resolve();
                 else
                    reject();
             }, 10000);
             intervalId = window.createInterval(function (){
                if (checkCondition()) {
                    window.clearInterval(intervalId);
                    resolve();
                }
             }, 1000);
         });
    });
    
    
    await waitForProperty();
    
    const mapLoaded = await ClientFunction(() => window.reactMap.loaded())();
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 2011-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-17
      相关资源
      最近更新 更多