我对量角器和JS很陌生。我编写了一个简单的代码,使用在线计算器添加了几个数字。添加我正在通过在我返回Promise的地方调用add()函数来执行此操作。我正在处理导致问题并给出上述错误的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)
答案 0 :(得分:0)
尝试以下一个
it("Addition from calc should give correct result", async() =>{
await brwoser.waitForAngularEnabled(true);
await browser.get('http://juliemr.github.io/protractor-demo/');
})
});
希望它对您有帮助
答案 1 :(得分:0)
这可能无济于事,因为在您的代码中看不到browser.wait()
,但是FWIW我们花了几天的时间调试此确切的错误消息,并最终通过显式更新所有browser.wait()
调用来解决此问题超时。例如
browser.wait(condition, 5000);
代替
browser.wait(condition);
我们首先验证browser.waitForAngularEnabled()
是否设置为true(我们正在使用Cucumber / Protrator / Selenium / Chai测试纯Angular应用程序,没有非角度页面,因此没有理由打开waitForAngular
)。所以那里没有运气。
然后,经过大量实验,我们得出结论:browser.wait()
并不总是会引发异常,并且在预期条件永远不会变为真时不会通过测试,除非您提供超时参数。如果没有超时,最好的情况是测试将达到全局黄瓜超时,并且我们将收到无用的通用失败消息。最坏的情况是执行偶尔会继续执行下一个功能,而第一个功能在后台超时。当第一个功能最终超时时,它导致第二个功能失败,并显示了神秘消息both angularJS testability and angular testability are undefined
。 the documentation中没有提到wait()
的这种行为。
我们尝试增加全局黄瓜超时并设置全局量角器超时,但是没有效果。因此,我们进行了全面更新以始终提供timeout参数,此后再也没有看到错误。
我怀疑整个灾难可能与我们使用Chai而不是Jasmine有关,因为文档中提到了jasmineNodeOpts.defaultTimeoutInterval
,因此代码中可能存在一些我们要打破的假设。