test_1962654_idnow_de.py (3229B)
1 import asyncio 2 3 import pytest 4 from webdriver.error import WebDriverException 5 6 URL = "https://kyc.bonify.de/choose" 7 SHADOWROOT_CSS = "#usercentrics-root" 8 VPN_TEXT = "Access Denied" 9 COOKIES_CSS = "[data-testid=uc-accept-all-button]" 10 USERNAME_CSS = "#loginId" 11 PASSWORD_CSS = "#password" 12 LOGIN_CSS = "#login-button" 13 DETECT_CSS = "[data-testid=TestID_autoIdentStartCTA]" 14 CB_WEBCAM_CSS = "label[for=start-has-webcam]" 15 CB_DOCUMENTS_CSS = "label[for=start-has-documents]" 16 CB_AGREE_CSS = "label[for=start-has-agreed]" 17 PROCEED_CSS = ".btn-proceed" 18 TRY_DESKTOP_CSS = ".user-transfer-continue-web-desktop-experience" 19 SUCCESS_CSS = "#readyButton" 20 FAILURE_CSS = "img[src*=chrome]" 21 22 23 async def start_process(client, credentials): 24 await client.make_preload_script("delete navigator.__proto__.webdriver") 25 await client.navigate(URL, wait="none") 26 shadowRoot, vpn = client.await_first_element_of( 27 [ 28 client.css(SHADOWROOT_CSS), 29 client.text(VPN_TEXT), 30 ], 31 is_displayed=True, 32 ) 33 if vpn: 34 pytest.skip("Region-locked, cannot test. Try using a VPN set to Germany.") 35 return False 36 37 def await_css(selector): 38 return client.execute_async_script( 39 """ 40 const [root, selector, done] = arguments; 41 const i = setInterval(() => { 42 const v = root.shadowRoot.querySelector(selector); 43 if (v) { 44 clearInterval(i); 45 done(v); 46 } 47 }, 100); 48 """, 49 shadowRoot, 50 selector, 51 ) 52 53 await_css(COOKIES_CSS).click() 54 55 async def click_when_ready(selector): 56 for _ in range(5): 57 elem = client.await_css(selector, is_displayed=True) 58 try: 59 elem.click() 60 return elem 61 except WebDriverException: # element not interactable 62 await asyncio.sleep(0.5) 63 64 (await click_when_ready(USERNAME_CSS)).send_keys(credentials["username"]) 65 (await click_when_ready(PASSWORD_CSS)).send_keys(credentials["password"]) 66 await click_when_ready(LOGIN_CSS) 67 await click_when_ready(DETECT_CSS) 68 await click_when_ready(CB_WEBCAM_CSS) 69 await click_when_ready(CB_DOCUMENTS_CSS) 70 await click_when_ready(CB_AGREE_CSS) 71 72 proceed = client.await_css(PROCEED_CSS, is_displayed=True) 73 for _ in range(5): 74 try: 75 client.soft_click(proceed) 76 await asyncio.sleep(0.5) 77 except Exception as e: 78 print(e) 79 pass 80 81 client.await_css(TRY_DESKTOP_CSS, is_displayed=True).click() 82 83 84 @pytest.mark.only_platforms("linux") 85 @pytest.mark.asyncio 86 @pytest.mark.with_interventions 87 async def test_enabled(client, credentials): 88 await start_process(client, credentials) 89 assert client.await_css(SUCCESS_CSS, is_displayed=True) 90 assert not client.find_css(FAILURE_CSS, is_displayed=True) 91 92 93 @pytest.mark.only_platforms("linux") 94 @pytest.mark.asyncio 95 @pytest.mark.without_interventions 96 async def test_disabled(client, credentials): 97 await start_process(client, credentials) 98 assert client.await_css(FAILURE_CSS, is_displayed=True) 99 assert not client.find_css(SUCCESS_CSS, is_displayed=True)