如何使用量角器在 ionic 2 混合移动应用程序中实现等待屏幕元素加载
How to implement WAIT for screen elements load in ionic 2 hybrid mobile application using protractor
如何使用量角器在 ionic 2 混合移动应用程序中实现 wait
屏幕元素加载。
因为我正在测试 IONIC Mobile 应用程序,没有 browser.sleep()
就无法使用 wait
,因为浏览器实例在应用程序中不工作。
请帮我解决这个问题。
已经有一段时间了,但我使用以下辅助方法使用 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();
});
如何使用量角器在 ionic 2 混合移动应用程序中实现 wait
屏幕元素加载。
因为我正在测试 IONIC Mobile 应用程序,没有 browser.sleep()
就无法使用 wait
,因为浏览器实例在应用程序中不工作。
请帮我解决这个问题。
已经有一段时间了,但我使用以下辅助方法使用 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();
});