cypress - Cypress - if - else 条件不起作用
问题描述
我需要使用 Cypress 自动执行 if-else 条件,但它在我的脚本中不起作用。我需要一个“如果”元素存在(或可见),然后单击“是”,否则继续。但就我而言,如果第一个条件不存在,则测试尝试以任何方式单击“是”。
it('Logout', () => {
const out = new logout();
const lged = new logged();
lged.logged().then($button => {
if ($button.is(':visible')){
lged.logged().click()
out.bar().click()
out.clickout()
}
else {
out.bar().click()
out.clickout()
}
})
})
在我的 pageObjects 中,我有“记录”类:
class logged {
logged(){
return cy.contains('Yes', { timeout: 10000 })
}
}
export default logged
解决方案
推荐阅读
- reactjs - 使用 react 构建信息丰富的公司网站时,我是否应该对内容进行硬编码?
- laravel - 如何在 Laravel 中使用 orderBy() 和模型的方法
- arduino - 我的框图出现问题:Init.vi 出现错误 5002
- neo4j - Neo4j 密码查询因未知语法错误而失败
- pip - Linux 上的 Lektor 安装失败
- python - 模板标签返回无
- .net - Azure Blob 存储 - 使用文件流/内存流显示 PDF
- android - 未找到 api < 21 的 android Api 密钥
- twitter-bootstrap - 如何做响应式 5 列(网格)。[引导]
- php - AJAX 发送 GET 而不是 POST