Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: set up Playwright #2554

Merged
merged 8 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,21 @@ updates:
include: "scope"
labels:
- "dependencies"
- package-ecosystem: "docker"
directory: "/tests/playwright" # Playwright Docker image
schedule:
interval: "daily"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
- package-ecosystem: "pip"
directory: "/tests/playwright" # Playwright pytest plugin
schedule:
interval: "daily"
commit-message:
prefix: "chore"
include: "scope"
labels:
- "dependencies"
9 changes: 9 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ services:
- "8000"
volumes:
- ./.devcontainer:/.devcontainer

playwright:
build:
context: .
dockerfile: tests/playwright/Dockerfile
image: benefits_client:playwright
volumes:
- ./tests/playwright:/playwright
command: ./run.sh
10 changes: 10 additions & 0 deletions docs/tests/automated-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,13 @@ The report files include a local `.gitignore` file, so the entire directory is h
### Latest coverage report

We also make the latest (from `main`) coverage report available online here: [Coverage report](../coverage)

## Playwright

For testing the app flows from beginning to end, we use Playwright.

To run all Playwright tests locally, open a terminal outside the devcontainer and run:

```bash
docker compose run --rm playwright
```
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ test = [
"pytest",
"pytest-django",
"pytest-mock",
"pytest-playwright", # only for writing tests. run tests using playwright Docker Compose service
"pytest-socket",
]

Expand Down
3 changes: 3 additions & 0 deletions tests/playwright/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
.pytest_cache
test-results
11 changes: 11 additions & 0 deletions tests/playwright/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# https://playwright.dev/docs/docker
FROM mcr.microsoft.com/playwright/python:v1.48.0-jammy
angela-tran marked this conversation as resolved.
Show resolved Hide resolved

WORKDIR /playwright

COPY tests/playwright/requirements.txt requirements.txt

RUN python -m pip install --upgrade pip && \
pip install -r requirements.txt

USER pwuser
2 changes: 2 additions & 0 deletions tests/playwright/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
addopts = --tracing on -v --template=html1/index.html --report=test-results/report.html --video on
4 changes: 4 additions & 0 deletions tests/playwright/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
playwright==1.48.0 # needs to match version on Docker image
pytest
pytest-playwright
pytest-reporter-html1
5 changes: 5 additions & 0 deletions tests/playwright/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

set -e

pytest
7 changes: 7 additions & 0 deletions tests/playwright/test_healthcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from playwright.sync_api import Page, expect


def test_dev_healthcheck(page: Page):
page.goto("https://dev-benefits.calitp.org/healthcheck")

expect(page.get_by_text("Healthy")).to_be_visible()
2 changes: 1 addition & 1 deletion tests/pytest/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -eu

# run normal pytests
coverage run -m pytest
coverage run -m pytest tests/pytest

# clean out old coverage results
rm -rf benefits/static/coverage
Expand Down
Loading