我正在嘗試檢查表中顯示的專案是否有一些斷言。我的方法是將所有專案放在一個陣列中,然后遍歷該陣列。
我的問題:所有斷言都已經通過,但是 cypress runner 仍然需要很多時間來完成 cy.wrap(.invoke(text)) 作業。
由于這是我的柏樹測驗的一個非常核心的命令,因此擁有更高效的功能會很棒。
我的命令:
cy.get('table tbody').within(() => {
cy.get('tr').each((tr) => {
cy.wrap(tr.children().eq(index)).invoke('text').then((text) => {
text = text.trim();
arrayWithValuesOfTheList.push(text);
});
})
.then(() => {
//in here all the (quickly passing) assertions are...
});
});
感謝您提前提供任何幫助。我很感激你們!
uj5u.com熱心網友回復:
我會使用 a.map()來獲取文本陣列。
cy.get('table tbody tr td:eq(index)') // every row, nth cell
.then($tds => {
const arrayWithValuesOfTheList = [...$tds].map(el => el.innerText.trim())
return arrayWithValuesOfTheList
})
.then((arrayWithValuesOfTheList) => {
//in here all the (quickly passing) assertions are...
})
})
Ref Array.map() - 此函式接受一個元素陣列并將其轉換為相應的文本。
uj5u.com熱心網友回復:
您可以避免包裝該值,這會提高速度,但很難說最慢的部分是什么。
const arrayWithValuesOfTheList = []
cy.get('table tbody tr')
.each($tr => {
arrayWithValuesOfTheList.push($tr.children().eq(index).text())
})
.then(() => {
//in here all the (quickly passing) assertions are...
})
})
uj5u.com熱心網友回復:
你可以做這樣的事情。tr它一一獲取值并與正則運算式模式匹配。
cy.get('table tbody tr').each(($ele) => {
cy.wrap($ele.text().trim())
.should('match', /myregexp/)
.and('not.include', 'some text')
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/484051.html
