Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automating Xcode' Debug > Simulate Location command

Is there any programmatic way to control the xcode > simulate location command? I have external location test scripts I'd like to run, and ideally the test suite could cause xcode to change the location of the connected phone at will.

Is this possible, and if so how?

like image 533
Stefan Kendall Avatar asked Jul 21 '16 01:07

Stefan Kendall


3 Answers

Not sure if it's exactly what you're after, but you can have different unit test bundles use different locations (or GPX files) by setting it up in the scheme.

You could then have unit tests in each bundle which test what you need regarding that specific location.

Scheme

xctool can also just run the unit tests in a specific target using the -only option:

path/to/xctool.sh \
  -workspace YourWorkspace.xcworkspace \
  -scheme YourScheme \
  test -only SomeTestTarget
like image 124
InsertWittyName Avatar answered Nov 10 '22 19:11

InsertWittyName


There is a GitHub project called Pokemon-Go-Controller that does exactly what you want.

Overview of the solution:

  1. Create a gpx file
  2. Create a blank project referencing (not copying) that gpx file and run it on your device
  3. Run auto clicker which will constantly click update location in Xcode
  4. Update gpx file using some script and the device location will be automatically updated

Instead of the auto clicker you can use this Apple Script:

#Will continue update the location to the location name below from Xcode:

property locationName : "pokemonLocation" #name of your gpx filex

###########################
tell application "System Events"
    tell process "Xcode"
        repeat while true
            click menu item locationName of menu 1 of menu item "Simulate Location" of menu 1 of menu bar item "Debug" of menu bar 1
            delay 0.2
        end repeat
    end tell
end tell
like image 45
bzz Avatar answered Nov 10 '22 18:11

bzz


Yes, it is possible. 1. Set up the GPX files as described in @InsertWittyName 's answer, or as described in this blog post. 2. Use Instruments to run your app in the Simulator using the different GPX files.

I would write out the entire process, but someone more eloquent than myself already has.

As an avid S/O user, I would be bereft to leave what is basically a single-link answer. So here is some extra, bonus information.

  1. You should definitely look into security testing your location aware features. I will be at Black Hat this year, so if you're there, let's talk about it!

  2. If you don't like the previously linked/sort of explained answer, you could use XCTest with code to simulate different locations (like this).

  3. It looks like there are also Apple Script solutions, like this one.

I hope I have at the very least provided enough information to qualify as more than just a lazy link-only answer. Enjoy, and good luck!

like image 2
Max von Hippel Avatar answered Nov 10 '22 18:11

Max von Hippel