|
1 | 1 | import os
|
2 | 2 | from playwright.sync_api import Page, expect
|
3 | 3 |
|
| 4 | +from models import Index |
| 5 | + |
4 | 6 |
|
5 | 7 | def test_medicare_cardholder_flow(page: Page):
|
6 | 8 | page.goto("/")
|
7 | 9 |
|
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") |
14 | 13 |
|
| 14 | + # avoid looking like a bot |
15 | 15 | page.add_init_script("delete Object.getPrototypeOf(navigator).webdriver")
|
16 | 16 |
|
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() |
20 | 18 |
|
21 | 19 | username = os.environ.get("PLAYWRIGHT_MEDICARE_GOV_USERNAME")
|
22 |
| - page.get_by_label("Username", exact=True).fill(username) |
23 |
| - |
24 | 20 | 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() |
61 | 23 |
|
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") |
63 | 25 |
|
| 26 | + # enrollment can take a bit |
64 | 27 | page.wait_for_timeout(10000)
|
65 | 28 |
|
66 | 29 | success_message = page.get_by_text("You can now use your contactless card to tap to ride with a reduced fare!")
|
|
0 commit comments