我可以将 browser.wait() 的第三个参数用于"return false"而不是替代错误消息吗?



我正试图找到一种不那么复杂的方法来寻找潜在的弹出对话框,在继续之前单击它(如果它出现),或者直接继续。

作为上下文:我的应用程序中有几十个滑块的滑块功能。现在,只要你移动其中一些滑块,它们就会弹出警告。对于这几个滑块,我需要确认警告,然后才能继续,而对于所有其他滑块,我不必这样做。

我的代码简化为我的问题(省略了所有定义等):

dragSlider = function(){
//some code to evaluate if(currentValue === desiredValue){return}
browser.actions().dragAndDrop(slider,{x:10, y:0}).perform();
warningDlg.isPresent().then(function(toConfirm){
if(toConfirm){
confirmBtn.click(); //click the warning away, so I can drag the slider again
}
dragSlider(); //recursive call until I have my desired value.
});
};

现在我的想法是:

dragSlider = function(){
//some code to evaluate if(currentValue === desiredValue){return}
browser.actions().dragAndDrop(slider,{x:10, y:0}).perform();
//HERE TO WAIT WITH EXPECTED CONDITION AND RETURN FALSE INSTEAD OF ERROR
if( browser.wait(EC.presenceOf(warningDlg), 500, false)  ){
confirmBtn.click();
}
dragSlider(); //recursive call until I have my desired value.
};

这样我就可以摆脱then(),从而摆脱不必要的异步执行和复杂性。

有什么想法吗?我该怎么做?

将等待函数与您自己自定义实现的等待函数组合起来,然后随心所欲

使用promise.then()处理不同的promise状态:

dragSlider = function(){
//some code to evaluate if(currentValue === desiredValue){return}
browser.actions().dragAndDrop(slider,{x:10, y:0}).perform();
browser.wait(EC.presenceOf(warningDlg), 500).then(()=> {
// If wait successful - means warningDlg is present
confirmBtn.click()
}, (err)=> {
// If wait not successful - means warningDlg is not present
// Just empty function to ignore error
})
dragSlider(); //recursive call until I have my desired value.
};

最新更新