πpylenium.json
The configuration file for Pylenium
Configure with a JSON File
If you don't want to use Pylenium's defaults but you don't want to configure it via the CLI, you can create a pylenium.json file at the Project Root (same directory as our conftest.py file) and do it with a JSON instead.
Here are all of the current settings (and their defaults) you can configure right now:
{
"driver": {
"browser": "chrome",
"remote_url": "",
"wait_time": 10,
"page_load_wait_time": 0,
"options": [],
"capabilities": {},
"experimental_options": null,
"extension_paths": [],
"webdriver_kwargs": {},
"local_path": ""
},
"logging": {
"screenshots_on": true
},
"viewport": {
"maximize": true,
"width": 1440,
"height": 900,
"orientation": "portrait"
},
"custom": {}
}
Change a single value
If I only wanted to change the browser to be "firefox"
, then only include that:
{
"driver": {
"browser": "firefox"
}
}
Adding custom values
Adding your own key/value pairs is easy:
{
"custom": {
"env_url": "https://staging.our-app.com"
}
}
Now you can use it like any other dictionary in Python:
py.config.custom.get("env_url")
---or---
py.config.custom["env_url"]
Complex custom objects
More complex or nested objects are easy to add as well:
{
"custom": {
"environment": {
"url": "https://staging.our-app.com",
"username": "foo",
"password": "bar",
"clusters": [ "cl01", "cl03", "cl05" ]
}
}
}
It's still just a Python dictionary, so you can easily access them:
# Get the entire environment object
py.config.custom.get("environment")
# Get only the url
py.config.custom["environment"]["url"]
# Get the first item in the list of clusters
py.config.custom["environment"]["clusters"][0]
Multiple Versions
You can have multiple pylenium.json
files and pick which one to use when executing tests.
For example, you can have multiple at your Project Root:
π Project
π conftest.py
π pylenium.json
π local.pylenium.json
...
or store them in another folder:
π Project
π conftest.py
π pylenium.json
π config
π local.pylenium.json
π dev.pylenium.json
π stage.config.json
Keep the original pylenium.json
at the Project Root so the default behavior continues to work π
Then, use the --pylenium_json
argument to pick which to use:
pytest --pylenium_json="local.pylenium.json"
pytest --pylenium_json="config/dev.pylenium.json"
Last updated