99
1010const childProcess = require ( 'child_process' ) ;
1111const fs = require ( 'fs' ) ;
12- const { filterFlowsByTags } = require ( './maestro-android ' ) ;
12+ const path = require ( 'path ' ) ;
1313
1414const usage = `
1515=== Usage ===
16- node maestro-ios.js <path to app> <app_id> <maestro_flow> <jsengine> <flavor> <working_directory> [device_model] [device_os] [exclude_tags]
16+ node maestro-ios.js <path to app> <app_id> <maestro_flow> <jsengine> <flavor> <working_directory> [device_model] [device_os]
1717
1818@param {string} appPath - Path to the app APK
1919@param {string} appId - App ID that needs to be launched
@@ -23,11 +23,11 @@ node maestro-ios.js <path to app> <app_id> <maestro_flow> <jsengine> <flavor> <w
2323@param {string} workingDirectory - Working directory from where to run Metro
2424@param {string} deviceModel - Optional Maestro device model, such as iPhone-17-Pro
2525@param {string} deviceOS - Optional Maestro device OS, such as iOS-26-2
26- @param {string} excludeTags - Optional comma-separated flow tags to exclude
2726==============
2827` ;
2928
3029const MAX_ATTEMPTS = 5 ;
30+ const MAESTRO_LOG_DIRECTORY = '/tmp/MaestroLogs' ;
3131
3232function findAvailableSimulator ( deviceModel , deviceOS ) {
3333 const output = childProcess . execSync (
@@ -187,7 +187,14 @@ async function executeFlowWithRetries(
187187 const recProcess = startVideoRecording ( udid , currentAttempt ) ;
188188 try {
189189 const timeout = 1000 * 60 * 10 ; // 10 minutes
190- const command = `$HOME/.maestro/bin/maestro --udid="${ udid } " test "${ flow } " --format junit -e APP_ID="${ appId } "` ;
190+ // Keep each attempt's commands, screenshots, and logs; retries would
191+ // otherwise overwrite them.
192+ const debugOutput = path . join (
193+ MAESTRO_LOG_DIRECTORY ,
194+ path . basename ( flow , path . extname ( flow ) ) ,
195+ `attempt-${ currentAttempt } ` ,
196+ ) ;
197+ const command = `$HOME/.maestro/bin/maestro --udid="${ udid } " test "${ flow } " --format junit -e APP_ID="${ appId } " --debug-output "${ debugOutput } "` ;
191198 console . info ( `Executing flow: ${ flow } (attempt ${ currentAttempt } )` ) ;
192199 console . log ( command ) ;
193200 childProcess . execSync ( `MAESTRO_DRIVER_STARTUP_TIMEOUT=1500000 ${ command } ` , {
@@ -217,13 +224,7 @@ async function executeFlowWithRetries(
217224 }
218225}
219226
220- async function executeFlows (
221- appId ,
222- udid ,
223- maestroFlow ,
224- jsengine ,
225- excludeTags = [ ] ,
226- ) {
227+ async function executeFlows ( appId , udid , maestroFlow , jsengine ) {
227228 if ( ! fs . existsSync ( maestroFlow ) || ! fs . lstatSync ( maestroFlow ) . isDirectory ( ) ) {
228229 await executeFlowWithRetries ( appId , udid , maestroFlow , jsengine , 1 ) ;
229230 return ;
@@ -237,18 +238,15 @@ async function executeFlows(
237238 if ( file === 'helpers' ) {
238239 continue ;
239240 }
240- await executeFlows ( appId , udid , filePath , jsengine , excludeTags ) ;
241+ await executeFlows ( appId , udid , filePath , jsengine ) ;
241242 } else if ( file . endsWith ( '.yml' ) || file . endsWith ( '.yaml' ) ) {
242- if ( filterFlowsByTags ( [ filePath ] , excludeTags ) . length === 0 ) {
243- continue ;
244- }
245243 await executeFlowWithRetries ( appId , udid , filePath , jsengine , 1 ) ;
246244 }
247245 }
248246}
249247
250248async function main ( args = process . argv . slice ( 2 ) ) {
251- if ( args . length < 6 || args . length > 9 ) {
249+ if ( args . length < 6 || args . length > 8 ) {
252250 throw new Error ( `Invalid number of arguments.\n${ usage } ` ) ;
253251 }
254252
@@ -260,10 +258,6 @@ async function main(args = process.argv.slice(2)) {
260258 const workingDirectory = args [ 5 ] ;
261259 const deviceModel = args [ 6 ] || null ;
262260 const deviceOS = args [ 7 ] || null ;
263- const excludeTags = ( args [ 8 ] ?? '' )
264- . split ( ',' )
265- . map ( tag => tag . trim ( ) )
266- . filter ( Boolean ) ;
267261
268262 console . info ( '\n==============================' ) ;
269263 console . info ( 'Running tests for iOS with the following parameters:' ) ;
@@ -275,15 +269,14 @@ async function main(args = process.argv.slice(2)) {
275269 console . info ( `WORKING_DIRECTORY: ${ workingDirectory } ` ) ;
276270 console . info ( `DEVICE_MODEL: ${ deviceModel ?? '<automatic>' } ` ) ;
277271 console . info ( `DEVICE_OS: ${ deviceOS ?? '<automatic>' } ` ) ;
278- console . info ( `EXCLUDE_TAGS: ${ excludeTags . join ( ',' ) || '<none>' } ` ) ;
279272 console . info ( '==============================\n' ) ;
280273
281274 const simulator = findAvailableSimulator ( deviceModel , deviceOS ) ;
282275 launchSimulator ( simulator ) ;
283276 installAppOnSimulator ( appPath , simulator . udid ) ;
284277 bringSimulatorInForeground ( ) ;
285278 await launchAppOnSimulator ( appId , simulator . udid , isDebug ) ;
286- await executeFlows ( appId , simulator . udid , maestroFlow , jsengine , excludeTags ) ;
279+ await executeFlows ( appId , simulator . udid , maestroFlow , jsengine ) ;
287280 console . log ( 'Test finished' ) ;
288281}
289282
0 commit comments