2

Context: Running automated scripts using Xcode's UIAutomation with simulators 6.1 and 5.1 Xcode version is 4.6.1

Problem: When running a shell script from the Terminal, UIAutomation ALWAYS opens up 6.1, even though i've set the app path to 5.1.

I've tried building and running on 5.1, also if i run the test from Instruments, I'm able to choose the target for 5.1 and it works fine. The problem is only when i run it from the command line.

I checked the iphonesimulator.plist and the currentSDKRoot points to the 5.1 path, but as soon as the shell script runs, it changes to 6.1. Is there anyway I can force it to use 5.1?

After hours of searching (including the most apt one - Launch a specific Hardware version of iOS simulator using instruments command line utility) , there seems to be no solution to this.

There is a way to set the device using defaults write com.apple.iphonesimulator \ "SimulateDevice" '"iPad"' I need something like defaults write com.apple.iphonesimulator \ "Version" '"5.1"' though obviously that doesn't work.

Any pointers will be much appreciated. Thank You!

EDIT: I was hoping this would be resolved with XCode 5, but I still have the same issue and iOS7 simulator ALWAYS opens up! Btw,is there a way to circumvent this issue - I'm sure there are many out there running multiple simulator versions.

Community
  • 1
  • 1

2 Answers2

1

This isn't elegant, but it is a work around that we have been able to get to work on our automation setup:

Install Xcode 5 from the App Store
Install Xcode 4.6.3 or from the developer portal's "Old Versions of Xcode page"
Repeat with older versions of Xcode where the max sim version == the one you want to run
Use "sudo xcode-select -switch /path/to/Xcode.app" to pick the version of Xcode

Hope that helps!

Nick
  • 33
  • 1
  • 7
  • Thank You! This is probably the best approach for now since usually we run tests on the latest iOS version and one lower major version to support compatibility. And If i ever have to support 5.1, then I'll install an earlier version of XCode which has 5 as its max sim. – MobileTester Sep 25 '13 at 19:39
  • Edit - Since the code is now built using XCode 5, I cannot use Xcode 4.6.3 anymore :( Suggestions? – MobileTester Oct 31 '13 at 00:15
1

I also ran into this issue while running my automation tests on my Jenkins box and I did the following to test my app with ver 6.1 simulator and not 7.0 simulator:

Using Jenkins:

STEP 1 = I create one job that builds my ios app with the 6.1 sdk version.

===========================================

STEP 2 = I create a 2nd job using a bash script that downstreams from the 1st job which does the following:

[Go inside the Xcode app location to get to the iphone simulator sdk directory]

cd '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'

[Move the 'iPhoneSimulator7.0.sdk' directory to another location (I chose the desktop)]

echo [ENTER ADMIN PASSWORD HERE] | sudo -S mv iPhoneSimulator7.0.sdk/ ${HOME}/Desktop

[Rename the 'iPhoneSimulator6.1.sdk' to 'iPhoneSimulator7.0.sdk']

echo [ENTER ADMIN PASSWORD HERE] | sudo -S mv iPhoneSimulator6.1.sdk/ iPhoneSimulator7.0.sdk/

===========================================

STEP 3 = I create 3rd job that executes my tests. The 3rd job downstreams from my 2nd job.

===========================================

STEP 4 = I create a 4th job that downstreams from the 3rd job. The 4th job uses a bash script which does the following:

[Go inside the Xcode app location to get to the iphone simulator sdk directory]

cd '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'

[Rename the 'iPhoneSimulator7.0.sdk' back to 'iPhoneSimulator6.1.sdk']

echo [ENTER ADMIN PASSWORD HERE] | sudo -S mv iPhoneSimulator7.0.sdk/ iPhoneSimulator6.1.sdk/

[Go to directory where you moved the 'iPhoneSimulator7.0.sdk' (in my case I moved the 'iPhoneSimulator7.0.sdk' to the desktop)]

cd ${HOME}/Desktop

[Move the 'iPhoneSimulator7.0.sdk' directory back to the Xcode app sdk directory]

echo [ENTER ADMIN PASSWORD HERE] | sudo -S mv iPhoneSimulator7.0.sdk/ '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/'

[I kill any lingering processes related to the automation]

ps ax|grep [b]ash|awk '{print $1}'|xargs kill -9

ps ax|grep [i]nstruments|awk '{print $1}'|xargs kill -9

===========================================

I probably need to make this process more foolproof however I think its better than having multiple instances of xcode on the automation machine.

Community
  • 1
  • 1
Ray
  • 501
  • 4
  • 9
  • if you plan to edit my post, get the formatting right so the lines dont run into each other – Ray Oct 01 '13 at 02:52
  • I also made this process more streamlined by using the Jenkins plugin called Parameterized Trigger Plugin. – Ray Oct 01 '13 at 22:42