πŸ“„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.

pylenium.json is already created when using the pylenium init command

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": {},
    "seleniumwire_enabled": false,
    "seleniumwire_options": {},
    "local_path": ""
  },
  "logging": {
    "screenshots_on": true
  },
  "viewport": {
    "maximize": true,
    "width": 1440,
    "height": 900,
    "orientation": "portrait"
  },

  "custom": {}
}

Change a single value

You only need to change the values you care about.

If I only wanted to change the browser to be "firefox", then only include that:

{
  "driver": {
    "browser": "firefox"
  }
}

Adding custom values

You can add any objects within the custom object to be used by py.config

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"

You can name your custom Pylenium config files whatever you like, but they MUST be .json and have the same shape (aka schema) as the default pylenium.json

Last updated