Skip to content

Commit 9500dea

Browse files
committed
refactor(medicare_gov): use Page object model pattern
1 parent 228b856 commit 9500dea

File tree

2 files changed

+38
-48
lines changed

2 files changed

+38
-48
lines changed

tests/playwright/smoke_tests/models.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ def get_started_with_login_gov(self):
4242

4343
return LoginGov(page)
4444

45+
def continue_to_medicare_gov(self):
46+
page = self.page
47+
page.get_by_role("button", name="Continue to Medicare.gov").click()
48+
49+
return MedicareGov(page)
50+
4551

4652
class EligibilityConfirm:
4753
def __init__(self, page: Page):
@@ -85,6 +91,27 @@ def enter_otp(self, one_time_password):
8591
return EnrollmentIndex(page)
8692

8793

94+
class MedicareGov:
95+
def __init__(self, page: Page):
96+
self.page = page
97+
98+
def log_in(self, username, password):
99+
page = self.page
100+
101+
page.get_by_label("Username", exact=True).click()
102+
page.get_by_label("Username", exact=True).fill(username)
103+
104+
page.get_by_label("Password").fill(password)
105+
106+
page.get_by_role("button", name="Log in").click()
107+
108+
def accept_consent_screen(self):
109+
page = self.page
110+
page.get_by_role("button", name="Connect").click()
111+
112+
return EnrollmentIndex(page)
113+
114+
88115
class EnrollmentIndex:
89116
def __init__(self, page: Page):
90117
self.page = page

tests/playwright/smoke_tests/test_medicare_flow.py

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,29 @@
11
import os
22
from playwright.sync_api import Page, expect
33

4+
from models import Index
5+
46

57
def test_medicare_cardholder_flow(page: Page):
68
page.goto("/")
79

8-
page.click("text='Choose your Provider'")
9-
page.get_by_role("link", name="California State Transit").click()
10-
11-
page.get_by_label("Medicare Cardholder").check()
12-
page.wait_for_load_state("networkidle") # wait for reCAPTCHA to finish loading
13-
page.get_by_role("button", name="Choose this benefit").click()
10+
index = Index(page)
11+
eligibility_index = index.select_agency("California State Transit")
12+
eligibility_start = eligibility_index.select_flow("Medicare Cardholder")
1413

14+
# avoid looking like a bot
1515
page.add_init_script("delete Object.getPrototypeOf(navigator).webdriver")
1616

17-
page.get_by_role("button", name="Continue to Medicare.gov").click()
18-
19-
page.get_by_label("Username", exact=True).click()
17+
medicare_gov = eligibility_start.continue_to_medicare_gov()
2018

2119
username = os.environ.get("PLAYWRIGHT_MEDICARE_GOV_USERNAME")
22-
page.get_by_label("Username", exact=True).fill(username)
23-
2420
password = os.environ.get("PLAYWRIGHT_MEDICARE_GOV_PASSWORD")
25-
page.get_by_label("Password").fill(password)
26-
27-
page.get_by_role("button", name="Log in").click()
28-
29-
page.get_by_role("button", name="Connect").click()
30-
31-
# Enrollment Index - fill out transit processor form in pop-up window
32-
with page.expect_popup() as popup_info:
33-
page.get_by_role("button", name="Enroll").click()
34-
35-
popup = popup_info.value
36-
popup.wait_for_timeout(3000)
37-
38-
popup.get_by_text("Cardholder name").click()
39-
40-
cardholder_name = "Test User"
41-
popup.get_by_label("Cardholder name").fill(cardholder_name)
42-
popup.keyboard.press("Tab")
43-
44-
card_number = "4111 1111 1111 1111"
45-
popup.get_by_label("Card number").fill(card_number)
46-
popup.keyboard.press("Tab")
47-
48-
expiration = "12/34"
49-
popup.get_by_label("mm/yy").fill(expiration)
50-
popup.keyboard.press("Tab")
51-
52-
security_code = "123"
53-
popup.get_by_text("Security code", exact=True).click()
54-
popup.get_by_label("Security code").fill(security_code)
55-
56-
# trigger form validation - not sure why their form behaves this way
57-
popup.keyboard.press("Shift+Tab")
58-
popup.keyboard.press("Shift+Tab")
59-
popup.keyboard.press("Shift+Tab")
60-
popup.keyboard.press("Tab")
21+
medicare_gov.log_in(username, password)
22+
enrollment_index = medicare_gov.accept_consent_screen()
6123

62-
popup.get_by_role("group", name="Enter your card details").get_by_role("button").click()
24+
enrollment_index.enroll("Test User", "4111 1111 1111 1111", "12/34", "123")
6325

26+
# enrollment can take a bit
6427
page.wait_for_timeout(10000)
6528

6629
success_message = page.get_by_text("You can now use your contactless card to tap to ride with a reduced fare!")

0 commit comments

Comments
 (0)