@@ -103,14 +103,25 @@ object XCUITestCommands {
103103 return Triple (" Not Found" , " False" , " False" )
104104 }
105105
106- // Extract JSON from output
107- val jsonText = outputBuffer.toString().substringAfter(" ✅ Result JSON:" , " " ).trim()
108- if (jsonText.isEmpty()) {
106+ val output = outputBuffer.toString()
107+ val jsonSection = output.substringAfter(" ✅ Result JSON:" , " " )
108+ .trim()
109+ if (jsonSection.isEmpty()) {
109110 Logger .error(" ❌ JSON output not found in xcodebuild output" )
110- Logger .error(" Full output:\n $outputBuffer " )
111+ Logger .error(" Full output:\n $output " )
111112 return Triple (" Not Found" , " False" , " False" )
112113 }
113-
114+
115+ // Try to extract the JSON array (up to the next closing bracket)
116+ val jsonStart = jsonSection.indexOf(" [" )
117+ val jsonEnd = jsonSection.indexOf(" ]" ) + 1
118+ if (jsonStart == - 1 || jsonEnd == - 1 ) {
119+ Logger .error(" ❌ JSON array not found in output" )
120+ Logger .error(" JSON section was: $jsonSection " )
121+ return Triple (" Not Found" , " False" , " False" )
122+ }
123+ val jsonText = jsonSection.substring(jsonStart, jsonEnd)
124+
114125 return try {
115126 val jsonArray = JSONArray (jsonText)
116127 val result = jsonArray.getJSONObject(0 )
0 commit comments