pylenium.json
[267]
The major update for this release is the ability to pass in any `pylenium.json` config file when executing your tests! Before v1.16.0, there was only a _single_ `pylenium.json` file that existed at your Project Root (after running `$ pylenium init`) and this was the main config file to change.
> ๐ก Now you can keep multiple versions of the file and use the one you need (see the Example below ๐ โฌ๏ธ
Example
You can keep different versions stored at your Project Root or in a separate folder.
Keep things at the Project Root...
๐ Project
๐ conftest.py
๐ pylenium.json
๐ local.pylenium.json
...
or put your custom ones in a different folder.
> Keep the original `pylenium.json` at the Project Root so the default behavior continues to work ๐
๐ Project
๐ conftest.py
๐ pylenium.json
๐ config
๐ local.pylenium.json
๐ dev.pylenium.json
๐ stage.config.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`
Finally, when you execute the tests, you can pass in which Pylenium config file to use for that run using the `--pylenium_json` argument:
bash
pytest --pylenium_json="local.pylenium.json"
pytest --pylenium_json="config/dev.pylenium.json"
Updated Logging
[206]
The other big change was around using `rich-click` (which is a combination of the `rich` and `click` packages) for cleaner and prettier logging and printing. With this change, a few other things were added:
- Two new, custom Log Levels: `COMMAND` and `USER`
- A global, Pylenium Logger instance that _can_ be used by the User if they choose
Log Levels
<table>
<tr>
<td>Name
<td>Level
<td>
<tr>
<td>CRITICAL
<td>50
<td>
<tr>
<td>ERROR
<td>40
<td>
<tr>
<td>WARNING
<td>30
<td>
<tr>
<td>USER
<td>25
<td>new
<tr>
<td>INFO
<td>20
<td>
<tr>
<td>COMMAND (new and default)
<td>15
<td>new, default
<tr>
<td>DEBUG
<td>10
<td>
</table>
If you are familiar with logging, then the above table is straightforward. If not, then all you really need to know about these levels is that you can set the Log Level when executing tests, and any logs at the specified level or higher will be captured.
For example, if you wanted to set the Log Level to see only logs at `INFO` and higher, you would do this:
bash
pytest --log-cli-level=INFO
> ๐ก The above command would ignore logs _below_ the `INFO` level. In other words, ignore the `COMMAND` and `DEBUG` logs.
COMMAND Level
The `COMMAND` Log Level is used by Pylenium for logging its commands in a cleaner and easier to parse format. You shouldn't use this level unless you _really want to_. Take a look at our `visit()` command to see it in action:
py
def visit(self, url: str) -> "Pylenium":
"""Navigate to the given URL.
Returns:
The current instance of Pylenium
"""
log.command("py.visit() - Visit URL: `%s`", url)
self.webdriver.get(url)
return self
> ๐ก Notice how the string uses the `%s` format and NOT the f-string format. This is intentional!
USER Level
The `USER` Log Level is meant for you! This is a convenient way for logging things if you don't want everything from the `INFO` level.
> ๐ก I highly recommend creating your own loggers, but sometimes something simple like this is all you need ๐
To take advantage of this level, use `log.this()`:
py
You can import this in any file
from pylenium.log import logger as log
Log this
def add_to_cart(item: str, quantity: int):
log.this("Adding %s %s to my cart", quantity, item)
...
Then call the function
add_to_cart("Charizard", 3)
>>> USER Adding 3 Charizard to my cart
You can also directly use `py.log`:
py
Log this
def add_to_cart(py: Pylenium, item: str, quantity: int):
py.log.this("Adding %s %s to my cart", quantity, item)
...
Then call the function
add_to_cart(py, "Charizard", 3)
>>> USER Adding 3 Charizard to my cart
Other Changes
- Add `Element.upload()` command (258)
- Add `Element.focus()` command (257)
- Resolve ReportPortal warnings from `pytest.ini` (255)
- Fix dependency conflicts with the `black` package (263)
- Fix outdated ReportPortal imports in `conftest.py` (268)
- Rename `Element.get_cookies()` to `Element.get_all_cookies()`