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.

Not for use with personal data

Using axe DevTools Mobile, you can find accessibility issues with your UI tests. Integrate your test with Sauce Labs and gain insights into your audience's experience with your app - before they've even seen it! This doesn't entail additional effort from your team. Sauce Labs is the largest cloud-based testing platform, hosting various device and emulator configurations to build your digital confidence. Configure your tests to run on Sauce within your current build automation to catch issues before they reach production.

Below is a guide for running your UI tests integrated with axe DevTools Mobile and Sauce Labs.

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 testing on Sauce Labs is performed with real devices, having the app and UITest targets provisioned before sending it to their service to be resigned will result in a smoother process.
  3. Install the 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. Verify that you have the prerequisites.
  2. Download the sample project from Github
  3. Open a Terminal window, enter cd , and 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. See the sample config file 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.

From your project's root folder in the Terminal, call the following 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.

Run the following 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