Testing 如何检查Cypress.io中的元素是否包含多个项
我如何检查一个元素在Cypress.io中是否包含多个项,而不需要大量复制我的代码 当前示例:Testing 如何检查Cypress.io中的元素是否包含多个项,testing,cypress,qa,Testing,Cypress,Qa,我如何检查一个元素在Cypress.io中是否包含多个项,而不需要大量复制我的代码 当前示例: cy.get(".column") .children() .contains("Name"); cy.get(".column") .children() .contains("Age"); cy.get(".column") .children() .contains("Weight"); cy.get(".column") .children() .cont
cy.get(".column")
.children()
.contains("Name");
cy.get(".column")
.children()
.contains("Age");
cy.get(".column")
.children()
.contains("Weight");
cy.get(".column")
.children()
.contains("Height");
cy.get(".column")
.children()
.contains("Favorite Color");
您可以这样做:
cy.get('.column')
.children()
.should('contain', 'Name')
.and('contain', 'Age')
.and('contain', 'Weight')
.and('contain', 'Height')
.and('contain', 'Favorite Color')
可以使用带有扩展运算符的数组
cy.get('ele').contains(
'nested_ele',
...['Name', 'Age', 'Weight', 'Height']
)
完美的谢谢你的帮助!!这是可行的,但如果数据恰好是“年龄”,它可能会产生误报。@DanDascalescu是的,的确如此。您可以使用
.contains
方法,并传递一个选择器,如:.contains('.my item',Age')
。