test_1966330_salling_dk.py (1705B)
1 import asyncio 2 3 import pytest 4 from webdriver.error import ( 5 ElementClickInterceptedException, 6 NoSuchElementException, 7 WebDriverException, 8 ) 9 10 URL = "https://salling.dk/herre/toej/c-11905/" 11 COOKIES_CSS = "button[class*=accept]" 12 COOKIES_OVERLAY_CSS = "#coiOverlay" 13 FILTERS_CSS = "button:has(svg.icon--filter)" 14 BRANDS_CSS = ".filter:nth-of-type(3):has(.accordion)" 15 16 17 async def are_filters_onscreen(client): 18 client.set_screen_size(767, 500) 19 await client.navigate(URL, wait="none") 20 try: 21 client.await_css(COOKIES_CSS, is_displayed=True, timeout=5).click() 22 client.await_element_hidden(client.css(COOKIES_OVERLAY_CSS)) 23 except NoSuchElementException: 24 pass 25 for _ in range(20): 26 try: 27 await asyncio.sleep(0.1) 28 client.await_css(FILTERS_CSS, is_displayed=True).click() 29 except (WebDriverException, ElementClickInterceptedException): 30 continue 31 if client.find_css(BRANDS_CSS, is_displayed=True): 32 break 33 for _ in range(20): 34 try: 35 client.await_css(BRANDS_CSS, is_displayed=True).click() 36 break 37 except (WebDriverException, ElementClickInterceptedException): 38 await asyncio.sleep(0.1) 39 await asyncio.sleep(0.5) 40 return client.execute_script( 41 "return arguments[0].getBoundingClientRect().top >= 0", 42 client.await_css(BRANDS_CSS, is_displayed=True), 43 ) 44 45 46 @pytest.mark.asyncio 47 @pytest.mark.with_interventions 48 async def test_enabled(client): 49 assert await are_filters_onscreen(client) 50 51 52 @pytest.mark.asyncio 53 @pytest.mark.without_interventions 54 async def test_disabled(client): 55 assert not await are_filters_onscreen(client)