如何使用量角器实现离子2混合移动应用中屏幕元素加载的WAIT

问题描述 投票:0回答:1

如何使用量角器实现wait用于离子2混合移动应用中的屏幕元素负载。

因为我正在测试IONIC Mobile应用程序而不能在没有wait的情况下使用browser.sleep(),因为浏览器实例在应用程序中不起作用。

请帮我解决这个问题。

android ionic-framework ionic2 protractor hybrid
1个回答
1
投票

已经有一段时间了,但是我已经用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();
});
© www.soinside.com 2019 - 2024. All rights reserved.