3

I am writing automation testing for my iOS app and I am trying to figure out how to detect in the javascript script when a view controller fully loaded and is on screen...

So right now for example the script taps on a button:

target.frontMostApp().mainWindow().buttons()["loginButton"].tap();

Then, once the app logs in (which could take a few seconds or less) I need to press another button.

Right now, I made it work by simply putting a delay:

target.delay(3);

But I want to be able to detect when the next view controller is loaded so that I know I can access the elements on the new screen just loaded.

Any suggestions?

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
zumzum
  • 17,984
  • 26
  • 111
  • 172

3 Answers3

2

There are some ways to achieve that:

  1. Tune Up Library

    https://github.com/alexvollmer/tuneup_js

    I would really recommend to check this out. They have some useful wrapper function to write more advanced test. Some methods is written to extend the UIAElement class. They have waitUntilVisible() method.

    But there might be possibility that the element itself is nil. Its not the matter of visibility but its just not in the screen yet.

  2. UIATargetInstance.pushTimeout(delay) and UIATargetInstance.popTimeout()

    Apple documentation says :

    To provide some flexibility in such cases and to give you finer control over timing, UI Automation provides for a timeout period, a period during which it will repeatedly attempt to perform the specified action before failing. If the action completes during the timeout period, that line of code returns, and your script can proceed. If the action doesn’t complete during the timeout period, an exception is thrown. The default timeout period is five seconds, but your script can change that at any time.

    You can also use UIATarget.delay(delay); function, but this delays the execution of the next statement, not nescessarily waiting to find the element. setTimeout(delay) can also be used to globally set the timeout before UIAutomation decides it could not find the element.

    There is Apple's guide explaining more understanding towards the framework here. http://developer.apple.com/library/IOS/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/UsingtheAutomationInstrument/UsingtheAutomationInstrument.html

Rpranata
  • 2,010
  • 18
  • 24
1

In most cases simply identifying an element specific to the next view controller should be sufficient. The description of the element must be something unique to the new UI however.

i.e. target.frontmostApp().mainWindo().navigationBar()["My Next View"];

The script should delay until the element can be identified or the timeout has been reached (see pushTimeout popTimout).

In some cases it might be necessary to specify that the element is visible.

.withValueForKey(1, "isVisible")

It's also possible to use waitForInvalid to do the reverse (wait for something in the previous UI to go away).

BBog
  • 3,630
  • 5
  • 33
  • 64
Smith
  • 11
  • 1
0

Search for tuneup library here

Refer function waitUntilVisible for the same. you may include other files to for supporting functions in it. Hope it help.

Community
  • 1
  • 1
ExploringApple
  • 1,348
  • 2
  • 17
  • 30
  • I can't get tuneup js functions to work properly, for example: mainWindow.waitUntilFoundByName("foo", 100) never find my controller that has accessibilityLabel set to foo. Any ideas? – nylund Apr 15 '14 at 11:45