【发布时间】:2020-01-27 23:10:35
【问题描述】:
我想在 cypress 中编写一些测试来加载页面并检查是否打开了某些模态(不应该超过 5 秒)然后关闭它,否则如果模态没有打开,只需转到 before 块中的测试用例。我该怎么做?到目前为止,我有以下代码,我只能确定模态是否存在然后关闭。
function checkModalThenProceed() {
cy.get(#check modal is open function).then(($modal) => {
if ($modal) {
closedModal();
}
})
}
describe('test if-else flow', () => {
before(()=>{
checkModalThenProceed();
})
it('testflow', () => {
expect(1).to.eq(1);
});
})
``
【问题讨论】:
-
如果你想基于元素或 DOM 有条件地运行测试,你需要使用 jQuery 来选择这些元素并弄清楚你想要什么。如果您使用
cy.get(),它实际上是在运行测试。不返回任何内容的cy.get()算作测试失败。
标签: typescript mocha.js cypress