test_1724868_news_yahoo_co_jp.py (1874B)
1 import pytest 2 3 URL = "https://news.yahoo.co.jp/live" 4 5 ARTICLE_LINK_CSS = "a[href*='news.yahoo.co.jp/articles']:has(svg)" 6 IFRAME_CSS = "iframe[src*=player]" 7 SUPPORTED_CSS = "video[playsinline]" 8 UNSUPPORTED_TEXT = "ご利用の環境では映像を視聴できません" 9 NEED_VPN_TEXT1 = "PLAYER_ERR_GEO_RESTRICTED" 10 NEED_VPN_TEXT2 = "この映像は日本国外からはご視聴いただけません" 11 12 13 async def go(client, should_work): 14 await client.navigate(URL, wait="none") 15 client.await_css(ARTICLE_LINK_CSS, is_displayed=True).click() 16 # when unsupported, the site only shows an "unsupported" banner, but 17 # when supported, it may show the player or vpn messages. 18 # it may also nest the player in an iframe. 19 iframe = client.css(IFRAME_CSS) 20 unsupported = client.text(UNSUPPORTED_TEXT) 21 supported = client.css(SUPPORTED_CSS) 22 vpn1 = client.text(NEED_VPN_TEXT1) 23 vpn2 = client.text(NEED_VPN_TEXT2) 24 for i in range(2): 25 _iframe, _unsupported, _supported, _vpn1, _vpn2 = client.await_first_element_of( 26 [iframe, unsupported, supported, vpn1, vpn2], 27 is_displayed=True, 28 ) 29 if _iframe: 30 client.switch_to_frame(_iframe) 31 continue 32 if should_work: 33 assert _supported or _vpn1 or _vpn2 34 assert not client.find_element(unsupported) 35 return 36 assert _unsupported 37 assert not client.find_element(supported) 38 assert not client.find_element(vpn1) 39 assert not client.find_element(vpn2) 40 41 42 @pytest.mark.only_platforms("android", "linux") 43 @pytest.mark.asyncio 44 @pytest.mark.with_interventions 45 async def test_enabled(client): 46 await go(client, True) 47 48 49 @pytest.mark.only_platforms("android", "linux") 50 @pytest.mark.asyncio 51 @pytest.mark.without_interventions 52 async def test_disabled(client): 53 await go(client, False)