Skip to content

Commit 71276be

Browse files
committed
refactor(tests): introduce fixtures for agency card flows
1 parent c5ddcc2 commit 71276be

File tree

6 files changed

+75
-21
lines changed

6 files changed

+75
-21
lines changed

tests/playwright/qa/__init__.py

Whitespace-only changes.

tests/playwright/qa/conftest.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,55 @@
1+
from dataclasses import dataclass
12
import pytest
23

34

5+
@dataclass
6+
class AgencyFlow:
7+
agency: str
8+
flow: str
9+
10+
11+
@dataclass
12+
class AgencyCardCredentials:
13+
sub: str
14+
name: str
15+
16+
17+
@dataclass
18+
class PaymentCard:
19+
cardholder_name: str
20+
card_number: str
21+
expiration: str
22+
security_code: str
23+
24+
425
@pytest.fixture
526
def browser_context_args():
627
return dict(user_agent="cal-itp/benefits-smoke-test")
28+
29+
30+
@pytest.fixture
31+
def agency_card_flows():
32+
return [
33+
(
34+
AgencyFlow(agency="California State Transit", flow="Agency Cardholder"),
35+
AgencyCardCredentials(sub="71162", name="Box"),
36+
),
37+
(
38+
AgencyFlow(agency="Monterey-Salinas Transit", flow="Courtesy Card"),
39+
AgencyCardCredentials(sub="71162", name="Box"),
40+
),
41+
(
42+
AgencyFlow(agency="Santa Barbara MTD", flow="Reduced Fare Mobility ID"),
43+
AgencyCardCredentials(sub="1234", name="Barbara"),
44+
),
45+
]
46+
47+
48+
@pytest.fixture
49+
def valid_payment_card():
50+
return PaymentCard(
51+
cardholder_name="Test User",
52+
card_number="4111 1111 1111 1111",
53+
expiration="12/34",
54+
security_code="123",
55+
)

tests/playwright/qa/models.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from playwright.sync_api import Page
88

9+
from .conftest import PaymentCard
10+
911

1012
class Index:
1113
def __init__(self, page: Page):
@@ -122,7 +124,7 @@ class EnrollmentIndex:
122124
def __init__(self, page: Page):
123125
self.page = page
124126

125-
def enroll(self, cardholder_name, card_number, expiration, security_code):
127+
def enroll(self, payment_card: PaymentCard):
126128
page = self.page
127129

128130
with page.expect_popup() as popup_info:
@@ -133,17 +135,17 @@ def enroll(self, cardholder_name, card_number, expiration, security_code):
133135

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

136-
popup.get_by_label("Cardholder name").fill(cardholder_name)
138+
popup.get_by_label("Cardholder name").fill(payment_card.cardholder_name)
137139
popup.keyboard.press("Tab")
138140

139-
popup.get_by_label("Card number").fill(card_number)
141+
popup.get_by_label("Card number").fill(payment_card.card_number)
140142
popup.keyboard.press("Tab")
141143

142-
popup.get_by_label("mm/yy").fill(expiration)
144+
popup.get_by_label("mm/yy").fill(payment_card.expiration)
143145
popup.keyboard.press("Tab")
144146

145147
popup.get_by_text("Security code", exact=True).click()
146-
popup.get_by_label("Security code").fill(security_code)
148+
popup.get_by_label("Security code").fill(payment_card.security_code)
147149

148150
# trigger form validation - not sure why their form behaves this way
149151
popup.keyboard.press("Shift+Tab")
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
from playwright.sync_api import BrowserContext, expect
22

3-
from models import Index
3+
from .models import Index
44

55

6-
def test_agency_card_flow(context: BrowserContext, base_url):
7-
page = context.new_page()
6+
def test_agency_card_flow(context: BrowserContext, base_url, agency_card_flows, valid_payment_card):
7+
for agency_flow, cred in agency_card_flows:
8+
print(agency_flow)
89

9-
page.goto(base_url)
10+
page = context.new_page()
1011

11-
index = Index(page)
12-
eligibility_index = index.select_agency("California State Transit")
13-
eligibility_start = eligibility_index.select_flow("Agency Cardholder")
14-
eligibility_confirm = eligibility_start.click_continue()
15-
enrollment_index = eligibility_confirm.submit_form("71162", "Box")
16-
enrollment_index.enroll("Test User", "4111 1111 1111 1111", "12/34", "123")
12+
page.goto(base_url)
1713

18-
# enrollment can take a bit
19-
page.wait_for_timeout(10000)
14+
index = Index(page)
15+
eligibility_index = index.select_agency(agency_flow.agency)
16+
eligibility_start = eligibility_index.select_flow(agency_flow.flow)
17+
eligibility_confirm = eligibility_start.click_continue()
18+
enrollment_index = eligibility_confirm.submit_form(cred.sub, cred.name)
19+
enrollment_index.enroll(valid_payment_card)
2020

21-
success_message = page.get_by_text("You can now use your contactless card to tap to ride with a reduced fare!")
22-
expect(success_message).to_be_visible()
21+
# enrollment can take a bit
22+
page.wait_for_timeout(15000)
23+
24+
success_message = page.get_by_text("You can now use your contactless card to tap to ride with a reduced fare!")
25+
expect(success_message).to_be_visible()

tests/playwright/qa/test_login_gov_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from playwright.sync_api import BrowserContext, expect
44
import pyotp
55

6-
from models import Index
6+
from .models import Index
77

88

99
def test_older_adult_flow(context: BrowserContext, base_url):

tests/playwright/qa/test_medicare_flow.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import os
22
from playwright.sync_api import BrowserContext, expect
33

4-
from models import Index
4+
from .models import Index
55

66

77
def test_medicare_cardholder_flow(context: BrowserContext, base_url):

0 commit comments

Comments
 (0)