3

I am trying UI Automation on iPhone for connecting to any given Wi-Fi network. I want to automate Settings app. It should automatically:

  1. open Settings app;
  2. turn on Wi-Fi;
  3. connect to given network by providing SSID and WPA.

My questions are:

  1. Is it possible to automate any inbuilt app using UI Automation? Does the Apple/iOS security model preclude any such access to inbuilt apps?
  2. If it is possible, how to achieve this?
Lebyrt
  • 1,376
  • 1
  • 9
  • 18
Ravindra
  • 271
  • 3
  • 6

2 Answers2

4

I know I'm late to the party, but I'd like to provide a more complete answer and elaborate on my solution.

I run my uiautomation from shell scripts, here's my solution..

(You'll have to remove spaces etc)

settingsapp.sh

#!/bin/bash
sleep 5s
instruments -v -w MY_SIMULATOR_DEVICE_ID -t
/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/
PlugIns/AutomationInstrument.xrplugin/Contents/Resources/
Automation.tracetemplate /Applications/Xcode.app/Contents/Developer/
Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/
Applications/Preferences.app -e UIASCRIPT 
/Users/ path to my js file/settingapp.js

settingapp.js

var target = UIATarget.localTarget();
target.delay(1.0);
target.frontMostApp().mainWindow().tableViews()[0].cells()
  ["General"].tap();

target.delay(1.0);
target.frontMostApp().mainWindow().tableViews()[0].cells()
  ["Language & Region"].tap();

target.delay(1.0);
target.frontMostApp().mainWindow().tableViews()[0].cells()
  ["Region"].tap();

target.delay(1.0);
target.frontMostApp().mainWindow().tableViews()[0].cells()
  ["United Kingdom"].tap();

target.delay(1.0);

So you could have several shell scripts, firstly one to set the language, then another to do screen shots, then run another switch to another language etc..

:)

Jules
  • 7,568
  • 14
  • 102
  • 186
2

Yes, it is possible and easy to do. Select the "Preferences.app" (Settings) as your target and write a script for the rest. The "Preferences.app" is located inside your Xcode app

/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs//Applications/Preferences.app

Ricardo B.
  • 189
  • 1
  • 8
  • I'm also interested in finding out how to do this? There must be some way to automate the settings app on the physical iPhone??? – bearaman Apr 22 '15 at 09:38
  • @Ricardo B. I'm upvoting you as this helped with my answer! – Jules Apr 28 '15 at 18:24