0
我正在使用實習生進行UI測試自動化。我有一個測試,在測試失敗時輸入無效的用戶名結果。但是,我的測試不應該失敗,當它應該。測試沒有失敗使用chai聲明與實習生
步驟i希望自動:
- 輸入用戶名
- 點擊下一步按鈕
- 檢查是否顯示密碼文本框(密碼文本框中只顯示,如果用戶名是有效的別的保持在同一頁上)
這裏是我的代碼:
頁面對象的腳本:
enterLoginName: function (username) {
console.log('entering username');
return this.remote
.findById(this.locator.uname).clearValue().sleep(1000)
.type(username)
.end().then(function() {
console.log('username entered ');
})
.findById(this.locator.nextbtn).sleep(1000)
.click().end(); // enter login name and click next button
},
isValidUsername:function() {
console.log('checking if password textbox is displayed');
return this.remote
.findDisplayedById(this.locator.pwd).isDisplayed();
//passowd test box is only shown if username is valid
},
測試腳本:
'correct login name lands to password page': function() {
loginPage.enterLoginName('ss').then(function() {
loginPage.isValidUsername().then(function (pass) {
console.log(pass);
}, function (fail) {
// code reaches here since password test box is not displayed
console.log('user name uas valid , enter password panel not was shown');
assert.fail(0, 1, 'Exception not thrown');// test not failing
});
})
能有人請解釋什麼是不這裏工作,以及如何使其正常工作?
我不明白。你可以解釋嗎?? – CodeBlooded
在您的測試腳本中,您調用的是異步的函數,並返回Promise(或類似Promise的對象),如'loginPage.enterLoginName'。在測試中使用Promises時,需要1)返回Promise鏈的結尾,以便Intern可以知道異步操作何時完成; 2)確保返回在'then'回調中生成的任何Promises以確保_all_異步觀察操作。所以你需要在外層返回「loginPage.enterLoginName」,在'then'回調中需要'return loginPage.isValidUsername'。 – jason0x43