【问题标题】:Getting "Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined ....""获取“等待量角器与页面同步时出错:“angularJS 可测试性和 angular 可测试性都未定义......”
【发布时间】:2019-04-04 13:04:53
【问题描述】:

我对 Protractor 和 JS 还很陌生。我编写了一个简单的代码来使用在线计算器添加几个数字。添加我正在通过调用一个 add() 函数来返回一个 Promise。这个 Promise 我正在我的 it 块中处理它导致问题并给出上述错误。

尝试更新版本但没有帮助

describe("Using Protractor and working", function(){

    var resultsExpected = [];

    function add(a,b){
        return new Promise(function(resolve, reject){
            element(by.model("first")).sendKeys(String(a));
            element(by.model("second")).sendKeys(String(b));
            element(by.id("gobutton")).click();     

            var len=0;
            len = resultsExpected.length;
            resultsExpected[len] = {value:String(a+b)};
             console.log("Length is: "+resultsExpected.length);
             console.log("Item inside: "+resultsExpected[len].value);
             resolve();
        });

    }

it("Addition from calc should give correct result", function(){
        browser.get('http://juliemr.github.io/protractor-demo/');        

        add(2,4).then(function(ff){
            expect(element(by.css("h2.ng-binding")).getText()).toEqual("6");
            return add(5,3);
        }).then(function(ff){
            expect(element(by.css("h2.ng-binding")).getText()).toEqual("8");
            return add(5,8);
        }).then(function(ff){
            expect(element(by.css("h2.ng-binding")).getText()).toEqual("13");
        })

    })
})
Failures:
1) Using Protractor and working Addition from calc should give correct result
  Message:
[31m    Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"[0m
  Stack:
    Error: Error while waiting for Protractor to sync with the page: "both angularJS testability and angular testability are undefined.  This could be either because this is a non-angular page or because your test involves client-side navigation, which can interfere with Protractor's bootstrapping.  See http://git.io/v4gXM for details"
        at runWaitForAngularScript.then (D:\JavaScriptWorkSpace\FirstProtractor\protractor\built\browser.js:463:23)
        at ManagedPromise.invokeCallback_ (D:\JavaScriptWorkSpace\FirstProtractor\protractor\node_modules\selenium-webdriver\lib\promise.js:1376:14)
        at TaskQueue.execute_ (D:\JavaScriptWorkSpace\FirstProtractor\protractor\node_modules\selenium-webdriver\lib\promise.js:3084:14)
        at TaskQueue.executeNext_ (D:\JavaScriptWorkSpace\FirstProtractor\protractor\node_modules\selenium-webdriver\lib\promise.js:3067:27)
        at asyncRun (D:\JavaScriptWorkSpace\FirstProtractor\protractor\node_modules\selenium-webdriver\lib\promise.js:2927:27)
        at D:\JavaScriptWorkSpace\FirstProtractor\protractor\node_modules\selenium-webdriver\lib\promise.js:668:7
        at process._tickCallback (internal/process/next_tick.js:68:7)Error
        at ElementArrayFinder.applyAction_ (D:\JavaScriptWorkSpace\FirstProtractor\protractor\built\element.js:459:27)
        at ElementArrayFinder.(anonymous function).args [as getText] (D:\JavaScriptWorkSpace\FirstProtractor\protractor\built\element.js:91:29)
        at ElementFinder.(anonymous function).args [as getText] (D:\JavaScriptWorkSpace\FirstProtractor\protractor\built\element.js:831:22)
        at D:\JavaScriptWorkSpace\FirstProtractor\WorkinWithDropDown.js:55:45
        at process._tickCallback (internal/process/next_tick.js:68:7)

【问题讨论】:

标签: protractor


【解决方案1】:

试试下面这个

it("Addition from calc should give correct result", async() =>{
       await brwoser.waitForAngularEnabled(true);
       await browser.get('http://juliemr.github.io/protractor-demo/');        
    })
});

希望对你有帮助

【讨论】:

    【解决方案2】:

    这可能无济于事,因为我在您的代码中没有看到 browser.wait(),但 FWIW 我们花了几天时间调试这个确切的错误消息,并最终通过使用显式超时更新所有 browser.wait() 调用来修复它。例如

    browser.wait(condition, 5000);
    

    代替

    browser.wait(condition);
    

    我们首先验证 browser.waitForAngularEnabled() 是否设置为 true,确实如此(我们正在测试一个带有 Cucumber/Protrator/Selenium/Chai 的纯 Angular 应用程序,没有非 Angular 页面,所以没有理由关闭 @ 987654327@)。所以没有运气。

    然后,经过大量实验,我们得出结论,browser.wait() 并不总是在预期条件永远不会变为真时引发异常并导致测试失败,除非您提供超时参数。如果没有超时,最好的情况是测试会达到全局黄瓜超时,我们会得到一个无用的通用失败消息。最坏的情况是执行偶尔会继续到下一个功能,而第一个功能在后台超时。当第一个功能最终超时时,它导致第二个功能失败并显示神秘消息both angularJS testability and angular testability are undefined。 the documentation 中没有提到 wait() 的这种行为。

    我们尝试增加全局黄瓜超时并设置全局量角器超时,但没有效果。所以我们进行了全面更新以始终提供超时参数,并且从那以后就没有看到错误。

    我怀疑整个不幸事件可能与我们使用 Chai 而不是 Jasmine 有关,因为文档中提到了 jasmineNodeOpts.defaultTimeoutInterval,所以我们正在破坏的代码中可能存在一些假设。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-11
      • 1970-01-01
      • 2019-10-03
      • 2016-04-26
      • 1970-01-01
      • 2018-12-07
      • 2014-05-16
      • 2016-08-16
      相关资源
      最近更新 更多