Environment variables and launch arguments
You can pass environment variables and launch arguments with an XCUITest run, without rebuilding your test bundle. Use this to point a suite at a staging backend, switch on a test mode in your app, or pass any other run-specific setting.
There are two targets:
- testEnv and testArgs: for the process that runs your test code
- appEnv and appArgs: for your app, when a test launches it
Test runner: testEnv and testArgs
testEnv sets environment variables and testArgs adds launch arguments for the process that runs your test code. Read them in your tests with ProcessInfo.processInfo.environment and ProcessInfo.processInfo.arguments.
testingbot xcuitest app.ipa app-test.zip \
--device "iPhone.*" \
--real-device \
--test-env API_URL=https://staging.example.com \
--test-env RETRIES=2 \
--test-arg=-verbose
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/xcuitest/:id/run" \
-d '{ "options": { "testEnv": { "API_URL": "https://staging.example.com", "RETRIES": "2" }, "testArgs": ["-verbose"] }, "capabilities":[{"deviceName":"iPhone.*", "platformName":"iOS", "realDevice": true}]}' \
-H "Content-Type: application/json"
let apiURL = ProcessInfo.processInfo.environment["API_URL"]
let verbose = ProcessInfo.processInfo.arguments.contains("-verbose")
App under test: appEnv and appArgs
appEnv sets environment variables and appArgs adds launch arguments for your app when a test starts it with XCUIApplication().launch(). Your app reads them with ProcessInfo.processInfo.environment and ProcessInfo.processInfo.arguments, the same way it would read launchEnvironment and launchArguments set in the test code.
testingbot xcuitest app.ipa app-test.zip \
--device "iPhone.*" \
--real-device \
--app-env FEATURE_NEW_CHECKOUT=on \
--app-arg=-UITestMode
curl -u api_key:api_secret \
-X POST "https://api.testingbot.com/v1/app-automate/xcuitest/:id/run" \
-d '{ "options": { "appEnv": { "FEATURE_NEW_CHECKOUT": "on" }, "appArgs": ["-UITestMode"] }, "capabilities":[{"deviceName":"iPhone.*", "platformName":"iOS", "realDevice": true}]}' \
-H "Content-Type: application/json"
Rules and limits
-
testEnvandappEnvare JSON objects. Names start with a letter or underscore and contain only letters, digits and underscores. Values are strings; numbers and booleans are converted to strings. -
testArgsandappArgsare JSON arrays of strings. - With the CLI, write an argument that starts with a dash with an equals sign, for example
--test-arg=-verbose, so it is not read as a CLI option. - Up to 100 variables per object and 100 arguments per list; each value can be up to 4096 characters.
- Options that break these rules make the API answer with a
400error. - Do not pass passwords or access tokens in these options.
You can combine these options with test filters and the other XCUITest options in the same options object.