1

我必须迭代一个包含列的表:参考号、用途和按钮。我想检查我的参考号是否 == 所需的文本和目的 == 所需的文本,然后单击按钮。现在的问题是它只检查第一行,而不是迭代其他行。

下面是我正在尝试的代码:

clickButton(purpose) {
    cy.xpath(this.objectFactory.referenceNoColumnXpath).each(
      ($e, index, $list) => {
        const refNumberText = $e.text()
        if (refNumberText.includes('automationRefNumberEdit')) {
          cy.log(refNumberText)

          cy.xpath(this.objectFactory.purposeColumnXpath).each(
            ($ee, indexx, $listt) => {
              const purposeText = $ee.text()
              cy.log(purposeText)
              if (purposeText.includes(purpose)) {
                const signatureElement = cy
                  .xpath(this.objectFactory.signatureButtonXpath)
                  .eq(indexx)
                  .find('img')
                  .should('have.attr', 'src')
                if (signatureElement.should('contain', 'signature_gray')) {
                  cy.log(indexx)
                  cy.xpath(this.objectFactory.signatureButtonXpath)
                    .eq(indexx)
                    .first()
                    .click()
                  cy.xpath(this.objectFactory.applyNowButtonXpath)
                    .should('be.visible')
                    .click()
                  cy.VerifyAlert(
                    'Listing(s) has been updated successfully',
                    'rgb(65, 140, 89)'
                  )
                }
              }
              if (!purposeText.includes(purpose)) {
                assert.fail('Purpose not found in table')
              }
              return false
            }
          )
        }
        if (!refNumberText.includes('automationRefNumberEdit')) {
          assert.fail('Reference number not found in table')
        }
        return false
      }
    )
  }
4

0 回答 0