iPhone Dev Note #22: UIAutomation
One of the problems with UIAutomation is the lack of documentation. At the time of writing this, the current documentation/reference that I use is found here ( http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html )
- Works on the device but not on the simulator?
Copy com.apple.Accessibility.plist from 4.0 to 4.0.1
- I can’t get the mainWindow().buttons(). Why?
Related code shown below have a navigation view added as a subview to window. Don’t confuse yourself that you need to get a subview from mainWindow() like mainWindow().elements[0]? It will not work. There’s nothing wrong with your code, however, open up your xib or Interface Builder, in my case, I will open MenuController.xib.
- (void)applicationDidFinishLaunching:(UIApplication *)application { [self createEditableCopyOfDatabaseIfNeeded]; MenuController *mainMenuController = [[MenuController alloc] initWithNibName:@"MenuController" bundle:nil]; navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenuController]; [window addSubview: [navigationController view]]; [mainMenuController release]; // Override point for customization after application launch [window makeKeyAndVisible]; } |
For some reason, when the “Accessibility” is enabled on the view, it doesn’t work. I am not exactly sure why, but UIAutomation only recognizes the window and not its sub-elements. Unticking this checkbox, allows us to get all the elements under mainWindow(). This has been a bugger and I spent 4 hours figuring this.
After you finished updating your elements in Interface Builder, make sure you build and deploy the app in the simulator. This will recreate/replace the binary and remember that it is the target app of Instruments. Afterwards, launch the test script and see if it works now.
- How was I able to see the element heirarchy?
...mainWindow().logElementTree(); |
As always don’t keep banging your head that there’s something wrong with your view heirarchy. I suggest you read thoroughly the reference posted above to understand what is available for mainWindow().
- Instrument tips
– Command + R will stop or record the test.
– Your app is not listed in the “Choose target”? Well you could navigate to the /Users/rupert/Library/Application Support/iPhone Simulator/4.0.1/Applications/94EC26E5-D76B-4003-9675-8F0DDE111D01/beforeUdig.app/ (which sucks) OR from XCode > Run > Run With Perfomance Tool > Leaks. Once Leaks opens, it automatically chooses your current app as the target. Close leaks and go back to Instruments. From here, you will see your app listed in the target.