Skip to main content
No Result Found
Connect & Get help from fellow developers on our Discord community. Ask the CommunityAsk the Community

Set environment variables

Securely manage information in your Maestro tests by setting them as environment variables. Learn how to pass and use them in your flow files.

When running your Maestro tests on BrowserStack App Automate, you can securely pass information like usernames, passwords, etc., as environment variables. This method ensures that your sensitive information is not hard-coded in your test scripts.

Environment variable values are directly visible on the dashboard and are not currently masked. Avoid using sensitive values unless necessary.

Key features of environment variables

  • Set during build creation: Environment variables are defined only when you create a build.
  • Immutable after build starts: Once a build is running, its environment variables are locked and cannot be updated or removed.
    • To change any variables, you must start an entirely new build.
  • Unrestricted naming and values: You can use any name or value for your variables, as there are no restrictions on length, allowed characters, or reserved words.

Set environment variables

To set environment variables, use the setEnvVariables capability in your builds REST API request. This capability accepts a JSON object of key-value pairs.

Here’s an example of a curl request to the App Automate API that sets USERNAME and PASSWORD environment variables:

curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/android/build" \
-H "Content-Type: application/json" \
-d '{
  "app": "bs://<app_id>",
  "testSuite": "bs://<test_suite_id>",
  "networkLogs": "true",
  "deviceLogs": "true",
  "devices": ["<your_device>"],
  "setEnvVariables": {
    "USERNAME": "abcxyz",
    "PASSWORD": "password123"
  }
}'
curl -u "YOUR_USERNAME:YOUR_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/maestro/v2/ios/build" \
-H "Content-Type: application/json" \
-d '{
  "app": "bs://<app_id>",
  "testSuite": "bs://<test_suite_id>",
  "networkLogs": "true",
  "deviceLogs": "true",
  "devices": ["<your_device>"],
  "setEnvVariables": {
    "USERNAME": "abcxyz",
    "PASSWORD": "password123"
  }
}'

In the above example, the setEnvVariables object contains two key-value pairs. USERNAME is set to abcxyz and PASSWORD is set to password123.

Use environment variables in your test scripts

After you’ve set the environment variables in your API request, you can access them in your Maestro flow files using the ${VARIABLE_NAME} syntax.

If your Maestro flow file references an environment variable that you did not set in the API request, Maestro treats the variable as NULL. There is no default value. The test execution begins, but whether it passes or fails depends on your app or test logic.

Here is an example of a Maestro flow file (flowfile.yml) that uses the USERNAME and PASSWORD variables set in the previous step:

flowfile.yml
Copy icon Copy

In this flow, Maestro replaces ${USERNAME} and ${PASSWORD} with the values you provided in the setEnvVariables capability of your API call. This allows you to keep your sensitive information out of your test scripts, making them more secure and easier to manage.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback!

Talk to an Expert
Download Copy Check Circle