test_1846742_microsoft_com.py (1752B)
1 from asyncio.exceptions import TimeoutError 2 3 import pytest 4 5 URL = "https://www.microsoft.com/en-us" 6 7 COOKIES_CSS = "#wcpConsentBannerCtrl" 8 SEARCH_CSS = "#search" 9 INPUT_CSS = "#cli_shellHeaderSearchInput" 10 SUGGESTION_CSS = ".m-auto-suggest a.f-product" 11 SELECTED_PRODUCT_LINK_CSS = ".c-menu-item[data-selected=true] a.f-product" 12 13 14 async def does_enter_work(client): 15 await client.navigate(URL) 16 17 # Wait for the cookie banner. By then the page's event listeners are set up. 18 client.await_css(COOKIES_CSS, is_displayed=True) 19 20 client.await_css(SEARCH_CSS, is_displayed=True).click() 21 client.await_css(INPUT_CSS, is_displayed=True).send_keys("surface") 22 23 # We now wait for the search suggestions to appear, press Down twice, 24 # and Enter once. This should begin a navigation if things are working. 25 client.await_css(SUGGESTION_CSS, is_displayed=True) 26 await client.stall(1) 27 client.keyboard.key_down("\ue05b").perform() # Down arrow 28 client.keyboard.key_down("\ue05b").perform() # Down arrow 29 selected_product = client.await_css(SELECTED_PRODUCT_LINK_CSS, is_displayed=True) 30 expected_url = client.get_element_attribute(selected_product, "href") 31 nav = await client.promise_navigation_begins(url=expected_url, timeout=2) 32 client.keyboard.key_down("\ue007").perform() # Enter 33 try: 34 await nav 35 return True 36 except TimeoutError: 37 return False 38 39 40 @pytest.mark.skip_platforms("android") 41 @pytest.mark.asyncio 42 @pytest.mark.with_interventions 43 async def test_enabled(client): 44 assert await does_enter_work(client) 45 46 47 @pytest.mark.skip_platforms("android") 48 @pytest.mark.asyncio 49 @pytest.mark.without_interventions 50 async def test_disabled(client): 51 assert not await does_enter_work(client)