From 7cb750251e67015b6e49a4dbcef73d58737b9228 Mon Sep 17 00:00:00 2001 From: Zdravko Branzov Date: Thu, 20 Jun 2019 12:37:43 +0300 Subject: [PATCH] fix: close cookie window and adjust timing of events --- tests/market/test_market_playgrounds.py | 44 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/tests/market/test_market_playgrounds.py b/tests/market/test_market_playgrounds.py index afcefd2c..f9a5faf0 100644 --- a/tests/market/test_market_playgrounds.py +++ b/tests/market/test_market_playgrounds.py @@ -2,7 +2,7 @@ import time from parameterized import parameterized -from selenium.common.exceptions import NoSuchElementException +from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException from selenium.common.exceptions import ElementClickInterceptedException from core.base_test.tns_run_test import TnsRunTest @@ -76,8 +76,9 @@ def test(self, name, url, text, flavor): Log.info('Testing Android !!!') image_name = '{0}_{1}.png'.format(name.encode("utf8"), str(Platform.ANDROID)) Preview.run_url(url=link, device=self.emu) + Log.info(' Waiting Android app to load...') + time.sleep(10) PlaygroundMarketSamples.verify_device_is_connected(self.chrome, "Android SDK built") - PlaygroundMarketSamples.open_device_logs(self.chrome) emulator_result = PlaygroundMarketSamples.get_error(self.chrome) is_android_fail = emulator_result > 0 android = str(not is_android_fail) @@ -120,7 +121,6 @@ def test(self, name, url, text, flavor): PlaygroundMarketSamples.close_popup(self.sim) PlaygroundMarketSamples.close_permissions_windows_ios(name, self.sim) - PlaygroundMarketSamples.open_device_logs(self.chrome) simulator_result = PlaygroundMarketSamples.get_error(self.chrome) is_app_active = Preview.is_running_on_ios(self.sim, Settings.Packages.PREVIEW_APP_ID) self.is_ios_fail = simulator_result > 0 or not is_app_active @@ -165,8 +165,9 @@ def get_link(chrome, url): @staticmethod def get_error(chrome, previous_errors=0): + PlaygroundMarketSamples.open_device_logs(chrome) exceptions = 0 - timeout = 15 # In seconds + timeout = 10 # In seconds end_time = time.time() + timeout while end_time > time.time(): Log.info(' Searching for exception ...') @@ -213,6 +214,7 @@ def close_permissions_windows_ios(name, sim): @staticmethod def verify_device_is_connected(chrome, device, timeout=15): + PlaygroundMarketSamples.close_cookie_alert(chrome) Log.info("Check device in Playground") t_end = time.time() + timeout while time.time() < t_end: @@ -224,20 +226,38 @@ def verify_device_is_connected(chrome, device, timeout=15): Log.info('Unable to click Devices button!') time.sleep(3) devices = chrome.driver.find_elements_by_class_name('device-name') - if devices: - device_name = devices[0].text - if device not in device_name: - Log.info("Searched device not found !!! Actual: " + str(device_name) + " Expected: " + device) - else: - Log.info("No device has been found to be attached !!!") + try: + if devices: + device_name = devices[0].text + if device not in device_name: + Log.info("Searched device not found !!! Actual: " + str(device_name) + " Expected: " + device) + else: + Log.info("No device has been found to be attached !!!") + except StaleElementReferenceException: + Log.info('Device name element has been removed from the DOM!!!') @staticmethod - def open_device_logs(chrome): + def open_device_logs(chrome, timeout=5): Log.info("Open device Logs") - chrome.driver.find_elements_by_xpath("//span[contains(.,'Device Logs')]")[0].click() + t_end = time.time() + timeout + while time.time() < t_end: + try: + chrome.driver.find_elements_by_xpath("//span[contains(.,'Device Logs')]")[0].click() + Log.info('Device Log opened.') + break + except ElementClickInterceptedException: + Log.info('Unable to click Device Log!') + time.sleep(2) @staticmethod def close_popup(device, timeout=10, button_text="Open"): if PlaygroundMarketSamples.wait_for_text(device, button_text, timeout): device.click(text=button_text) # Preview.dismiss_simulator_alert() + + @staticmethod + def close_cookie_alert(chrome): + Log.info("Close cookie alert.") + accept_cookies = chrome.driver.find_elements_by_xpath("//button[contains(.,'Accept Cookies')]") + if accept_cookies: + accept_cookies[0].click()