Sauce Labs Appium Example
Below is an example for running your Appium tests integrated with axe DevTools against Sauce Labs.
Setup Configuration
Using Sauce Labs to test your project with Appium requires setting the iOSDriver
URL within the test file to point to the below Sauce Labs URL. Be sure to plug in your Sauce Labs username and access key.
public static final String URL = "https://" + SAUCE_USERNAME +":" + SAUCE_ACCESS_KEY +"@ondemand.us-west- 1.saucelabs.com:443/wd/hub";
Next, check that the desired capabilities for Appium are set correctly within the test file. Update or set the app capability:
caps.setCapability("app", "storage:filename=<APP NAME AS IT APPEARS ON SAUCE STORAGE>");
Build Setup
With the configurations and test file ready, let's create a build and upload it to Sauce Labs for testing. Use the below script from the project's root, or follow the documentation to build your app and upload it manually.
APP_LOCATION="DerivedData/Build/Products/Debug-iphoneos"
APP_NAME=“./apps/$APP_NAME.ipa”
xcodebuild -configuration Debug \
-scheme SCHEME HERE \
-sdk iphoneos \
-derivedDataPath "./DerivedData"
mkdir Payload
mkdir apps
mv $APP_LOCATION/$APP_NAME.app Payload
zip -r $APP_NAME Payload
rm -rf Payload/*
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" --location \
--request POST 'https://api.us-west-1.saucelabs.com/v1/storage/upload' \
--form 'payload=@""' \
--form 'name=$APP_NAME
rm -rf apps
rm -rf DerivedData
Run Tests
Make a call to the testing framework you're using to run your tests. You may add your testing command to the above script or create a new one.
This command will vary by the testing framework used.
The axeDevToolsUIKit.xcframework supports SauceLabs and Appium on a simulator or real device. Please see the SauceLabs documentation for instructions on how to get set up.
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 tests. 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 Here"
xcodebuild build-for-testing -configuration Debug \
-scheme "$APP_SCHEME" \
-target "$APP_UITEST_TARGET" \
-sdk iphoneos \
-derivedDataPath "./DerivedData"
mkdir Payload
mkdir apps
mv $APP_LOCATION/$APP_NAME.app Payload
zip -r "apps/$APP_NAME.ipa" Payload
rm -rf Payload/*
mv $APP_LOCATION/${APP_NAME}UITests-Runner.app Payload
zip -r "apps/${APP_NAME}UITests-Runner.ipa" Payload
rm -rf Payload
# call testing framework to run tests
./gradlew test