我用一些鏈方法實作了頁面物件。
頁面看起來像這樣
class Table {
getTable() {
return cy.get('table#tblItem');
}
getListRow() {
return this.getTable()
.within(($tbl) => {
cy.get('tbody').scrollTo('bottom', { ensureScrollable: false, duration: 1000 });
return cy.wrap($tbl).find('tbody#itemBody tr');
});
}
}
在賽普拉斯規范檔案中,我做斷言來驗證行串列是否有專案
Table.getListRow()
.then((lstRowItem) => {
expect(lstRowItem).have.length.greaterThan(1);
})
但我總是得到方法“getTable()”的結果,而不是“getListRow()”。測驗失敗,因為它獲得了表的值 1。
我怎樣才能得到這個鏈方法的正確回傳。
謝謝
uj5u.com熱心網友回復:
該.within()命令不允許回傳內部值。
使用.then()and.find()代替。
getListRow() {
return this.getTable()
.then($tbl => {
return cy.wrap($tbl).find('tbody')
.scrollTo('bottom', { ensureScrollable: false, duration: 1000 })
.then(() => {
return cy.wrap($tbl).find('tbody#itemBody tr');
});
})
參考:.within()
.within() 產生與上一個命令相同的主題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/480819.html
