66from typing import Literal
77import asyncio
88import socket
9+ import xml .etree .ElementTree as ET
910
1011import requests
1112from fastapi import APIRouter
@@ -39,6 +40,7 @@ class InspectorResponse(BaseModel):
3940 status : Literal ["ok" , "error" ] = "ok"
4041 ui_xml : str | None = None
4142 screenshot : str | None = None # Base64 encoded image
43+ bundle_identifier : str | None = None
4244 error : str | None = None
4345
4446
@@ -178,6 +180,14 @@ def start_ios_services():
178180 return {"status" : "error" , "error" : str (e )}
179181
180182
183+ def extract_bundle_id_from_xml (xml_content : str ) -> str | None :
184+ try :
185+ root = ET .fromstring (xml_content )
186+ return root .get ('bundleId' )
187+ except Exception :
188+ return None
189+
190+
181191@router .get ("/ios/inspect" )
182192def inspect_ios (device_udid : str | None = None ):
183193 """Get iOS simulator screenshot and XML hierarchy."""
@@ -204,6 +214,9 @@ def inspect_ios(device_udid: str | None = None):
204214
205215 with open (IOS_XML_PATH , 'r' , encoding = 'utf-8' ) as xml_file :
206216 xml_content = xml_file .read ()
217+
218+ # Extract bundle identifier from XML content
219+ bundle_id = extract_bundle_id_from_xml (xml_content )
207220
208221 with open (IOS_SCREENSHOT_PATH , 'rb' ) as img_file :
209222 screenshot_bytes = img_file .read ()
@@ -212,7 +225,8 @@ def inspect_ios(device_udid: str | None = None):
212225 return InspectorResponse (
213226 status = "ok" ,
214227 ui_xml = xml_content ,
215- screenshot = screenshot_base64
228+ screenshot = screenshot_base64 ,
229+ bundle_identifier = bundle_id
216230 )
217231 except Exception as e :
218232 return InspectorResponse (
@@ -372,7 +386,7 @@ def capture_ios_ui_dump(device_udid: str):
372386 pass
373387
374388 # No real source available
375- raise Exception ("iOS service error. Please reload the iOS inspector page or run a test case ." )
389+ raise Exception ("iOS service error. Make sure simulator is running ." )
376390
377391
378392async def upload_android_ui_dump ():
0 commit comments