Automating Xcode' Debug Simulate Location command
There is a GitHub project called Pokemon-Go-Controller that does exactly what you want.
Overview of the solution:
- Create a
gpx
file - Create a blank project referencing (not copying) that
gpx
file and run it on your device - Run auto clicker which will constantly click
update location
in Xcode - 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
Set iOS Simulator custom location from terminal
What you want to do is not currently supported via simctl, but I suggest you file a radar asking for this functionality at http://bugreport.apple.com
iOS emulator location for UITesting
Did you select location on your local machine from the dropdown list before run?
If it is the case then you won't be able to use the graphical UI to do it on bitrise, however locations can be selected per scheme.
You can follow this post to set location on your schemes:
Automating Xcode' Debug > Simulate Location command
Update:
If the method above didn't solved the issue, another solution would be:
To change location in the simulator itself, you will need to add a script
step before your UITest including the following script:
# download set-simulator-location
brew install lyft/formulae/set-simulator-location
# run simulator
export IOS_SIMULATOR_UDID=`instruments -s devices | grep "iPhone 6 (10.3) \[" | awk -F '[ ]' '{print $4}' | awk -F '[\[]' '{print $2}' | sed 's/.$//'`
echo $IOS_SIMULATOR_UDID
open -a "simulator" --args -CurrentDeviceUDID $IOS_SIMULATOR_UDID
# wait simulator to start fully
sleep 15
# set location
set-simulator-location -q London
Don't forget to change iPhone 6 (10.3)
to the simulator you need and London
to your own location, with -c
flag you can set coordinates as well.
For more info about set-simulator-location
visit: set-simulator-location
Programmatically setting iphone simulator location
The following AppleScript will let you set the location of the iOS Simulator. It should be possible to integrate this kind of script into a unit test script, or have your script generate the equivalent AppleEvents.
tell application "iOS Simulator"
activate
end tell
tell application "System Events"
tell process "iOS Simulator"
tell menu bar 1
tell menu bar item "Debug"
tell menu "Debug"
tell menu item "Location"
click
tell menu "Location"
click menu item "Custom Location…"
end tell
end tell
end tell
end tell
end tell
tell window 1
set value of text field 1 to "40.69"
set value of text field 2 to "-74.045"
click button "OK"
end tell
end tell
end tell
When using GPX in Xcode to simulate location changes, is there a way to control the speed?
I don't think (know) that this is possible in the GPX directly, but you can test location change with Instruments/Automation.
You'd use a script like:
var target = UIATarget.localTarget();
target.setLocation(<location);
target.delay(5);
target.setLocation(...);
And so on. I took this example from the WWDC11 video (Testing your location-aware applications)
I'm aware that this doesn't actually let you define the speed, but the delays somehow account for that I hope. Maybe that'll help you.
How to get UIAutomation, Simulator, and Xcode Debugger Running at the same time?
This stumped me for a while, too -- especially since when the Automation Instrument is selected, the Instruments application explicitly says Current instrumentation disallows attach
. The key is to realize that an app running in the simulator is visible in your host system as its own process, so attaching directly from GDB works well. These instructions are for XCode 4.2 (4C199) on Snow Leopard 10.6.8:
Start your test in Instruments however you normally do (either directly from Instruments, or from Xcode 4's
Product -> Profile
. Pick whatever templates and scripts to get your automated test underway.Back in Xcode, under the menu
Product -> Attach to Process
, you should see your iOS app, listed by name, alongside all the other applications on your host computer. In fact, it very likely will be listed first, under the section headerLikely Targets
.If it's not visible, choose
View -> Debug Area -> Show Debug Area
so you can see the gdb console.Hit the pause button (
Product -> Debug -> Pause
) to interrupt your program. Set breakpoints, inspect, as usual.
Then next question is: why can't I see my normal NSLog()
output in the debugger console?
Your app already bound itself to the console output streams, so the simplest place to look for its output is in OS X Console app (/Applications/Utilities/Console.app
) and look under DATABASE SEARCHES -> All Messages
.
Accidentally overwrote iPhone device location via Xcode
This has happened to me before, it was very strange and mysterious!
I don't remember how I fixed it, but: have you tried Reset Location & Privacy
in the Settings app? If all else fails, I suspect Reset All Settings
would maybe work.
As I try to remember, I think maybe hard rebooting the phone might also work (just turn it off, turn it back on).
Related Topics
Push View Programmatically in Callback, Swiftui
"Unable to Validate Your Application Error" While Uploading a New Version of iOS App
Passing Data to and from an Embedded Uiwebview
Storyboard Instantiateviewcontrollerwithidentifier Not Setting Iboutlets
#Import <Libxml/Tree.H> File Not Found After Xcode Update
Move Gmsmarker on Google Map Like Uber
Change the Listing Order of the View Controllers in Xcode Storyboard
Change Uifont in Secure Uitextfield Strange Behaviour in iOS7
What Is Correct Format of Bundle Identifier in iOS
How to Test for the Class of a Variable in Swift
How to Increase Width of Textfield According to Typed Text
Attach a PDF File to Email - Swift
Try Sample Avcam from Apple Found Error