test_1644830_missingmail_usps.py (2625B)
1 import pytest 2 from webdriver.error import NoSuchElementException 3 4 URL = "https://missingmail.usps.com/?_gl=1*veidlp*_gcl_aw*R0NMLjE1OTE3MjUyNTkuRUFJYUlRb2JDaE1Jd3AzaTBhYjE2UUlWa01EQUNoMlBBUVlrRUFBWUFTQUFFZ0lMeFBEX0J3RQ..*_gcl_dc*R0NMLjE1OTE3MjUyNTkuRUFJYUlRb2JDaE1Jd3AzaTBhYjE2UUlWa01EQUNoMlBBUVlrRUFBWUFTQUFFZ0lMeFBEX0J3RQ..#/" 5 6 USERNAME_CSS = "input[autocomplete=username]" 7 PASSWORD_CSS = "input[autocomplete=current-password]" 8 PRIMARY_BUTTON_CSS = "button.btn-primary[type=submit]" 9 TERMS_CHECKBOX_CSS = "#tc-checkbox" 10 TERMS_FAUX_CHECKBOX_CSS = "#tc-checkbox + .mrc-custom-checkbox" 11 12 # The USPS missing mail website takes a very long time to load (multiple 13 # minutes). We give them a very generous amount of time here, but will 14 # give up after that and just skip the rest of the test. 15 TIMEOUT = 900 16 TIMEOUT_MESSAGE = "USPS website is too slow, skipping test" 17 18 19 async def are_checkboxes_clickable(client, credentials): 20 # The site seems to silently reject logins when it detects webdriver. 21 await client.make_preload_script("delete navigator.__proto__.webdriver") 22 await client.navigate(URL) 23 24 username = client.await_css(USERNAME_CSS) 25 password = client.find_css(PASSWORD_CSS) 26 sign_in = client.find_css(PRIMARY_BUTTON_CSS) 27 assert client.is_displayed(username) 28 assert client.is_displayed(password) 29 assert client.is_displayed(sign_in) 30 31 username.send_keys(credentials["username"]) 32 password.send_keys(credentials["password"]) 33 sign_in.click() 34 35 try: 36 client.await_css( 37 ".custom-control-label", 38 condition="elem.innerText.includes('Not Now')", 39 is_displayed=True, 40 ).click() 41 client.await_css(PRIMARY_BUTTON_CSS, is_displayed=True).click() 42 except NoSuchElementException: 43 pass 44 45 tc = client.await_css(TERMS_CHECKBOX_CSS, timeout=TIMEOUT) 46 if tc is None: 47 pytest.skip(TIMEOUT_MESSAGE) 48 return 49 50 assert not tc.selected 51 52 # we need to simulate a real click on the checkbox 53 tfc = client.find_css(TERMS_FAUX_CHECKBOX_CSS) 54 await client.dom_ready() 55 client.execute_script("arguments[0].scrollIntoView(true)", tfc) 56 client.mouse.click(tfc).perform() 57 return tc.selected 58 59 60 @pytest.mark.skip_platforms("android") 61 @pytest.mark.asyncio 62 @pytest.mark.with_interventions 63 async def test_enabled(client, credentials): 64 assert await are_checkboxes_clickable(client, credentials) 65 66 67 @pytest.mark.skip_platforms("android") 68 @pytest.mark.asyncio 69 @pytest.mark.without_interventions 70 async def test_disabled(client, credentials): 71 assert not await are_checkboxes_clickable(client, credentials)