A test automation web UI & API project using python, playwright & pytest. These tests currently interact with 2 websites - https://rickandmortyapi.com/ & https://www.automationexercise.com/. It implements the "page object model" practice for code structure. It implements BDD (using pytest-bdd).
All the commands below are for Windows:
- Your machine must have Python installed, ideally the latest version. Download the latest version of Python from Python.org.
- Install Poetry by running in PowerShell (as admin):
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -
- Clone the project to your local device e.g. via SSH you can run:
git clone git@github.com:jacob-mecoy/playwright-python-project.git
- Move into the project directory:
cd playwright-python-project - Install dependencies:
poetry install
- Activate Poetry shell (virtual environment):
poetry env activate
- Install Playwright browsers:
poetry run playwright install
- Some of the tests rely on importing environment variables. Therefore you will need to create a
.envfile in the project root with the required key:value pairs
# Install dependencies from lock file (recommended)
poetry install# Update specific package to latest version allowed in pyproject.toml
poetry update package-name
# Update all packages (use with caution)
poetry update# Show currently installed versions
poetry show
# Show outdated packages
poetry show --outdatedNote: Use poetry install for day-to-day development to ensure consistent dependencies. Only use poetry update when you intentionally want to upgrade packages to newer versions.
To run the tests, run through the "project setup" section and follow the below:
# Run all tests
poetry run pytest tests
# Run specific test file
poetry run pytest tests/<file_name>
# Run UI tests in headed mode
poetry run pytest tests --headed
# Run tests with slower execution
poetry run pytest tests --headed --slowmo 1000- All the tests are within the
testsfolder.- Each
test_...file imports scenarios from feature files using thescenarios(...)line it contains. View this line to understand which scenarios atest_...file "contains". testscontains one file for ui tests and one file for api tests.
- Each
- UI tests - By default, pytest runs the tests in headless mode.
Currently using ruff as both a linter and formatter. See https://docs.astral.sh/ruff/ for more information. We have a pyproject.toml file in the project root that contains some configuration for ruff.
# Run the linter
poetry run ruff check
# Run the formatter
poetry run ruff format