Web Automation with Python

CukeTest has not yet integrated the Python version of Playwright, so if you need to record Python code for Web automation, you need to download Playwright manually.

Download Playwright

To use Playwright with pytest, install the pytest-playwright module.

pip install pytest-playwright

Next, install the appropriate browser by executing the command.

playwright install

Use Playwright

The most common scenario is the recording of generated web automation code, which can be started using the following command.

playwright codegen https://bing.com --target=python -o recording.py -b cr
  • --target: indicate which language automation code is generated, here python code is generated, default is Playwright's own defined test code.
  • -o: indicate which file the recorded code is output to, default is not output.
  • -b: indicate which browser to use for recording, default is Chromium browser, optional are Firefox ff, WebKit wk.

Specific usage can be seen on the command line with the -h option to help.

playwright codegen -h

Run Script

Assuming that the recording generates a file named recording.py, then just run python recording.py.

You can also run it using pytest, for example to run a test file:

pytest ./recording.py

Or run a test folder at:

pytest .

Or, alternatively, run a test method that satisfies the condition that:

pytest -k "test_add_a_todo_item"

results matching ""

    No results matching ""