是否可以在 Cypress 测试中使用两个对象:Force 和 Multiple?

Ujj*_*wal 3 automation automated-tests cypress

我正在使用 cypress test 来检查页面中的所有按钮是否可以单击。

我已经使用了这行代码:

cy.get('button').click({ force: true }).should('have.attr', 'href')
Run Code Online (Sandbox Code Playgroud)

并给出错误

CypressError:cy.click() 只能在单个元素上调用。您的主题包含 5 个要素。如果您想连续单击每个元素,请传递 { multiple: true }。

之后将代码更改为:

cy.get('button').click({ multiple: true }).should('have.attr', 'href')
Run Code Online (Sandbox Code Playgroud)

并得到另一个错误

CypressError:重试超时:cy.click() 失败,因为此元素不可见:

...

该元素 '' 不可见,因为它具有 CSS 属性:'display: none'

修复此问题,或使用 {force: true} 禁用错误检查。

https://on.cypress.io/element-cannot-be-interacted-with

有没有办法同时使用这两个对象来解决问题?

Mr.*_* J. 14

这应该可行(我没有在需要时测试它的情况,但它不会导致错误):

cy.get('button')
  .click({ multiple: true, force: true })
  .should('have.attr', 'href')
Run Code Online (Sandbox Code Playgroud)