Search code examples
ios-ui-automation

How to get UIAutomation to wait for 2 view changes consistently?


Xcode 6 beta 6

One workflow in my iOS app has a UINavigationController-controlled VC presenting a modal VC; "Save" in the modal VC dismisses it and pushes a new VC onto the navigation stack:

so from

UINC --> VC_1 -modal-> VC_2

to

UINC --> VC_1 --> VC_3

Ideally, I want something like this in my JS:

app.navigationBar().buttons()["Save"].tap();
_waitForView(app.navigationBar().withName("VC_3 title"));
...
// assertions re: VC_3 contents

where _waitForView() throws or otherwise fails the test if the desired view does not appear within the timeout.

On a few occasions, it has waited until VC_3 appeared and carried on correctly. More often than not, however, the first VC_3-specific assertion fails on VC_1 contents -- so my _waitForView() didn't throw/fail!

I've tried various combinations of isValid(), checkIsValid(), pushTimeout()/poptimeout(), and waiting first for VC_1 then VC_3 in _waitForView().

Have others gotten something like this to work consistently?

TIA


Solution

  • Not ideal, but this seems to work:

    UIATarget.localTarget().delay(2);
    _waitForView(app.navigationBar().withName("VC_3 title"));
    

    I hope not to need the hard-coded 2-second delay long-term, but it'll hopefully be "good enough" while Xcode 6, et al, stabilize...