我遇到了与here所述相同的问题我需要等待网站加载,当旋转器消失然后我需要进行测试时,我知道它已经完成了。但是这么简单的测试:
beforeAll(function(){
Core.login(env.currentUser).then(function(){
var foo = browser.wait(function(){
return !browser.isElementPresent(by.css('.modal .env-waiting-content'));
}, 50000);
console.log("page loaded");
mainPage.navBar.buttons.logIncident.click();
});
});
it('should work', function(){
expect(1).toBe(1);
});
因错误而失败:
Message:
Failed: ENOTFOUND getaddrinfo ENOTFOUND
Stack:
Error: Failed: ENOTFOUND getaddrinfo ENOTFOUND
at /home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16
at /home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
at notify (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
at notifyAll (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:442:7)
at resolve (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:420:7)
at reject (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:545:5)
at /home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
at notify (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)
at notifyAll (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:442:7)
at resolve (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:420:7)
at [object Object].reject (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:545:5)
at /home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1529:10
at newFrame.onAbort (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1679:7)
at [object Object].webdriver.promise.Frame_.notify_ (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1914:5)
at [object Object]._onTimeout (/home/set/.nvm/v0.10.28/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1887:13)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
console.log("page loaded");
输出消息比spinner更早消失,在when
之后执行某些代码的方式是什么,某种then
?答案 0 :(得分:1)
您的错误看起来像是一个基本的网络问题。您是否能够获得Protractor随附的示例测试?
第二个问题(为什么console.log
如此早发生)是因为Protractor命令不做事情,他们排队以后要完成的事情(承诺底层webdriver"控制流"执行)。阅读此https://github.com/angular/protractor/blob/master/docs/control-flow.md和https://code.google.com/p/selenium/wiki/WebDriverJs#Understanding_the_API。因此,当步骤排队而不执行时,console.log最终会运行。
一般来说,在量角器中,"顶级"像browser
和protractor
以及by
这样的API都是" Angular-aware"。 browser.driver
API是底层的Selenium webdriver API(它不知道Angular)。在wait
的特定情况下,我并不认为存在很大差异(但我对此并不是100%有信心)。