Test location defined in scheme settings does not work when running snapshot
Closed this issue · 21 comments
Original issue by @Myrronth - Imported from fastlane/snapshot#333 |
I have a location-based app that has to show map(s) on its app store screenshots using a custom "current" location. To achieve this I created a custom scheme "Snapshot" and set a gpx file as test location for the tests that snapshot will use to create its screenshots.
When running the test with XCode via Product > Test the "current" lcoation is set to the location provided by the gpx file and all is working like expteced.
But when running the test with snapshot (I would assume snapshot does the same that I do via the interface?) than the simulator has no current location and my maps are messed up.
Does anyone know why this is not working and can provide me with a solution or a workaround?
@Ashton-W commented |
If you run the UI tests via xcode-build does the same thing happen?
Running snapshot with verbose should print out the xcodebuild command ised
@Myrronth commented |
snapshot uses "xcrun xcodebuild -showBuildSettings -workspace './Grunzeug.xcworkspace' -scheme 'Snapshot'" to run the tests. I don't know if there is another way to run the tests manually from the command line? The specified scheme and workspace seems to be correct and the rest of the tests itself succeed.
I attached a screenshot of my scheme's test configuration if that helps in some way?
@Ashton-W commented |
Try
xcrun xcodebuild -workspace './Grunzeug.xcworkspace' -scheme 'Snapshot' test
If you have time, could you create a small sample project that reproduces it?
@Myrronth commented |
Sorry for the delayed response, i had a few busy weeks.
I created a small test project (https://github.com/Myrronth/GPX-Location/tree/master).
Running and testing the app via Xcode works fine, testing via snapshot or xcrun xcodebuild -scheme 'GPX Location' -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.2' test
does not.
@SanMarcos commented |
Same issue here
@clementpadovani commented |
Hey @Myrronth, I’ve had the same issue as you. After some digging in the Apple private frameworks I’ve abandoned the GPX file for my tests. I’m using a location simulation class that’s available as a private API. You can check it out here.
@Ashton-W commented |
I think this is related to this Xcode Known Issue, since Gather Coverage data is another flag set in schemes that does not work during UI Testing:
Code coverage analysis is not recorded for the target app when UI tests are executed via
xcodebuild test, even when "Gather coverage data" is enabled. (23913271)
@SanMarcos commented |
Xcode does support location testing with UI Testing.
They do not work in Snapshot.
Perhaps somebody can figure out what exactly Xcode is doing to launch a simulator instance with location simulation.
@Ashton-W commented |
In my brief testing it does not work when running UI Tests at all.
@SanMarcos commented |
It works if you don't run it with a UI Test that has any reference to snapshot. Also be sure to reset the simulator before trying it again.
@clementpadovani commented |
You can simulate your location using this method that I specified in this comment fastlane-old/snapshot#333 (comment)
@olutsenko commented |
I have the same issue.
Location simulation works if running tests from Xcode (cmd+U).
Location simulation doesn't work when running 'snapshot' command.
@olutsenko commented |
As a workaround this helps me.
Make sure your simulator is set to use custom location manually before running 'snapshot'. You do it once (not for each supported simulator).
Same here.
Location simulation works if running tests from Xcode (cmd+U).
Location simulation doesn't work when running 'snapshot' command.
@olutsenko's work around worked great for me.
+1 from me. @olutsenko 's work around is not working for me.
As I previously mentioned, the only workaround that I’ve found to work 100% of the time is the use of CLSimulationManager
(header: https://github.com/ClementPadovani/aBike/blob/master/aBikeFramework/aBikeLibrary/Additions/CLSimulationManager.h).
I wrap all my code conditional if
s so I don’t ship with that internal class.
It’s simple to get it working, you can check it out here https://github.com/ClementPadovani/aBike/blob/master/aBikeFramework/aBikeLibrary/Additions/VELocationManager.m#L169
@clementpadovani Thanks for stepping in. @wrightak Let me know if you get up and running with this workaround. Thanks! 👍
@TKBurner @clementpadovani Thank you for the reply and for offering a work around. I looked through your code and I don't think the costs associated with integrating something like that are worth the pay off. My app is 100% in Swift. It appears that you're using preprocessor macros and a variety of classes (and some private APIs?) to replace the location manager.
@wrightak Thanks for following up. I'm going to make sure we look this over. We'll update on this thread 👍
Thanks for this report, and the work-arounds @olutsenko and @clementpadovani! It looks like there isn't a simple broadly applicable option for this right now, so I'm going to close this issue as something that snapshot
currently does not support, but I'm adding a "help-wanted" tag to it in case anyone wants to take a stab at adding this functionality.