Pass in any pylenium.json file when running tests
v1.16.0 - 2022.07.05
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.jsonat 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
.jsonand have the same shape (aka schema) as the defaultpylenium.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:
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:
COMMANDandUSER - A global, Pylenium Logger instance that can be used by the User if they choose
Log Levels
| Name | Level | |
| CRITICAL | 50 | |
| ERROR | 40 | |
| WARNING | 30 | |
| USER | 25 | new |
| INFO | 20 | |
| COMMAND (new and default) | 15 | new, default |
| DEBUG | 10 |
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:
pytest --log-cli-level=INFO💡 The above command would ignore logs below the
INFOlevel. In other words, ignore theCOMMANDandDEBUGlogs.
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:
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
%sformat 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():
# 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 cartYou can also directly use py.log:
# 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