如何使用量角器实现wait
用于离子2混合移动应用中的屏幕元素负载。
因为我正在测试IONIC Mobile应用程序而不能在没有wait
的情况下使用browser.sleep()
,因为浏览器实例在应用程序中不起作用。
请帮我解决这个问题。
已经有一段时间了,但是我已经用Protractor测试Ionic并使用以下辅助方法取得了一些成功:
waitForIonic: function () {
//Register a promise with protractor, so the browser waits for it
var deferred = protractor.promise.defer();
let clickBlock = element(by.css('.click-block-active'));
//if there's a click block, wait for it to be gone, otherwise just wait 1 sec
if (clickBlock.isPresent()) {
var untilClickBlockIsGone = ExpectedConditions.not(ExpectedConditions.visibilityOf(clickBlock));
browser.wait(untilClickBlockIsGone, 20000).then(() => {
browser.driver.sleep(1000);
//We've fulfilled the promise, so
deferred.fulfill();
});
}
else {
browser.driver.sleep(1000);
//We've fulfilled the promise, so
deferred.fulfill();
}
//Return the promise (which hasn't been fulfilled yet)
return deferred.promise;
}
然后像这样使用它:
//Wait for ionic animiations, Click logout
module.exports.waitForIonic().then(() => {
logoutButton.click();
});