如何在柏树上一页一页地走? [英] How to go page by page in cypress?

查看:15
本文介绍了如何在柏树上一页一页地走?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Web中有AJAX表,该表有很多页面。我的目标是浏览所有行和列,转到下一页,然后执行以下步骤,直到页面结束。我有以下代码:

  for(let i = 0; i < 10; i++){

      cy.get('tr:has(td)').each(($tr, rowIndex) => {    // look at each row individually

        cy.wrap($tr)
          .find('td')                           // all cols inside this row
          .invoke('slice', 5, 8)                // filter to last 3 cols only
          .invoke('text')                       // get all the text in one lump
          .then(text => {
            if (text.trim() === '') {           // after trim(), is all text empty?
              console.log(`Row ${rowIndex+1} has three empty cols`) 
              cy.wrap($tr).find('td').eq(5).click({force: true})  // click the 6th col
              cy.wait(4000)
                   cy.get('.review-modal_textarea_3L5AQ').eq(0).should('be.visible').type(str)

cy.get('.pagination_pagination_2iOOV > :nth-child(4)').click({force: true}) //clicking to the next page

}

我设法浏览了一页中的所有行和列,但转到下一页有问题(只转了一次)。我想我的循环有问题。它根本不起作用。我有I<;10,因为我有10页,但是页面可以更多(希望有一种方法可以在没有for循环的情况下做到这一点)。我如何解决此问题?

推荐答案

我认为您可以通过将每页代码包装在函数中并在正确的时间调用它来完成此操作。

for(let i = 0; i < 10; i++){的问题是无法完成页面更改。

function handlePage() {  // naf function name, but for illustration
  cy.get('tr').each(($tr, rowIndex) => {    // look at each row individually

    cy.wrap($tr)
      .find('td')                           // all cols inside this row
      .invoke('slice', 5, 8)                // filter to last 3 cols only
      .invoke('text')                       // get all the text in one lump
      .then(text => {
        if (text.trim() === '') {           // after trim(), is all text empty?
          console.log(`Row ${rowIndex+1} has three empty cols`) 
          cy.wrap($tr).find('td').eq(5).click()  // click the 6th col
          cy.wait(4000)
          cy.get('.review-modal_textarea_3L5AQ').eq(0).should('be.visible').type(str)
        }
      })
  })
}

cy.visit(...)  // whatever gets 1st page

handlePage()   // 1st page

Cypress._.times(9, () => {    // 9 more pages

  cy.get('.pagination_pagination_2iOOV > :nth-child(4)').click({force: true}) 
  .then(() => {           // after page transition
    // may need a cy.wait() or test page number on screen
    handlePage()          
  })
})

这篇关于如何在柏树上一页一页地走?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆