Skip to content

Commit

Permalink
Feat: set up Playwright (#2554)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran authored Feb 5, 2025
2 parents fc10e0c + efcf709 commit 02057b8
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 1 deletion.
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

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

0 comments on commit 02057b8

Please sign in to comment.