How to pass parameters to test execution


#1

Ranorex Webtesit allows you to pass custom properties to the test execution. You can define these properties in the *.endpoints.json files.

{
  "endpoints": [
    {
      "active": true,
      "capabilities": {},
      "headless": false,
      "id": "6b50c119-b2b3-12a1-3796-2815c408b7f1",
      "name": "ChromeEndpoint",
      "type": "local",
      "browserName": "chrome",
      "environment": {      // pass parameters just to this specific endpoint
        "aString": "abc",
        "aNumber": 100,
        "aBoolean": false,
        "anArray": [
          "a",
          "b",
          "c"
        ],
        "anObject": {
          "a": 1,
          "b": 2,
          "c": 3
        }
      }
    }
  ],
  "environment": {         // pass parameters to all endpoints in this file
    "aNumber": 42,
    "language": "en"
  }
}

Note: Array and object values are passed as JSON strings.

If you pass the same property once globally to all endpoints and once to a specific endpoint, like aNumber in the sample above, the endpoint specific property will overwrite the other one. Meaning in this sample, aNumber would be 100 for the ChromeEndpoint, but for all other endpoints it would still be 42.

Another thing worth mentioning is, that some properties are already used by Ranorex Webtestit. When you define such a property, the JSON schema warns you and it will have no effect on the test execution as those custom values would be overwritten by the predefined ones.

Accessing the passed parameters
Depending on the programming language you use, there are different ways on how to access those properties:

  • Java with Selenium and TestNG

    String language = System.getenv("language")
    int aNumber = Integer.parseInt(System.getenv("aNumber"));
    
  • TypeScript with Protractor

    const language = process.env.language;
    const aNumber = parseInt(process.env.aNumber, 10);
    

    NOTE: The types for NodeJS are not installed by default. Open the project in a terminal and install the types with the command npm install --save-dev @types/node in order to use process.

  • Python with Selenium and unittest

    language = os.environ.get("language")
    a_number = int(os.environ.get("aNumber"))