我想写一些测试在柏树加载页面,并检查如果一些模式是打开(这应该不会超过5秒),然后关闭它,否则,如果模式没有打开,只要去测试用例在之前块。我该怎么做呢?到目前为止,我有以下代码,我只能确保如果存在模式,然后关闭它。
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);
});
})
``发布于 2020-01-29 07:15:06
很难猜测#check modal是开放函数代表的是什么,但是如果顾名思义它是一个函数,那么你可以直接调用它并在一个简单的if()语句中使用结果。
因为这是显而易见的,而且您有一个cy.get(),所以我假设您使用的是某种选择器。
在该场景中使用cy.get()将在模式未实际打开时导致测试失败。
您可以将表达式更改为使用jquery (在Cypress global上提供为Cypress.$,ref),它允许您在不导致测试失败的情况下测试选择器,请参见jquery ref。
function checkModalThenProceed() {
if (Cypress.$('my-modal-selector').length) { // zero length means not found
closedModal();
}
}发布于 2020-03-06 04:07:52
我使用以下代码:
if ($body.find("modal_selector").length > 0) {
//evaluates as true if selector exists at all
//do something
.....
}else{
//if selector does not exist
}https://stackoverflow.com/questions/59940195
复制相似问题