22import time
33
44from parameterized import parameterized
5- from selenium .common .exceptions import NoSuchElementException
5+ from selenium .common .exceptions import NoSuchElementException , StaleElementReferenceException
66from selenium .common .exceptions import ElementClickInterceptedException
77
88from core .base_test .tns_run_test import TnsRunTest
@@ -76,8 +76,9 @@ def test(self, name, url, text, flavor):
7676 Log .info ('Testing Android !!!' )
7777 image_name = '{0}_{1}.png' .format (name .encode ("utf8" ), str (Platform .ANDROID ))
7878 Preview .run_url (url = link , device = self .emu )
79+ Log .info (' Waiting Android app to load...' )
80+ time .sleep (10 )
7981 PlaygroundMarketSamples .verify_device_is_connected (self .chrome , "Android SDK built" )
80- PlaygroundMarketSamples .open_device_logs (self .chrome )
8182 emulator_result = PlaygroundMarketSamples .get_error (self .chrome )
8283 is_android_fail = emulator_result > 0
8384 android = str (not is_android_fail )
@@ -120,7 +121,6 @@ def test(self, name, url, text, flavor):
120121 PlaygroundMarketSamples .close_popup (self .sim )
121122
122123 PlaygroundMarketSamples .close_permissions_windows_ios (name , self .sim )
123- PlaygroundMarketSamples .open_device_logs (self .chrome )
124124 simulator_result = PlaygroundMarketSamples .get_error (self .chrome )
125125 is_app_active = Preview .is_running_on_ios (self .sim , Settings .Packages .PREVIEW_APP_ID )
126126 self .is_ios_fail = simulator_result > 0 or not is_app_active
@@ -165,8 +165,9 @@ def get_link(chrome, url):
165165
166166 @staticmethod
167167 def get_error (chrome , previous_errors = 0 ):
168+ PlaygroundMarketSamples .open_device_logs (chrome )
168169 exceptions = 0
169- timeout = 15 # In seconds
170+ timeout = 10 # In seconds
170171 end_time = time .time () + timeout
171172 while end_time > time .time ():
172173 Log .info (' Searching for exception ...' )
@@ -213,6 +214,7 @@ def close_permissions_windows_ios(name, sim):
213214
214215 @staticmethod
215216 def verify_device_is_connected (chrome , device , timeout = 15 ):
217+ PlaygroundMarketSamples .close_cookie_alert (chrome )
216218 Log .info ("Check device in Playground" )
217219 t_end = time .time () + timeout
218220 while time .time () < t_end :
@@ -224,20 +226,38 @@ def verify_device_is_connected(chrome, device, timeout=15):
224226 Log .info ('Unable to click Devices button!' )
225227 time .sleep (3 )
226228 devices = chrome .driver .find_elements_by_class_name ('device-name' )
227- if devices :
228- device_name = devices [0 ].text
229- if device not in device_name :
230- Log .info ("Searched device not found !!! Actual: " + str (device_name ) + " Expected: " + device )
231- else :
232- Log .info ("No device has been found to be attached !!!" )
229+ try :
230+ if devices :
231+ device_name = devices [0 ].text
232+ if device not in device_name :
233+ Log .info ("Searched device not found !!! Actual: " + str (device_name ) + " Expected: " + device )
234+ else :
235+ Log .info ("No device has been found to be attached !!!" )
236+ except StaleElementReferenceException :
237+ Log .info ('Device name element has been removed from the DOM!!!' )
233238
234239 @staticmethod
235- def open_device_logs (chrome ):
240+ def open_device_logs (chrome , timeout = 5 ):
236241 Log .info ("Open device Logs" )
237- chrome .driver .find_elements_by_xpath ("//span[contains(.,'Device Logs')]" )[0 ].click ()
242+ t_end = time .time () + timeout
243+ while time .time () < t_end :
244+ try :
245+ chrome .driver .find_elements_by_xpath ("//span[contains(.,'Device Logs')]" )[0 ].click ()
246+ Log .info ('Device Log opened.' )
247+ break
248+ except ElementClickInterceptedException :
249+ Log .info ('Unable to click Device Log!' )
250+ time .sleep (2 )
238251
239252 @staticmethod
240253 def close_popup (device , timeout = 10 , button_text = "Open" ):
241254 if PlaygroundMarketSamples .wait_for_text (device , button_text , timeout ):
242255 device .click (text = button_text )
243256 # Preview.dismiss_simulator_alert()
257+
258+ @staticmethod
259+ def close_cookie_alert (chrome ):
260+ Log .info ("Close cookie alert." )
261+ accept_cookies = chrome .driver .find_elements_by_xpath ("//button[contains(.,'Accept Cookies')]" )
262+ if accept_cookies :
263+ accept_cookies [0 ].click ()
0 commit comments