繁体   English   中英

iOS UI自动化等待,直到Web视图准备就绪并呈现为止

[英]iOS UI Automation wait until web view is ready and rendered

我正在使用Instruments创建iOS UI自动化javascript,以自动为我的iOS应用截图。 我用来自动截图的工具是Snapshot

我正在为应用程序的一部分使用网络视图,并且在继续执行脚本的其余部分之前,我想截取完整呈现的网络视图的屏幕快照。 所以目前我的脚本看起来像:

var target = UIATarget.localTarget();
target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0].links()[0].tap();
// take screen shot here
target.frontMostApp().navigationBar().leftButton().tap();

但是,当进行屏幕截图时,Web视图未完全呈现,因此它处于空白屏幕并返回到主屏幕。 有没有办法等到webview完全加载,然后截屏并继续脚本的其余部分?

您可以使用计算样式,放置一些惰性样式属性(我使用剪辑),并且可以每隔1秒检查一次(如果使用CSS文件,则最好使用它创建一个类并在元素上使用该类)。

我下面的函数用于获取计算的样式。

function getStyle (el, prop) {
    try {
        if (getComputedStyle !== undefined) {
            return getComputedStyle(el, null).getPropertyValue(prop);
        }
        else {
            return el.currentStyle[prop];
        }
    } catch (e) {
        return el.currentStyle[prop];
    }
}

你可以尝试计时器

请注意,计算风格可能因浏览器而异。

希望能帮助到你...

Illuminator框架(完整披露,我写了它)在其Extensions.js中提供了一个名为waitForChildExistence()的函数,该函数使您能够不断评估对元素的引用,直到它真正出现为止。

您可能需要执行以下操作,以等待最多10秒钟的时间来加载Web视图:

var webView = target.frontMostApp().mainWindow().scrollViews()[0].webViews()[0];
webView.tap();

webView.waitForChildExistence(10, true, "a specific link in the web view", function(wb) {
    // the argument wb will contain the reference to our var webView
    return wb.links()["the link you are waiting for"];
});

// take screen shot here
target.frontMostApp().navigationBar().leftButton().tap();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM