我对Protractor和JS还是个新手。我写了一个简单的代码,使用一个在线计算器来添加一些数字。通过调用add()函数来添加我正在做的事情,其中我返回了一个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)发布于 2019-03-28 20:56:26
试试下面的
it("Addition from calc should give correct result", async() =>{
await brwoser.waitForAngularEnabled(true);
await browser.get('http://juliemr.github.io/protractor-demo/');
})
});希望能对你有所帮助
发布于 2019-04-04 13:04:54
例如。
browser.wait(condition, 5000);而不是
browser.wait(condition);所以没那么走运。
然后,经过多次实验,我们得出结论,除非您提供超时参数,否则browser.wait()并不总是抛出异常,当预期的条件永远不会成为真时,测试也会失败。在没有超时的情况下,最好的情况是测试将达到全局黄瓜超时,我们将得到一条无用的通用失败消息。最坏的情况是,执行偶尔会继续到下一个功能,而第一个功能在后台超时。当第一个功能最终超时时,它会导致第二个功能失败,并显示隐秘的消息both angularJS testability and angular testability are undefined。在wait()的the documentation中没有提到这种行为。
我们尝试增加全局黄瓜超时并设置全局量角器超时,但没有效果。因此,我们进行了全面更新,以始终提供超时参数,此后再也没有看到错误。
https://stackoverflow.com/questions/55396133
复制相似问题