Jas*_*onS 6 wait promise protractor
我想使用browser.wait函数重复检查按钮元素是否存在一段时间然后使用相关的回调.下面我有不使用等待的代码.
detailsButton.isPresent()
.then(function(present){
if(!present) {
callback();
} else {
callback(new Error('The details button was not present.'));
}
});
Run Code Online (Sandbox Code Playgroud)
我想帮助修复这段代码,因为我不确定wait函数如何处理falure/timeout.基本上我在问下面代码的'.then'部分应该是什么,而不是我现在所拥有的那么笨重.
browser.driver.wait(function(){
return pgTransactionHistory.transactionHistoryDetails.isPresent();
}, 60000).then(function(){
pgTransactionHistory.transactionHistoryDetails.isPresent()
.then(function(present){
if(!present) {
callback();
} else {
callback(new Error('The details button was not present.'));
}
});
});
Run Code Online (Sandbox Code Playgroud)
谢谢!
Jas*_*onS 10
有两种方法可以执行此操作:首先,您可以将browser.wait的第三个参数用于将作为错误消息发送的字符串.像这样:
browser.driver.wait(function(){
return //condition
}, timeout, 'Error message string')
.then(function(){
callback();
});
Run Code Online (Sandbox Code Playgroud)
或者其次使用.then的第二个参数,如下所示:
browser.driver.wait(function(){
return //condition
}, timeout)
.then(function(){
callback();
}, function(){
//code to want to execute on failure.
});
Run Code Online (Sandbox Code Playgroud)