tor-browser

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

test_1949466_lapalabradeldia_com.py (4205B)


      1 import asyncio
      2 from random import randint
      3 
      4 import pytest
      5 
      6 URL = "https://lapalabradeldia.com/"
      7 
      8 JUGAR_BUTTON_TEXT = "¡Jugar!"
      9 CARD1_CSS = "#board .react-card-flip:nth-of-type(1)"
     10 CARD2_CSS = "#board .react-card-flip:nth-of-type(2)"
     11 CARD3_CSS = "#board .react-card-flip:nth-of-type(3)"
     12 CARD4_CSS = "#board .react-card-flip:nth-of-type(4)"
     13 CARD5_CSS = "#board .react-card-flip:nth-of-type(5)"
     14 LETTERS_CSS = "#keyboard button:not(:has(svg))"  # avoid check and delete buttons
     15 
     16 
     17 async def letters_sometimes_vanish(client):
     18    await client.navigate(URL, wait="load")
     19    client.await_text(JUGAR_BUTTON_TEXT, is_displayed=True).click()
     20    letters = client.await_css(LETTERS_CSS, is_displayed=True, all=True)
     21    body = client.find_css("body")
     22 
     23    # This is a very subtle test, because the problem isn't well-understood. I found that I could
     24    # only reproduce the issue if I move the mouse immediately after clicking a letter, while the
     25    # css animation runs. Then the card will sometimes vanish immediately after the animation ends,
     26    # and if I move the mouse again, it seems to reappear. So this test will simulate that kind of
     27    # movement while clicking on 5 random letters, then wait a half-second, see if any of the cards
     28    # are invisible (by taking a "screenshot" of the element, with their CSS borders hidden to make
     29    # is_one_solid_color not have to fuzz), and try another 5 random letters a few times just to make
     30    # sure the cards always appear. The need for delaying the various simulated events during the
     31    # animation makes this test slower than it probably needs to be, but that's fine.
     32    client.add_stylesheet(
     33        "#board .react-card-flip * { border:0 !important; animation-duration:0.5s !important; }"
     34    )
     35 
     36    # click on 5 random letters, check if any are invisible, then delete them and retry
     37    # repeat this 10 times, and presume everything is fine if none disappear.
     38    for attempt in range(10):
     39        for click_five_keys in range(5):
     40            letter = letters[randint(0, len(letters) - 1)]
     41 
     42            coords = client.get_element_screen_position(letter)
     43            coords = [coords[0] + 20, coords[1] + 20]
     44            await client.apz_down(coords=coords)
     45            await asyncio.sleep(0.025)
     46            coords = [coords[0] + 20, coords[1] + 20]
     47            await client.send_apz_mouse_event("move", coords=coords)
     48            await client.apz_up(coords=coords)
     49 
     50            await asyncio.sleep(0.025)
     51            await client.send_apz_mouse_event(
     52                "move", coords=[coords[0] + 50, coords[1] + 50]
     53            )
     54            await asyncio.sleep(0.025)
     55            await client.send_apz_mouse_event(
     56                "move", coords=[coords[0] + 100, coords[1] + 100]
     57            )
     58            await asyncio.sleep(0.025)
     59            await client.send_apz_mouse_event(
     60                "move", coords=[coords[0] + 150, coords[1] + 150]
     61            )
     62            await asyncio.sleep(0.025)
     63            await client.send_apz_mouse_event(
     64                "move", coords=[coords[0] + 200, coords[1] + 200]
     65            )
     66            await asyncio.sleep(0.025)
     67 
     68        # wait a moment to let the animations settle down to increase the
     69        # likelihood that we'll see the problem.
     70        await asyncio.sleep(0.5)
     71 
     72        if (
     73            client.is_one_solid_color(client.find_css(CARD1_CSS))
     74            or client.is_one_solid_color(client.find_css(CARD2_CSS))
     75            or client.is_one_solid_color(client.find_css(CARD3_CSS))
     76            or client.is_one_solid_color(client.find_css(CARD4_CSS))
     77            or client.is_one_solid_color(client.find_css(CARD5_CSS))
     78        ):
     79            return True
     80 
     81        # press backspace key 5 times to clear the inputs so we can try again
     82        for backspace in range(5):
     83            body.send_keys("\ue003")
     84 
     85    return False
     86 
     87 
     88 @pytest.mark.skip_platforms("android")
     89 @pytest.mark.asyncio
     90 @pytest.mark.with_interventions
     91 async def test_enabled(client):
     92    assert not await letters_sometimes_vanish(client)
     93 
     94 
     95 @pytest.mark.skip_platforms("android")
     96 @pytest.mark.asyncio
     97 @pytest.mark.without_interventions
     98 async def test_disabled(client):
     99    assert await letters_sometimes_vanish(client)