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

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 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
12 changes: 12 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ services:
- "8000"
volumes:
- ./.devcontainer:/.devcontainer

playwright:
build:
context: .
dockerfile: playwright/Dockerfile
image: benefits_client:playwright
env_file: playwright/.env
volumes:
- ./playwright:/playwright
# https://code.visualstudio.com/docs/remote/create-dev-container#_use-docker-compose
entrypoint: sleep infinity
profiles: ["testing"]
10 changes: 10 additions & 0 deletions playwright/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MEDICARE_FLOW_USERNAME=
MEDICARE_FLOW_PASSWORD=

AGENCY_CARD_SUB=
AGENCY_CARD_NAME=

TRANSIT_PROCESSOR_CARDHOLDER_NAME=
TRANSIT_PROCESSOR_CARD_NUMBER=
TRANSIT_PROCESSOR_CARD_EXPIRATION=
TRANSIT_PROCESSOR_CARD_SECURITY_CODE=
3 changes: 3 additions & 0 deletions 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 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 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 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 playwright/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pytest
pytest-playwright
pytest-reporter-html1
8 changes: 8 additions & 0 deletions playwright/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

base_url="https://dev-benefits.calitp.org"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe take this from the command line?


# also uses arguments from pytest.ini
pytest --base-url $base_url
70 changes: 70 additions & 0 deletions playwright/test_agencycard_flow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os

from playwright.sync_api import Page, expect


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you meant page.goto("/")?


# 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 = os.environ.get("AGENCY_CARD_SUB")
page.get_by_placeholder("12345").fill(sub)
page.keyboard.press("Tab")

name = os.environ.get("AGENCY_CARD_NAME")
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 = os.environ.get("TRANSIT_PROCESSOR_CARDHOLDER_NAME")
popup.get_by_label("Cardholder name").fill(cardholder_name)
popup.keyboard.press("Tab")

card_number = os.environ.get("TRANSIT_PROCESSOR_CARD_NUMBER")
popup.get_by_label("Card number").fill(card_number)
popup.keyboard.press("Tab")

expiration = os.environ.get("TRANSIT_PROCESSOR_CARD_EXPIRATION")
popup.get_by_label("mm/yy").fill(expiration)
popup.keyboard.press("Tab")

security_code = os.environ.get("TRANSIT_PROCESSOR_CARD_SECURITY_CODE")
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 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 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
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
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