summaryrefslogtreecommitdiffstats
path: root/testing/webcompat/interventions/tests/test_1644830_missingmail_usps.py
blob: 39a2db683a0f850af0f22df0cedccd3f38233d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pytest

URL = (
    "https://missingmail.usps.com/?_gl=1*veidlp*_gcl_aw*R0NMLjE1OTE3MjUyNTkuRUF"
    "JYUlRb2JDaE1Jd3AzaTBhYjE2UUlWa01EQUNoMlBBUVlrRUFBWUFTQUFFZ0lMeFBEX0J3RQ..*"
    "_gcl_dc*R0NMLjE1OTE3MjUyNTkuRUFJYUlRb2JDaE1Jd3AzaTBhYjE2UUlWa01EQUNoMlBBUV"
    "lrRUFBWUFTQUFFZ0lMeFBEX0J3RQ..#/"
)

USERNAME_CSS = "#username"
PASSWORD_CSS = "#password"
SIGN_IN_CSS = "#btn-submit"
TERMS_CHECKBOX_CSS = "#tc-checkbox"
TERMS_FAUX_CHECKBOX_CSS = "#tc-checkbox + .mrc-custom-checkbox"

# The USPS missing mail website takes a very long time to load (multiple
# minutes). We give them a very generous amount of time here, but will
# give up after that and just skip the rest of the test.
TIMEOUT = 900
TIMEOUT_MESSAGE = "USPS website is too slow, skipping test"


async def are_checkboxes_clickable(client, credentials):
    await client.navigate(URL)

    username = client.await_css(USERNAME_CSS)
    password = client.find_css(PASSWORD_CSS)
    sign_in = client.find_css(SIGN_IN_CSS)
    assert client.is_displayed(username)
    assert client.is_displayed(password)
    assert client.is_displayed(sign_in)

    username.send_keys(credentials["username"])
    password.send_keys(credentials["password"])
    sign_in.click()

    tc = client.await_css(TERMS_CHECKBOX_CSS, timeout=TIMEOUT)
    if tc is None:
        pytest.skip(TIMEOUT_MESSAGE)
        return

    assert not tc.selected

    # we need to simulate a real click on the checkbox
    tfc = client.find_css(TERMS_FAUX_CHECKBOX_CSS)
    await client.dom_ready()
    client.execute_script("arguments[0].scrollIntoView(true)", tfc)
    client.mouse.click(tfc).perform()
    return tc.selected


@pytest.mark.skip_platforms("android")
@pytest.mark.asyncio
@pytest.mark.with_interventions
async def test_enabled(client, credentials):
    assert await are_checkboxes_clickable(client, credentials)


@pytest.mark.skip_platforms("android")
@pytest.mark.asyncio
@pytest.mark.without_interventions
async def test_disabled(client, credentials):
    assert not await are_checkboxes_clickable(client, credentials)