簡體   English   中英

賽普拉斯在使用條件時出現“pointer-events: none”錯誤,我該怎么辦?

[英]Cypress results with "pointer-events: none" error when using condition, what should I do?

代碼

賽普拉斯結果

我想點擊下一步按鈕來測試分頁,直到它的 class 被“禁用”。 我使用了下面的代碼。 但即使“下一步”按鈕已“禁用”class,它也會繼續單擊。賽普拉斯會在附件中拋出錯誤。

static pagination(){

    var index = 0 
    cy.get('li [data-test="page-link"]:not(.active):not([aria-label="Next"]) :not([aria-label="Previous"]').as("pages")
        cy.get('@pages').its('length').then( len =>{
            if(index <= len){
                cy.get('[data-test="page-link"][aria-label="Next"]').then( next=>{
                    cy.wrap(next).invoke('hasClass', 'disabled').then( classDisable =>{
                        if(classDisable==false){
                            cy.wait(500)
                            cy.wrap(next).should('not.have.class', 'disabled')
                            cy.wrap(next).click()
                        }
                             this.pagination()
                             index++
                    })
                })
                
            }
        })
    }

嘗試在下次單擊時將 force 選項設置為 true。

cy.wrap(next).click({ force: true} )

如果你想點擊禁用的按鈕,你必須使用{force: true}

cy.wrap(next).click({force: true})

而且,如果你想先檢查按鈕是否啟用,然后執行點擊,你可以這樣做:

cy.get('[data-test="page-link"][aria-label="Next"]').then(($next) => {
  if ($next.is(':enabled')) {
    //next button is enabled
    cy.wrap(next).click()
  } else {
    // Do something when next button is disabled
  }
})

這可能是你想要的

const maxPages = 10  // so we don't get an infinite loop 
                     // if Next never gets disabled (maybe due to app bug)

function clickNext(nextClicks = 0) {

  if (nextClicks > maxPages) {
    throw "Maximum page clicks exceeded"
  }

  // use non-failing jQuery (Cypress.$) to test the disabled state
  const nextIsDisbaled = Cypress.$('[data-test="page-link"][aria-label="Next"]')
    .hasClass('disabled')
  if (nextIsDisabled) return

  cy.get('[data-test="page-link"][aria-label="Next"]').click()
  cy.wait(500)  // or wait for a page change, e.g new element
  clickNext(++nextClicks)
}

clickNext()  // start clicking

如果 Next 按鈕從一開始就被禁用,它也應該可以工作。

完全避免條件檢查是可能的。

如果您可以獲得“下一步”左側框中的數字 - 我猜測.prev()會得到它,但您可能必須調整該步驟。

然后你可以click() pageCount-1次。

cy.get('[data-test="page-link"][aria-label="Next"]')
  .prev()                                                // last page box
  .invoke('text')
  .then(lastPageText => {
    const pageCount = +lastPageText;
    Cypress._.times(pageCount -1, () => {
      cy.get('[data-test="page-link"][aria-label="Next"]').click()
    })
  })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM