Search code examples
ios-ui-automation

How can iOS's Javascript UIAutomation be used to navigate a native app's oAuth process?


Context

Many native apps have the user authenticate with Facebook, rather than with their own authentication system. This has been problematic for me to write iOS UIAutomation testcases with the Javascript bindings. Our scenario, from the user's perspective, typically looks like this.

Scenario

  1. The user clicks "Connect to Facebook".
  2. The (target) applications moves to the background, and a Safari browser moves into the foreground, so the user can authenticate with oAuth.
  3. The user enters their authentication data and submits.
  4. The Safari browser window moves into the background, and the target application moves back into the foreground.

Problem

Before running tests, Instruments has the user set the "target app" in the top menu bar. Using the Automation within Instruments proves problematic when the target app moves into the background and the Safari app moves into the foreground (Step #2). At this point, Instruments reports

The target application appears to have died

I thought this would be as simple as merely polling/testing for changes in UIATarget.localTarget().frontMostApp() (or something similar), but does not seem to be the case -- the test run stops executing.

How can I use Instruments to successfully test this scenario? Is this a testable scenario with UIAutomation's Javascript bindings?


Solution

  • Alas, this is not possible. Instruments loses it's connection with the app since the app freezes in the background and does not continue. Also, it's not possible to send touch events to Safari because UI Automation doesn't work with apps that you didn't build yourself.

    If you're using a pre-built SDK, you're pretty much out of luck. But if you are rolling your own Oauth connection to them, you could present a modal view controller with a webview going to Facebook's Oauth authentication page instead of kicking the user all the way out to mobile Safari.

    That way, the application never exits. You can then figure out the events to send to the webview and try testing this from there.