0

I want to be able to use UIAutomation to test an app. The problem I'm running into is, I need to download allot of data from the network. Is there a way to pause a UIAutomation script until a NSNotification is posted, or do I just need to delay() longer than I think is necessary to download the data. Waiting a set amount of time isn't preferable because sometimes data doesn't need to be re-downlaoded.

Any help / links is greatly appreciated.

Till
  • 27,559
  • 13
  • 88
  • 122
SkylarSch
  • 389
  • 2
  • 9

2 Answers2

2

UIAutomation has a nifty function called waitForInvalid(). If you've got a progress bar or something that will get displayed and then removed after the data is done downloading, you could use that.

This also works for a case in which the user already has the data and you don't show the UI, since the function would immediately return.

Jack Lawrence
  • 10,664
  • 1
  • 47
  • 61
1

Jack's answer works for most details, but some of the network work happens on a background queue, and there isn't a progress indicator.

I ended up writing a helper that sticks a CGRectZero UIView into an element. We can then wait until this element becomes valid. It's not as clean as I would like it to be but it's woking.

waitForElementNamed: function(name, element, timeout) {
  timeout = timeout || 10
  log("Waiting for " + timeout + " seconds")
  var valid = false
  for (var i = 0; i < timeout; i++) {
      UIATarget.localTarget().pushTimeout(.5)
      valid = element.elements()[name].isValid()
      if (valid) {
      log("Found Element " + name)
      return
      }
      UIATarget.localTarget().popTimeout()
      target.delay(.5)
  }
  if (!valid) {
      failed("Wait Timedout [" + timeout + "]")
  }
}

It's not pretty but it works.

SkylarSch
  • 389
  • 2
  • 9