title: iOS 9 UI Testing - Test Fails Because Target Control Isn't Available (yet)
body: <p>I am testing the new UI testing functionality of Xcode 7 (introduced in the WWDC 2015 video "<a href="https://developer.apple.com/videos/wwdc/2015/?id=406" rel="nofollow">UI Testing in Xcode</a>").</p>
  
  <p>On launch, my app animates a "login panel" into view, by updating the value of its vertical layout constraint: the panel slides up into view from beneath the main view (off screen).</p>
  
  <p>The panel contains two text fields, for <em>user name</em> and <em>password</em>. </p>
  
  <p>When you tap the return key on the keyboard for the <em>user name</em> text field (labeled "Next"), the <em>password</em> textfield becomes first responder. When you tap the retrun key for the password text field (labeled "Go"), the panel is "dismissed" (i.e., animated back off screen), an activity indicator starts to spin and authentication begins.</p>
  
  <p>I recorded a test performing the actions described above, but when I try to "reproduce" it, it fails seemingly because the text fields are not available for input right away:</p>
  
  <blockquote>
    <p>Test Suite 'Selected tests' started at 2015-08-14 13:14:19.454   Test
    Suite 'MyAppUITests' started at 2015-08-14 13:14:19.454   Test Case
    '-[MyAppUITests.MyAppUITests testExample]' started.<br>
        t =     0.00s     Start Test<br>
        t =     0.00s     Set Up<br>
        t =     0.00s         Launch com.myCompany.MyApp   2015-08-14 13:14:19.953 XCTRunner[4667:451922] Continuing to run tests in the
    background with task ID 1<br>
        t =     2.64s             Waiting for accessibility to load<br>
        t =     6.20s             Wait for app to idle<br>
        t =     6.49s     Tap "User ID" TextField<br>
        t =     6.49s         Wait for app to idle<br>
        t =     6.57s         Find the "User ID" TextField<br>
        t =     6.57s             Snapshot accessibility hierarchy for com.myCompany.MyApp<br>
        t =     6.60s             Find: Descendants matching type TextField<br>
        t =     6.60s             Find: Elements matching predicate '"User ID" IN identifiers'<br>
        t =     6.60s             Wait for app to idle<br>
        t =     6.67s         Synthesize event<br>
        t =     6.74s             Scroll element to visible<br>
        t =     6.78s             Assertion Failure: UI Testing Failure - Failed to scroll to visible (by AX action) TextField 0x7fc90251a130:
    traits: 146029150208, {{107.0, 807.0}, {200.0, 30.0}},
    placeholderValue: 'User ID', value: fffffaaaa, error: Error -25204
    performing AXAction 2003   :0: error:
    -[MyAppUITests.MyAppUITests testExample] : <strong>UI Testing Failure - Failed to scroll to visible (by AX action) TextField 0x7fc90251a130:</strong> traits:
    146029150208, {{107.0, 807.0}, {200.0, 30.0}}, placeholderValue: 'User
    ID', value: fffffaaaa, error: Error -25204 performing AXAction 2003<br>
        t =     6.78s     Tear Down   Test Case '-[MyAppUITests.MyAppUITests testExample]' failed (6.783 seconds).<br>
    Test Suite 'MyAppUITests' failed at 2015-08-14 13:14:26.238.<br>
    Executed 1 test, with 1 failure (0 unexpected) in 6.783 (6.784)
    seconds</p>
  </blockquote>
  
  <p><em>(emphasis mine. Project name and bundle id changed to fake values)</em></p>
  
  <p>How can I handle a UI like this? (i.e., test code has to wait for a certain animation to complete before the target control becomes operable)</p>
  
  <p>I can't remember the video mentioning these kind of 'timing' issues.</p>