我正在為具有動態組/專案串列的應用程式撰寫賽普拉斯測驗。每個專案都有一個詳細資訊鏈接,單擊該鏈接會創建一個包含所述詳細資訊的彈出視窗。我需要關閉該彈出視窗并移至組中的下一個專案。
我首先嘗試.each()在組上使用命令,然后會.click({multiple:true})詳細資訊,但彈出視窗會覆寫下一次單擊。添加{foce:true}確實允許顯示所有彈出視窗,但我認為這不符合應用程式應如何運行的精神。
我最近的嘗試是創建一個自定義命令,.next()用于遍歷組。這可行,但是當.next()到達組的末尾時,它會產生"",因此測驗最終會失敗。我得到的實際錯誤是:
Expected to find element: ``, but never found it. Queried from element: <div.groups.ng-star-inserted>
這.spec.ts
describe('Can select incentives and view details', () => {
it('Views incentive details', () => {
cy.optionPop('section#Incentives div.groups:first')
})
})
這index.ts
Cypress.Commands.add('optionPop', (clickable) => {
cy.get(clickable).find('[ng-reflect-track="Estimator, open_selection_dial"]').click()
cy.get('mat-dialog-container i.close').click()
cy.get(clickable).next().as('clicked').then(($clicked) => {
//fails at .next ^ because '' is yielded at end of list
cy.wrap($clicked).should('not.eq','')
})
cy.optionPop('@clicked')
})
uj5u.com熱心網友回復:
你基本上有正確的想法,但它可能在普通的 JS 函式而不是自定義命令中效果更好。
function openPopups(clickables) {
if (clickables.length === 0) return // exit when array is empty
const clickable = clickables.pop() // extract one and reduce array
cy.wrap(clickable)
.find('[ng-reflect-track="Estimator, open_selection_dial"]').click()
cy.get('mat-dialog-container i.close')
.should('be.visible') // in case popup is slow
.click()
// wait for this popup to go, then proceed to next
cy.get('mat-dialog-container')
.should('not.be.visible')
.then(() => {
openPopups(clickables) // clickables now has one less item
})
}
cy.get('section#Incentives div.groups') // get all the popups
.then($popups => {
const popupsArray = Array.from($popups) // convert jQuery result to array
openPopups(popupsArray)
})
一些額外的說明:
使用
Array.from($popups)是因為我們不知道串列中有多少,并且想用它array.pop()來抓取每個專案并同時減少陣列(它的長度將控制回圈退出)。clickables是原始元素的串列,因此cy.wrap(clickable)使單個元素可用于 Cypress 命令,例如.find().should('be.visible')- 在處理彈出視窗時,DOM 經常被打開它的點擊事件改變,這相對于測驗運行的速度可能很慢。添加.should('be.visible')是一個保護措施,以確保測驗在某些運行中不會出現問題(例如,如果使用 CI).should('not.be.visible').then(() => ...- 由于您有多個重疊彈出視窗的一些問題,這將確保每個彈出視窗在測驗下一個彈出視窗之前已經消失。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/425614.html
上一篇:Python沒有將變數識別為串列
下一篇:如何從Dart串列中洗掉地圖|撲
