Support & information center

How to use environment variables in test scripts via the API?

testRTC allows you to set your own customer environment variables in running test scripts via the APIs. This gives more flexibility when executing the commands from CI/CD or other test suite environments.

You can use environment variables to:

  1. Decide which URL to use (when launching tests on heroku machines for example)
  2. Pick specific room id’s or names in a test
  3. Decide on usernames or passwords
  4. Etc


Lets assume we want to create a custom variable to pick the room id for the user to join in a test.

We will call it ROOM_ID.

Inside our test script, we can refer to it as process.env.ROOM_ID, and use it in whatever fashion we need. Like:

client.rtcSetAdditionalInfo("process.env.ROOM_ID " + process.env.ROOM_ID);​Code language: JavaScript (javascript)

To populate ROOM_ID with a value, we need to add our environment variable as an array of tuples. Something like this:

"environmentVariables": [
        "variable": "ROOM_ID",
        "value": "room1"
]Code language: JSON / JSON with Comments (json)

Invoking it through cURL would be something like this:

curl -X POST "{{TESTID}}/run" -H "accept: application/json" -H "apikey: {{APIKEY}}" -H "Content-Type: application/json" -d "{ \"environmentVariables\": [{ \"variable\": \"ROOM_ID\", \"value\": \"room1\" } ]}"Code language: Bash (bash)

Was this article helpful?

Related Articles