JCallico
JCallico

Reputation: 1467

Passing variables from selenium-side-runner

Given this very simple Selenium test:

Selenium side script with username and password

How can the username and password variables be provided while running the .side project using the selenium-side-runner? Either as command line parameters, statically typed on the .side.yml configuration file or coming from an external data file. Any option other than having the user credentials hardcoded in the .side file.

For reference, here is the content of .side file:

{
  "id": "2fcada56-fdb1-4acd-9d95-451e3d74c8f3",
  "version": "2.0",
  "name": "Todo",
  "url": "https://www.todo-cloud.com/",
  "tests": [{
    "id": "8e83c690-453d-4602-b187-015e9ee4cfe7",
    "name": "Login",
    "commands": [{
      "id": "453101ad-3249-47e9-bc87-860bbfdea343",
      "comment": "",
      "command": "open",
      "target": "https://www.todo-cloud.com/#/welcome/login",
      "targets": [],
      "value": ""
    }, {
      "id": "f14304b6-4f66-4b79-b1a5-39bd206f29af",
      "comment": "",
      "command": "type",
      "target": "name=username",
      "targets": [
        ["name=username", "name"],
        ["css=.ng-valid", "css:finder"],
        ["xpath=//input[@name='username']", "xpath:attributes"],
        ["xpath=//input", "xpath:position"]
      ],
      "value": "${username}"
    }, {
      "id": "a2520d2d-100b-4be4-93f7-d88f3ede804a",
      "comment": "",
      "command": "type",
      "target": "name=password",
      "targets": [
        ["name=password", "name"],
        ["css=.password", "css:finder"],
        ["xpath=//input[@name='password']", "xpath:attributes"],
        ["xpath=//div[2]/div/input", "xpath:position"]
      ],
      "value": "${password}"
    }]
  }],
  "suites": [{
    "id": "31c08a71-044c-4917-87e8-fcaacf3cd7ac",
    "name": "Default Suite",
    "persistSession": false,
    "parallel": false,
    "timeout": 300,
    "tests": ["8e83c690-453d-4602-b187-015e9ee4cfe7"]
  }],
  "urls": ["https://www.todo-cloud.com/"],
  "plugins": []
}

Upvotes: 0

Views: 1447

Answers (1)

Anderwan
Anderwan

Reputation: 21

This is a feature request in the selenium side project on GitHub, if I am not mistaken.

In the meantime, as a workaround, I would suggest using a pre-process.

Since .side files are JSON outputs, you can:

  • retrieve the JSON object contained in the .side file,
  • find the variable you want to modify
  • assign the new value
  • rewrite your new JSON object into a json file before renaming it with a .side extension

Upvotes: 2

Related Questions