Sauce Labs XCUITest Example

Link to Sauce Labs XCUITest Example copied to clipboard

Empower your team to focus on identifying and resolving accessibility issues on real devices from Sauce Labs.

Free Trial

Run your UI Tests on Sauce Labs to get a comprehensive understanding of your app's accessibility health across devices.

Prerequisites

  1. Your UITests are integrated with axe DevTools Mobile for iOS. Checkout our getting started guide if needed.

  2. Prepare your app for distribution. Since we'll be testing on Sauce Labs with real devices, we found having the app and UITest targets provisioned before sending it to their service to be resigned results in a smoother process.

  3. Install saucectl command-line interface and set up your Sauce Labs credentials. Follow the instructions from Sauce Labs.

tip

Looking for an example? Our Sample iOS Project has an integration ready to test.

  1. Finish the prerequisites
  2. Download the sample project from Github
  3. Open a Terminal window, enter cd , then drag and drop the axe-devtools-ios-sample-app from Finder into the Terminal window. Hit return/enter.
  4. In the same window, type sh prepareForSauce.sh. Hit return/enter.

Add Sauce Labs Configuration

Sauce Labs uses a yaml file at the project root located at .sauce/config.yml. A sample config file is below:

apiVersion: v1alpha
kind: xcuitest
sauce:
  region: us-west-1
  concurrency: 1

xcuitest:
  app: "<app_name>.ipa"
  testApp: "<app_name>UITests-Runner.ipa"

suites:
  - name: "<app_name>UITests"
    devices:
      - name: "iPhone.*"
        platformVersion: "17.2"

Build Setup

warning

Sauce Labs only supports testing on "Real Devices" with XCUITests. Read more about Sauce Labs integration with XCUI.

In Terminal from your project's root folder, call the below command to create device builds without needing to have a device plugged into your computer:

xcodebuild build-for-testing -configuration Debug \
                             -scheme "$APP_SCHEME" \
                             -target "$APP_UITEST_TARGET" \
                             -sdk iphoneos \
                             -derivedDataPath "./DerivedData"

This command will generate two app files located at ./DerivedData/Build/Products/Debug-iphoneos/: Your iOS application and your UI tests (ending in UITests-Runner).

Next, convert both application files to .ipa files. Follow Sauce Labs' instructions on creating IPA files.

Once the .ipa files are created, create an apps folder in the project's directory and add both .ipa files to it.

Try running the below command to push the .ipa files to Sauce Labs and begin testing. saucectl run

note

Are you using additional continuous integration tools? Sauce Labs supports testing within your current environment. Learn more about integration with your CI pipeline and Sauce Labs.

Automation

Once you've confirmed your configurations are set up correctly, you're ready to automate this process! We've included a script below to automatically build .ipa files for devices, upload them to Sauce Labs, and run your XCUITests. Your team can also use this script to invoke a test run on Sauce Labs manually.

APP_LOCATION="DerivedData/Build/Products/Debug-iphoneos"
APP_NAME="<app_name>"

rm -rf *.ipa

xcodebuild build-for-testing -configuration Debug \
       -scheme "<scheme_name>" \
       -target "<UITests target>" \
       -sdk iphoneos \
       -derivedDataPath "./DerivedData" \
       -quiet

mkdir Payload

mv $APP_LOCATION/$APP_NAME.app Payload
zip -r -qq "$APP_NAME.ipa" Payload
rm -rf Payload/*

mv $APP_LOCATION/${APP_NAME}UITests-Runner.app Payload
zip -r -qq "${APP_NAME}UITests-Runner.ipa" Payload

saucectl run

rm -rf Payload
rm -rf DerivedData