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: Playwright setup #2500

Closed
wants to merge 11 commits into from
Closed
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
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,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
3 changes: 3 additions & 0 deletions tests/playwright/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-playwright
pytest-reporter-html1
6 changes: 6 additions & 0 deletions tests/playwright/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e

# also uses arguments from pytest.ini
pytest
68 changes: 68 additions & 0 deletions tests/playwright/test_agencycard_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from playwright.sync_api import Page, expect


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

# Index - select transit agency
page.get_by_role("link", name="Choose your Provider").click()
page.get_by_role("link", name="California State Transit (dev)").click()

# Eligibility Index - select enrollment flow
page.get_by_label("Agency Cardholder").check()
page.get_by_role("button", name="Choose this benefit").click()

# Eligibility Start - continue
page.get_by_role("button", name="Continue").click()

# Eligibility Confirm - fill out form and submit
page.get_by_placeholder("12345").click()

sub = "71162"
page.get_by_placeholder("12345").fill(sub)
page.keyboard.press("Tab")

name = "Box"
page.get_by_placeholder("Hernandez-Demarcos").fill(name)

page.get_by_role("button", name="Find my record").click()

# Enrollment Index - fill out transit processor form in pop-up window
page.mouse.wheel(0, 200)

with page.expect_popup() as popup_info:
page.get_by_role("button", name="Enroll").click()

popup = popup_info.value
popup.wait_for_timeout(3000)

popup.get_by_text("Cardholder name").click()

cardholder_name = "Test User"
popup.get_by_label("Cardholder name").fill(cardholder_name)
popup.keyboard.press("Tab")

card_number = "4111 1111 1111 1111"
popup.get_by_label("Card number").fill(card_number)
popup.keyboard.press("Tab")

expiration = "12/34"
popup.get_by_label("mm/yy").fill(expiration)
popup.keyboard.press("Tab")

security_code = "123"
popup.get_by_text("Security code", exact=True).click()
popup.get_by_label("Security code").fill(security_code)

# trigger form validation - not sure why their form behaves this way
popup.keyboard.press("Shift+Tab")
popup.keyboard.press("Shift+Tab")
popup.keyboard.press("Shift+Tab")
popup.keyboard.press("Tab")

popup.get_by_role("group", name="Enter your card details").get_by_role("button").click()

page.wait_for_timeout(10000)

success_message = page.get_by_text("You can now use your contactless card to tap to ride with a reduced fare!")
expect(success_message).to_be_visible()
13 changes: 13 additions & 0 deletions tests/playwright/test_logingov_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from playwright.sync_api import Page


def test_older_adult_flow(page: Page):
pass


def test_veteran_flow(page: Page):
pass


def test_calfresh_cardholder_flow(page: Page):
pass
26 changes: 26 additions & 0 deletions tests/playwright/test_medicaregov_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

import pytest

from playwright.sync_api import Page, expect


@pytest.mark.skip(reason="WIP - Medicare.gov not allowing test to login")
def test_medicare_cardholder_flow(page: Page):
page.goto("/")
page.click("text='Choose your Provider'")
page.get_by_role("link", name="California State Transit (dev)").click()
page.get_by_label("Medicare Cardholder You must").check()
page.get_by_role("button", name="Choose this benefit").click()
page.get_by_role("button", name="Continue to Medicare.gov").click()
page.get_by_label("Username", exact=True).click()

username = os.environ.get("MEDICARE_FLOW_USERNAME")
page.get_by_label("Username", exact=True).fill(username)

password = os.environ.get("MEDICARE_FLOW_PASSWORD")
page.get_by_label("Password").fill(password)

page.get_by_role("button", name="Log in").click()

expect
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