[英]Promise for getting the title of a web page never resolves with Protractor and Jasmine
以下量角器/茉莉花測試代碼僅打印出1和2,然后掛起並超時。
對於按鈕元素的click()操作或瀏覽器對象上的getTitle方法的promise,或兩者都是一個問題。
有沒有人有解決方案,或者更好的方式做我正在做的事情?
碼:
it('should allow successful login', function() {
browser.get('http://192.168.0.100/src/');
browser.waitForAngular();
var titlePromise = browser.getTitle();
titlePromise.then(function(text){
console.log("1**************", text);
});
var titlePromise = browser.getTitle();
titlePromise.then(function(text){
console.log("2**************", text);
});
element.all(by.model('credentials.username')).first().sendKeys('foo');
element.all(by.model('credentials.password')).first().sendKeys('bar');
var loginBtn = element.all(by.cssContainingText('.btn', 'Login')).first();
loginBtn.click();
browser.sleep(5000);
var titlePromise = browser.getTitle();
titlePromise.then(function(text){
console.log("3**************", text);
});
});
});
錯誤:
錯誤:等待Protractor在11秒后與頁面同步超時。 請參閱https://github.com/angular/protractor/blob/master/docs/faq.md
我可能沒有足夠的信息,但有些事情要嘗試:
很明顯,您是否已閱讀每個案例,這將導致鏈接文檔中的超時https://github.com/angular/protractor/blob/master/docs/faq.md ? 如果你在Angular應用程序中使用$ timeout,Protractor永遠不會加載。
你確定你正確選擇了loginBtn嗎? 您可能希望以交互方式測試量角器: https : //github.com/angular/protractor/blob/master/docs/debugging.md 。 從量角器目錄/ node_modules /量角器:
$ node ./bin/elementexplorer.js http://192.168.0.100/src/
如果您正在登錄並轉到另一個頁面,而不是等待下一頁加載,請等待它更改:
browser.driver.wait(function() { return browser.driver.getCurrentUrl().then(function(url) { return /logged-in-url/.test(url); }); });
您忘記了與文檔的所有交互都是通過Promises完成的。 您的代碼應該看起來像下面未經測試的塊。
另請注意, 不需要 browser.waitForAngular
,“Protractor會在每個WebDriver操作之前自動應用此命令。”
不知道為什么你這么經常調用getTitle
,但我把它留在了,以防它使重構更清晰。
it('should allow successful login', function() {
browser.get('http://192.168.0.100/src/')
.then(function(){
return browser.getTitle()
})
.then(function(text){
console.log("1**************", text);
return browser.getTitle();
})
.then(function(text) {
console.log("2**************", text);
return browser.getTitle()
})
.then(function (text) {
console.log("3**************", text);
element.all(by.model('credentials.username')).first().sendKeys('foo');
})
.then(function () {
element.all(by.model('credentials.password')).first().sendKeys('bar');
})
.then(function () {
element.all(by.cssContainingText('.btn', 'Login')).first().click();
})
.then(function () {
browser.sleep(5000); // Better to use ExpectedConditions to wait something
})
.then(function () {
var titlePromise = browser.getTitle();
return browser.getTitle()
})
.then(function (text) {
console.log("3**************", text);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.