test_1918604_g1_globo_com.py (2806B)
1 import asyncio 2 3 import pytest 4 5 URL = "https://g1.globo.com/jogos/caca-palavras/" 6 7 FULLSIZE_BUTTON_CSS = ".full-size-button" 8 INTRO_BUTTON_CSS = "button.intro-button" 9 TUTORIAL_BUTTON_CSS = ".tutorial button" 10 TUTORIAL_OVERLAY_CSS = ".drawer-overlay" 11 CLIPPED_BUTTON_CSS = ".subheader .dropdown button:has(svg)" 12 FIRST_LETTER_CSS = ".letter-box svg g g:first-child" 13 SELECTION_CSS = ".letter-box svg g path" 14 15 16 async def are_buttons_clipped_or_selection_is_misaligned(client): 17 await client.make_preload_script("delete navigator.__proto__.webdriver") 18 client.set_screen_size(300, 500) 19 await client.navigate(URL, wait="none") 20 21 fullsize, intro = client.await_first_element_of( 22 [ 23 client.css(FULLSIZE_BUTTON_CSS), 24 client.css(INTRO_BUTTON_CSS), 25 ], 26 is_displayed=True, 27 timeout=20, 28 ) 29 if fullsize: 30 client.soft_click(fullsize) 31 client.soft_click(client.await_css(INTRO_BUTTON_CSS, is_displayed=True)) 32 else: 33 client.soft_click(intro) 34 35 client.soft_click(client.await_css(TUTORIAL_BUTTON_CSS, is_displayed=True)) 36 client.await_element_hidden(client.css(TUTORIAL_OVERLAY_CSS)) 37 38 # check that the rightmost button isn't clipped away (isn't just the bgcolor) 39 clipped_button = client.await_css(CLIPPED_BUTTON_CSS, is_displayed=True) 40 if client.is_one_solid_color(clipped_button): 41 return True 42 43 letter = client.await_css(FIRST_LETTER_CSS, is_displayed=True) 44 coords = client.get_element_screen_position(letter) 45 coords = [coords[0] + 10, coords[1] + 10] 46 await client.send_apz_mouse_event("down", coords=coords) 47 for i in range(25): 48 await asyncio.sleep(0.01) 49 coords[0] += 5 50 await client.send_apz_mouse_event("move", coords=coords) 51 52 selection = client.await_css(SELECTION_CSS, is_displayed=True) 53 return client.execute_script( 54 """ 55 // The letter's CSS boxes are always bigger than their text, and also the selection. 56 // we check that it's more or less centered (possibly off by a pixel). 57 const letter = arguments[0].getBoundingClientRect(); 58 const selection = arguments[1].getBoundingClientRect(); 59 const halfHeightDiff = ((letter.height - selection.height) / 2) + 1; // can be off by one 60 return Math.abs(selection.bottom - letter.bottom) > halfHeightDiff || 61 Math.abs(selection.top - letter.top) > halfHeightDiff; 62 """, 63 letter, 64 selection, 65 ) 66 67 68 @pytest.mark.asyncio 69 @pytest.mark.with_interventions 70 async def test_enabled(client): 71 assert not await are_buttons_clipped_or_selection_is_misaligned(client) 72 73 74 @pytest.mark.asyncio 75 @pytest.mark.without_interventions 76 async def test_disabled(client): 77 assert await are_buttons_clipped_or_selection_is_misaligned(client)