0

I'd like to add a variable into each test, for example ${url}. Into a single test, this is the JSON code:

    "data": {
    "configs": {
      "manual": {
        "url": "https://my_url"
      }
    },
    "source": "manual"
  },

I want to share ${url} variable with all my tests. How should i go about this?

ham-sandwich
  • 3,975
  • 10
  • 34
  • 46
Maxime
  • 1
  • 2

1 Answers1

0

As stated in the Selenium Builder wiki under Data driven Testing you can store variables as an array of objects.

For your use you will make the file look like this:

[
    {"url" : "https://my_url"}
]

save the file as test_values.json in the same folder as your test and reference it like this in your test.json:

"data": {
"configs": {
  "json": {
    "path": "test_values.json"
  }
},
"source": "json"
},

If you need to pass multiple variables to your test do it inside the object (the curly braces) like this:

[
    {
        "url" : "https://my_url",
        "user" : "some_user",
        "password" : "some_password"
    }
]

Now, the fun part is, that if you add another object (set of curly braces) like this:

[
    {
        "url" : "https://my_url",
        "user" : "some_user",
        "password" : "some_password"
    },
    {
        "url" : "https://my_url",
        "user" : "some_other_user",
        "password" : "some_other_password"
    }
]

Then the test will run twice. Once with the first set of values, and the second time with the second set of values.

Jon jokja
  • 1
  • 2