summaryrefslogtreecommitdiffstats
path: root/testing/webcompat/interventions/tests/test_1786404_business_help_royalmail_com.py
blob: 59a95ff8d9820d6ca9795208c45b0668f0c63797 (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
64
65
66
67
68
69
70
import time

import pytest
from webdriver.error import StaleElementReferenceException

URL = "https://business.help.royalmail.com/app/webforms/stampsenquiries"

COOKIES_ACCEPT_CSS = "#consent_prompt_submit"
POSTCODE_CSS = "input[name='rn_AddressControl_16textbox']"
OPTION_CSS = "option.addr_pick_line:not(:disabled)"
ADDY1_CSS = "[name='Incident.CustomFields.c.address1_1']"


async def getResult(client):
    await client.navigate(URL)

    client.await_css(COOKIES_ACCEPT_CSS).click()

    # the viewport scrolls around while we try to interact
    # with the postcode in webdriver, so we take care here
    code = client.await_css(POSTCODE_CSS)
    client.scroll_into_view(code)
    time.sleep(1)
    client.mouse.click(element=code).perform()
    code.send_keys("W1A 1AV")

    # now wait for the options to open, scroll them back
    # into view, and carefully click on the first one.
    time.sleep(1)
    client.scroll_into_view(code)
    opt = client.await_css(OPTION_CSS)
    client.mouse.click(element=opt).perform()

    # the options should hide on click
    time.sleep(2)
    try:
        if client.is_displayed(opt):
            return False
    except StaleElementReferenceException:
        return False

    # a address line should end up being prefilled
    addy = client.await_css(ADDY1_CSS)
    return client.execute_async_script(
        """
        var addy = arguments[0];
        var done = arguments[1];
        var to = setTimeout(() => {
          if (addy.value) {
            clearTimeout(to);
            done(true);
          }
        }, 200);
      """,
        addy,
    )


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


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