Showing posts with label xcode-ui-testing. Show all posts
Showing posts with label xcode-ui-testing. Show all posts

Sunday, September 23, 2018

Get current GPS position in iOS UITest

Leave a Comment

Is it possible to get the current GPS position of the phone/simulator in a UITest test-case?

One possible workaround would be to run a test app in the background and communicate with that app in the test-case but I want to avoid that if possible.

2 Answers

Answers 1

TL;DR:

Example project: https://github.com/JakubMazur/SO52339694


The principle of testing is that you control environment, so for testing you should be using one of predefined location or put one of your's location into .gpx file:

example:

<?xml version="1.0"?> <gpx version="1.1"> <wpt lat="50.12108905423" lon="39.9260224404235"> </wpt> </gpx> 

If you said like in comment a location in a given moment inside UITesting, that's not gonna be possible in real time, but you can combine couple of things to get location from time couple of seconds/minutes back.

Here what I would do:

  1. There is a tool called corelocationcli available through homebrew. If you install it this will give you current coordinates.

  2. Then I will create file linked in my xcode project in tests let's call it genarated.gpx and filled it with any data on this point.

  3. Then I will wrote a script like this:

code

#!/bin/bash  latitude="$(CoreLocationCLI -format \"%latitude\")" longitude="$(CoreLocationCLI -format \"%longitude\")"  echo "<?xml version=\"1.0\"?> <gpx version=\"1.1\"> <wpt lat=${longitude} lon=${latitude}> </wpt> </gpx>" > generated.gpx 
  1. And apply this as a build phase:

enter image description here

That way getting location get a couple of seconds before starting an UITests, but if you can live with this couple of seconds delay this solution should work for you.

Example project you can find on github

Answers 2

Assuming you have control over the app code, and not just the test cases code :

  • Implement location tracking in the app itself
  • Expose the current / last known location with timestamp via the tracking class' public (static?) method
  • Access it in your test case addition to the functionality being tested

This makes your test cases less robust but should get you the desired behavior

Read More

Thursday, May 5, 2016

Assertion Failure: UI Testing Failure - Failure fetching attributes for element

Leave a Comment

When UI testing in Xcode(7.2 and 7.3), my tests sometimes fail with a rather generic error:

Assertion Failure: UI Testing Failure - Failure fetching attributes for element

I tend to get this error when calling .hittable or .tap() on an element but I cannot tell why. I've checked that the elements I'm dealing with all have their accessibility settings correctly setup and that any container views that they are in don't have accessibilty enabled. Alas, this doesn't seem to resolve the problem.

The console log reveals:

UI Testing Failure - Failure fetching attributes for element <XCAccessibilityElement: 0x7e68ae50> pid: 89032, context: 4D9272C7-3024-4062-B0FA-E16EF426F17A, payload: {     pid = 89032;     "uid.elementID" = 1432;     "uid.elementOrHash" = 2125772976; }: Error Domain=XCTestManagerErrorDomain Code=13 "Error copying attributes -25202" UserInfo={NSLocalizedDescription=Error copying attributes -25202} 

I've tried searching around and managed to find it's already been logged but there appears to be no current solution (radar link) even for Xcode 7.3.

It seems that sometimes if I restart the simulator/device this error doesn't happen but this isn't a nice solution.

1 Answers

Answers 1

This is apple's bug you can also show in apple's link. Here some guys suggest some solution might be work for you. If any solution not work for you then report a bug to apple. We can not do anything in this type of situation.

Read More