I have some kind of navigation app where I handle different locations. Is it possible in UI tests to simulate and even to change them at runtime? What would be the best approach to archive this?
I think the best approach to this will be to use GPX files. These allow you to set the lat and long of a location. (For more details see here: https://blackpixel.com/writing/2013/05/simulating-locations-with-xcode.html)
However, I suspect you will need to call these from within the app itself and then use UI testing launch arguments (when you launch XCUIApplication) to stipulate which GPX files to use depending upon the test.
See my detailed note https://github.com/onmyway133/blog/issues/45
You need to declare the gpx file in the app target, not the UI Tests target
Go to Simulator -> Location -> Custom Location to point to your location in the gpx. It is duplication, but without it, it does not work
If it does not work because of caching or something, run the app again, then run UI Tests again.
If it still does not work, reset simulator
You can create gpx file directly from Xcode
Related
I am currently writing tests for my app on xcode, and was wondering if there is a line of code I could use that would run my tests using an pre determined location service? I know it is possible to do it manually by clicking on the arrow when the test is running, but i want it automatically? I cant find any documentation or similar questions online.
Anyone know of anything?
A quick solution to this is going on simulator > Debug > Location > Custom Location > Then add the Lat and long in.
So I downloaded the beta of XCode 7 and I've created some UI tests, but I can't find the functionality of how to take screenshots of my app/UI during the test.
Can someone please help?
UI Testing in Xcode automatically takes screenshots of your app after every step.
Simply go to one of the tests that has already ran (Report Navigator > choose a Test), then start expanding your tests. When you hover your mouse over the steps, you will see eye icons near each step that has a screenshot.
Here's an example... in this case, notice the eye icon at the end of the gray row. If I were to tap on it, I would see a screenshot of the app right when the button in my app was tapped (since the step is Tap the "Button" Button).
If you want to generate screenshots, you can also use snapshot, which describes how to trigger screenshots in UI tests: https://github.com/fastlane/fastlane/tree/master/snapshot#how-does-it-work
It basically rotates the device to .Unknown (Source), which triggers a snapshot without actually modifying your app's state.
Comparing the output with the generated plist file enables you to even properly name the screenshot
Facebook's ios-snapshot-test-case and KIF both run as Unit Tests, and therefore are in the same process as the app. As such, they can directly access views and use something like renderView: or snapshotViewAfterScreenUpdates. Xcode UI Testing runs in a separate process, and therefore cannot directly access the views.
UI Automation, Apple's now-deprecated Javascript UI testing library, had a function calledcaptureScreenWithName.
Unfortunately, the new Xcode UI Testing lacks any similar function in its testing library, which to me seems like a glaring omission and I encourage you to submit a Radar for it, as taking screenshots is fundamental to perceptual difference tests (which it sounds like you're trying to do). I hope (and expect) that able will address this deficiency in later Xcode updates.
In the meantime, there are more creative approaches to taking screenshots. See this stack overflow response for a workaround involving taking the screenshot in the app itself and then sending it to the test process.
I' ve created a tool that saves the tests last n screenshots and generates the JUnit tests results report, parsing TestSummaries plist file from test logs. https://github.com/nacuteodor/ProcessTestSummaries
Maybe, that helps you.
Facebook's FBSnapshotTestCase can be alternative solution:
https://github.com/facebook/ios-snapshot-test-case
I am investigating the available testing frameworks for iOS,
I want to write tests for an iOS app that are location dependent, like if you are at place A (I mean geo-location) this testStep should fail and that one should succeed and in location B the situation is the other way around,
Is there a way to simulate being at a location when writing Frank tests, in the simulator, and not by manually choosing a gpx file for each test separately,
EDIT: to make it clear, I want to do it in my tests, so it should be done in my code or with calling an external script or in some automatic way, I want to run tests that should happen in different locations.
as of Frank 1.1.1 you can now ask Frank to simulate a location using the set_location method. For an example of how this works take a look at this step definition from the example app that comes with Frank.
I want to write tests for an iOS app that are location dependent, like if you are at place A (I mean geo-location) this testStep should fail and that one should succeed and in location B the situation is the other way around,
Is there a way to simulate being at a location for KIF tests, like defining a stepForBeingAtLocation , for the simulator obviously, and not by manually choosing a gpx file for each test separately,
EDIT: to make it more clear, I want to do it in my tests, so it should be done in my code or with calling an external script or in some automatic way, I want to run tests that should happen in different locations.
The iOS Simulator is able to simulate different locations.
Select the iOS Simulator app, and from its OS X menu bar, look under Debug -> Location.
For testing purposes, is it possible to specify a coordination as the default current location. As the app runs in the simulator, it returns the specified location when the app needs current location.
You can of course do this through the simulator:
Debug -> Location -> custom location
It's also possible to use GPX files. These are small XML-based files that have longitude and latitude information. This way you can create some easy to use favorite locations, which you can trigger from the debug area (from the "Simulate Location" compass icon) or from Product > Debug > Simulate Location. You can set any of them as your default location. Very handy! Also works as an override for attached devices.
I use http://www.gpx-poi.com to create them, but I'm sure you do it in other ways too.