Sauce Labs XCUITest Example
With XCUITests looking for accessibility issues with axe DevTools Mobile, integration with Sauce Labs enables knowing what your audience will experience before it reaches their hands. All without additional effort from your team. Sauce Labs is the largest cloud-based testing platform hosting various device and simulator configurations to build your digital confidence. Configure your tests to run on Sauce within your current or future build automation to catch issues before they become production issues.
Below is a guide for running your XCUITests integrated with axe DevTools with Sauce Labs.
Prerequisites
-
Prepare your app for distribution. Since we'll be testing on Sauce Labs with real devices, we found having our app provisioned before sending it to their service to be resigned resulted in a smoother process.
-
Install
saucectl
command-line interface. Follow the instructions from Sauce Labs. -
Add your Sauce Labs credentials to your
.bash_profile
or.zshenv
. Be sure to load the changes by runningsource .filename
. Follow instructions from Sauce Labs.
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
options:
orientation: "portrait"
xcuitest:
app: "<app_name>.ipa"
testApp: "<app_name>UITests-Runner.ipa"
suites:
- name: "<app_name>UITests"
devices:
- name: "iPhone.*"
platformVersion: "15.3.1"
Build Setup
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
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/axe-devtools-ios-sample-appUITests-Runner.app Payload
zip -r -qq "axe-devtools-ios-sample-appUITests-Runner.ipa" Payload
saucectl run
rm -rf Payload
rm -rf DerivedData