Member-only story

iOS: XCUITest and it’s nuances

Tiya Chows
2 min readNov 13, 2017

--

A quick post for anyone wanting to use Apple’s XCTest framework to automate testing an iOS app.

Thankfully, there is a large amount of documentation and help available online. However, over the last few months I have come across a number of nuances within the framework and language that have tripped me up. Hopefully this post is a shortcut for you!

  1. If the header element is offscreen and then later scrolled into view. The app hierarchy is not refreshed with the id of that header and the UI tests will not be able to access that element. This does not apply to cells.
  2. If Accessibility Ids are assigned and the accessiblityElement=true attribute is set on the parent element, this will block all child elements from being accessible. https://www.deque.com/blog/ios-nested-accessibility/
  3. Unknown code failures? Delete the “Derived data” folder under preferences and clean build folder and rebuild.
  4. Missing files in Xcode but files are present in finder? Right-click on directory in Xcode and click “Add files to..” all files that are not in Xcode will be shown. If you are referencing these “missing” files, you will see compilation errors.
  5. Scrolling! Apple’s inbuilt swipeUp() method has a set amount of scrolling. As a result, this could scroll past your element. I have created the following helper method to try and work around it!
The swipeUpToElement() method takes an XCUI element as a parameter and will only scroll until the element is within the window.

Tip:

Use print(app.debugDescription)

This command will expose the elements in a view and their accessibility ids.

--

--

Tiya Chows
Tiya Chows

Written by Tiya Chows

Software Engineer @GoldmanSachs. I write technical articles about building software, but short stories and poetry feed my soul.

No responses yet