赛普拉斯:通过赛普拉斯选中复选框时按钮不可见

时间:2021-07-11 09:12:09

标签: angular cypress

我正在使用 Angular 开发 Web 应用程序。有一个表,其中有复选框 每一行。

当我选中其中一个复选框时,“查看”或“删除”等操作按钮会显示在屏幕底部。但是,当我通过 Cypress 使用以下命令检查它时,按钮不显示。

cy.get('[ng-reflect-message="16"]').parent().find('input[type="checkbox"]').check({force: true})

我应该如何使用 Cypress 在屏幕上显示按钮?

谢谢。

2 个答案:

答案 0 :(得分:1)

感谢您的回答。 复选框是正常的(input type="checkbox")。 第一个在下面出现错误。

Timed out retrying after 4000ms: cy.trigger() failed because this element is not visible:

<input type="checkbox">

This element <input> is not visible because it has an effective width and height of: 0 x 0 pixels.

Fix this problem, or use {force: true} to disable error checking.Learn more

然后,我添加了 {force: true} 来触发如下部分并运行它。这次没有发生错误,但按钮仍然没有显示。

      cy.get('[ng-reflect-message="16"]')
        .parent()
        .find('input[type="checkbox"]')
        .check({force: true})
        .trigger('change', {force: true})

我也执行了第二个。没有发生错误,按钮也没有出现。

还有什么我可以尝试的吗?

答案 1 :(得分:0)

使用 Angular,你经常需要在检查的同时触发更改事件,所以也许

cy.get('[ng-reflect-message="16"]')
  .parent()
  .find('input[type="checkbox"]')
  .check({force: true})
  .trigger('change')

如果是 mat-checkbox,则点击即可

cy.get('[ng-reflect-message="16"]')
  .parent()
  .find('input[type="checkbox"]')
  .click({force: true})