赛普拉斯:如何验证表中的2行具有相同的值/ID

发布于 2025-02-02 16:35:23 字数 622 浏览 3 评论 0原文

嗨,我有一个表,其中有2行具有相同的值,我需要迭代,并且检查2行具有ID:POL-330等,该值作为参数传递。使用Cypress TypeScript请

在这里输入图像描述

我已经尝试过

```getNumberOfDocuments(document: string) {
    cy.contains('tr > td:nth-child(1)', document).should('have.length.greaterThan', 1);
  }```

,也

```getNumberOfDocuments(document: string) {
    cy.contains('tr > td:nth-child(1)', document).each(($ele, index, list) => {
        cy.wrap($ele).should('have.length.greaterThan', 1)
    })
  }```

请帮助

Hi I have a table below where 2 rows have same value i need to iterate and check 2 rows have ID: POL-330 etc which is passed as parameter. using cypress typescript please

enter image description here

i have tried

```getNumberOfDocuments(document: string) {
    cy.contains('tr > td:nth-child(1)', document).should('have.length.greaterThan', 1);
  }```

and also

```getNumberOfDocuments(document: string) {
    cy.contains('tr > td:nth-child(1)', document).each(($ele, index, list) => {
        cy.wrap($ele).should('have.length.greaterThan', 1)
    })
  }```

please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风起 2025-02-09 16:35:23

.contains()命令仅返回第一个匹配元素,因此您无法使用它检查两个行。

但是您可以在选择器内部使用:contains()

const selector = `tr > td:nth-child(1):contains(${document})`  // use string template to build selector

cy.get(selector).should('have.length.greaterThan', 1)

如果要循环),这就是它可能工作的方式

let count = 0;
cy.get('tr > td:nth-child(1)')
  .each($el => {
    if ($el.text() === document) {
      count = count + 1;
    }
  })
  .then(() => {                
    expect(count).to.be.gt(1)   
  })

The .contains() command only ever returns the first matching element, so you can't use it to check for two rows.

But you can use :contains() inside the selector

const selector = `tr > td:nth-child(1):contains(${document})`  // use string template to build selector

cy.get(selector).should('have.length.greaterThan', 1)

If you want to loop, this is how it might work

let count = 0;
cy.get('tr > td:nth-child(1)')
  .each($el => {
    if ($el.text() === document) {
      count = count + 1;
    }
  })
  .then(() => {                
    expect(count).to.be.gt(1)   
  })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文