在 Cypress 中,我想创建一个条件来检查是否创建了类,如果是,则执行相同的步骤。
我在以下位置看到了文档:
https://docs.cypress.io/guides/core-concepts/conditional-testing.html#A-B-campaign
我写了一个例子:
cy.get('.footerWrapper').then((div) => {
if (div.find('.TestClass')) {
cy.log('xxx')
} else {
cy.log('yyy')
}
})
但条件始终为真,即使我使用 find() 和 Children() 且“TestClass”类不存在。 “TestClass”是“footerWrapper”类的子类
应该怎么写呢?有人知道吗?
最佳答案
您应该检查 .length
属性,因为空数组 [] 总是在“if”条件内给出 true
。
cy.get('.footerWrapper').then((div) => {
if (div.find('.TestClass').length) {
cy.log('xxx')
} else {
cy.log('yyy')
}
})
关于javascript - 当我们想要检查该类是否存在时,如何使用条件语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54128673/