|
| 1 | +import os |
| 2 | +from playwright.sync_api import Page, expect |
| 3 | + |
| 4 | + |
| 5 | +def test_medicare_cardholder_flow(page: Page): |
| 6 | + page.goto("/") |
| 7 | + |
| 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() |
| 14 | + |
| 15 | + page.add_init_script("delete Object.getPrototypeOf(navigator).webdriver") |
| 16 | + |
| 17 | + page.get_by_role("button", name="Continue to Medicare.gov").click() |
| 18 | + |
| 19 | + page.get_by_label("Username", exact=True).click() |
| 20 | + |
| 21 | + username = os.environ.get("PLAYWRIGHT_MEDICARE_GOV_USERNAME") |
| 22 | + page.get_by_label("Username", exact=True).fill(username) |
| 23 | + |
| 24 | + 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") |
| 61 | + |
| 62 | + popup.get_by_role("group", name="Enter your card details").get_by_role("button").click() |
| 63 | + |
| 64 | + page.wait_for_timeout(10000) |
| 65 | + |
| 66 | + success_message = page.get_by_text("You can now use your contactless card to tap to ride with a reduced fare!") |
| 67 | + expect(success_message).to_be_visible() |
0 commit comments