Question

I am writing integration tests for an iOS app using UIAutomation.

As part of the test suite, I have incorporated a reset function that will return the app to the main menu by tapping on the left UINavigationBar item as long as it exists.

This is the code used to do so (written in tuneup.js):

function reset (app) {
    // While we have a left button on the nav bar, tap it.
    // This effectively resets our app

    while(app.mainWindow().navigationBars()[0].leftButton().isValid()) {
        app.mainWindow().navigationBars()[0].leftButton().tap();
    }
}

It does its purpose.

However, isValid() will wait for several seconds in case it can not immediately find an object. Thus the integration tests are running very slowly as every time we hit the main menu after resetting, isValid() will wait for some time to see if a left UINavigationBar item will appear.

Is there an alternative function or alternative implementation that would allow me to determine wether an element exists without this forced timeout?

Was it helpful?

Solution

You can overwrite the default timeout to 0 with:

UIATarget.localTarget().pushTimeout(timeoutInSeconds);

However it does not seem to be a good idea to check validation in a while cycle with 0 timeout.

function reset (app) {
    // While we have a left button on the nav bar, tap it.
    // This effectively resets our app

    UIATarget.localTarget().pushTimeout(0);
    if (app.mainWindow().navigationBars()[0].leftButton().isValid()) {
        app.mainWindow().navigationBars()[0].leftButton().tap();
    }
    UIATarget.localTarget().popTimeout();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top