1

I am creating an iOS UI Automation javascript using Instruments to automate taking a screenshot for my iOS app. The tool I am using to automate taking a screenshot is Snapshot.

I am using a webview for part of my app and I want to take a screenshot of fully rendered webview before proceeding to the rest of the script. So currently my script looks like:

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

But when it takes the screen shot, the webview was not fully rendered so it's taking an empty screen and go back to the main screen. Is there a way to wait until the webview is fully loaded, then take a screen shot and continue rest of the script?

DanielC
  • 51
  • 1
  • 8

2 Answers2

0

You can use computed style, put some inert style property (I used clip), and you can check with intervals of 1 second (if you use css files better create a class with it and use the class on element).

The function below i user to get the style computed.

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];
    }
}

The timer you can try this

Be aware of that computed style may vary by browsers.

Hope it helps...

Community
  • 1
  • 1
Luchini
  • 75
  • 1
  • 7
0

The Illuminator framework (full disclosure, I wrote it) provides a function called waitForChildExistence() in its Extensions.js that allows you to continuously evaluate a reference to an element until it actually appears.

You would do something like this to wait up to 10 seconds for the webview to load:

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();
Ian
  • 11,280
  • 3
  • 36
  • 58
  • Did you change the name? I'm getting 404 when I click the link. – ScottyBlades Jan 13 '22 at 04:31
  • Apple deprecated the Javascript-based UIAutomation tool in favor of XCtest, so Illuminator was updated and based on that framework instead. The last revision of Extensions.js should be in this commit: https://github.com/paypal/Illuminator/blob/f7b7218e42c94a3768d2828c9c1a40388725984a/gem/resources/js/Extensions.js – Ian Jan 14 '22 at 15:43