如何在Cypress.io中检查一个元素是否包含多个项目,而无需大量复制代码?
当前示例:
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");
答案 0 :(得分:3)
您可以通过以下方式做到这一点:
cy.get('.column')
.children()
.should('contain', 'Name')
.and('contain', 'Age')
.and('contain', 'Weight')
.and('contain', 'Height')
.and('contain', 'Favorite Color')
答案 1 :(得分:-1)
您可以使用带有扩展运算符的数组,
cy.get('ele').contains(
'nested_ele',
...['Name', 'Age', 'Weight', 'Height']
)