Search code examples
iosasynchronousios-ui-automation

UIAutomation and NSNotification


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.


Solution

  • 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.