Skip to content

Pass in any pylenium.json file when running tests

Choose a tag to compare

@ElSnoMan ElSnoMan released this 06 Jul 06:05
· 26 commits to main since this release

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.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:

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

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 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:

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():

# 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:

# 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()