@@ -344,26 +344,35 @@ def run_adb_command(command):
344344
345345def capture_ui_dump (device_serial : str | None = None ):
346346 """Capture the current UI hierarchy from the device"""
347+ # Try to get from active Appium driver first (like web does)
348+ try :
349+ from Framework .Built_In_Automation .Mobile .CrossPlatform .Appium .BuiltInFunctions import appium_driver
350+
351+ if appium_driver is not None :
352+ page_src = appium_driver .page_source
353+ with open (UI_XML_PATH , "w" ) as xml_file :
354+ xml_file .write (page_src )
355+ return
356+ except Exception as e :
357+ pass
358+
359+ # Fallback to ADB
347360 device_flag = f"-s { device_serial } " if device_serial else ""
361+
362+ if os .path .exists (UI_XML_PATH ):
363+ os .remove (UI_XML_PATH )
364+
348365 out = run_adb_command (
349366 f"{ ADB_PATH } { device_flag } shell uiautomator dump /sdcard/ui.xml" .strip ()
350367 )
351368 if out .startswith ("Error:" ):
352- from Framework .Built_In_Automation .Mobile .CrossPlatform .Appium .BuiltInFunctions import (
353- appium_driver ,
354- )
355-
356- if appium_driver is None :
357- return
358- page_src = appium_driver .page_source
359- with open (UI_XML_PATH , "w" ) as xml_file :
360- xml_file .write (page_src )
361- else :
362- out = run_adb_command (
363- f"{ ADB_PATH } { device_flag } pull /sdcard/ui.xml { UI_XML_PATH } "
364- )
365- if out .startswith ("Error:" ):
366- return
369+ return
370+
371+ out = run_adb_command (
372+ f"{ ADB_PATH } { device_flag } pull /sdcard/ui.xml { UI_XML_PATH } "
373+ )
374+ if os .path .exists (UI_XML_PATH ):
375+ size = os .path .getsize (UI_XML_PATH )
367376
368377
369378def capture_screenshot (device_serial : str | None = None ):
@@ -456,6 +465,19 @@ def get_real_ios_hierarchy(device_udid: str):
456465
457466
458467def capture_ios_ui_dump (device_udid : str ):
468+ # Try to get from active Appium driver first (like web does)
469+ try :
470+ from Framework .Built_In_Automation .Mobile .CrossPlatform .Appium .BuiltInFunctions import appium_driver
471+
472+ if appium_driver is not None :
473+ page_src = appium_driver .page_source
474+ with open (IOS_XML_PATH , 'w' , encoding = 'utf-8' ) as xml_file :
475+ xml_file .write (page_src )
476+ return
477+ except Exception as e :
478+ pass
479+
480+ # Fallback to WDA
459481 real_hierarchy = get_real_ios_hierarchy (device_udid )
460482 if real_hierarchy :
461483 try :
@@ -468,17 +490,6 @@ def capture_ios_ui_dump(device_udid: str):
468490 with open (IOS_XML_PATH , 'w' , encoding = 'utf-8' ) as xml_file :
469491 xml_file .write (xml_content )
470492 return
471-
472- # Fallback to Appium driver
473- try :
474- from Framework .Built_In_Automation .Mobile .CrossPlatform .Appium .BuiltInFunctions import appium_driver
475- if appium_driver is not None :
476- page_src = appium_driver .page_source
477- with open (IOS_XML_PATH , 'w' , encoding = 'utf-8' ) as xml_file :
478- xml_file .write (page_src )
479- return
480- except :
481- pass
482493
483494
484495async def upload_android_ui_dump ():
0 commit comments