tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_1848713_cleanrider_com.py (2927B)


      1 import pytest
      2 from webdriver import NoSuchElementException
      3 from webdriver.error import ElementClickInterceptedException, WebDriverException
      4 
      5 URL = "https://www.cleanrider.com/catalogue/velo-electrique/velos-pliants-electriques/"
      6 
      7 COOKIES_CSS = "#didomi-notice-agree-button"
      8 PRICE_SECTION_CSS = "#block-prix"
      9 MIN_THUMB_CSS = "#block-prix .range-min-bullet"
     10 
     11 
     12 async def can_interact_with_slider(client, platform):
     13    await client.navigate(URL, wait="none")
     14 
     15    client.hide_elements("#opd_bottomstickyad")
     16 
     17    try:
     18        client.await_css(COOKIES_CSS, is_displayed=True, timeout=5).click()
     19    except NoSuchElementException:
     20        pass
     21 
     22    # there are two copies of the site's markup, one for mobile and one for
     23    # desktop, with one of them hidden. we have to get the visible one.
     24    price = client.await_css(PRICE_SECTION_CSS)
     25    if not client.is_displayed(price):
     26        client.execute_script("arguments[0].remove()", price)
     27 
     28    min_thumb = client.await_css(MIN_THUMB_CSS, is_displayed=True)
     29    if platform == "android":
     30        for x in range(5):
     31            client.await_css(
     32                '[\\@click="openMobile = true"]', is_displayed=True
     33            ).click()
     34            await client.stall(0.5)
     35            if client.await_css('[\\@click="openMobile = false"]', is_displayed=True):
     36                break
     37 
     38        # wait for the button to slide onscreen
     39        client.execute_async_script(
     40            """
     41            var [minThumb, done] = arguments;
     42            const i = window.setInterval(() => {
     43                if (minThumb.getBoundingClientRect().x >= 0) {
     44                    clearInterval(i);
     45                    done();
     46                }
     47            }, 100);
     48        """,
     49            min_thumb,
     50        )
     51 
     52    coords = client.get_element_screen_position(min_thumb)
     53    coords = [coords[0] + 4, coords[1] + 4]
     54    await client.apz_down(coords=coords)
     55    for i in range(25):
     56        await client.stall(0.01)
     57        coords[0] += 5
     58        await client.apz_move(coords=coords)
     59 
     60    # we can detect the broken case as the element will not receive mouse events.
     61    client.execute_script(
     62        """
     63        document.documentElement.addEventListener(
     64          "mousedown",
     65          () => { alert("bad") },
     66          true
     67        );
     68    """
     69    )
     70 
     71    client.scroll_into_view(min_thumb)
     72    try:
     73        for _ in range(5):
     74            min_thumb.click()
     75            await client.stall(0.5)
     76    except (
     77        ElementClickInterceptedException,
     78        WebDriverException,
     79    ) as _:  # element not interactable
     80        return True
     81    assert await client.find_alert("bad")
     82 
     83 
     84 @pytest.mark.asyncio
     85 @pytest.mark.with_interventions
     86 async def test_enabled(client, platform):
     87    assert await can_interact_with_slider(client, platform)
     88 
     89 
     90 @pytest.mark.asyncio
     91 @pytest.mark.without_interventions
     92 async def test_disabled(client, platform):
     93    assert not await can_interact_with_slider(client, platform)