转换应表达为软主张
我有一个复杂的形式,具有许多单独的功能可以测试,我想在整个页面上遍历整个页面而不会失败。我已经看到了软主张,但无法弄清楚如何使其与禁用
之类的属性一起使用。
例如
<input data-id="name"></input>
<input data-id="email"></input>
<input data-id="password" disabled></input>
cy.get('[data-id="name"]').should('not.be.disabled')
cy.get('[data-id="email"]').should('be.disabled') // fails - convert to soft assertion?
cy.get('[data-id="password"]').should('have.attr', 'disabled')
I have a complex form with many individual features to test, and I'd like to traverse the whole page without failing the test. I've seen soft assertions but cannot figure out how to make it work with attributes such as disabled
.
For example
<input data-id="name"></input>
<input data-id="email"></input>
<input data-id="password" disabled></input>
cy.get('[data-id="name"]').should('not.be.disabled')
cy.get('[data-id="email"]').should('be.disabled') // fails - convert to soft assertion?
cy.get('[data-id="password"]').should('have.attr', 'disabled')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 alfonso-presa/soft-assert 有效。
这意味着您必须将
.should()
的样式更改为回调版。另外,由于
Expect()
在表达式为false时不再失败,因此您将失去重试功能。仅在稳定的HTML页面上使用它。注意
flush()
方法应添加到柏树命令链中,否则测试在评估之前结束。You could use alfonso-presa/soft-assert to change the way
expect
works.It would mean you have to alter the style of
.should()
to the callback version.Also, since the
expect()
not longer fails when the expression is false, you lose retry capability. Only use this on a stable HTML page.Note
The
flush()
method should be added to Cypress command chain, otherwise the test ends before it is evaluated.