@@ -6,20 +6,17 @@ import {
66 dismissAndroidKeyboard ,
77 getAndroidKeyboardState ,
88 pushAndroidNotification ,
9- snapshotAndroid ,
109} from '../platforms/android/index.ts' ;
11- import { getInteractor , type Interactor , type RunnerContext } from './interactors.ts' ;
10+ import { getInteractor } from './interactors.ts' ;
11+ import type { Interactor , RunnerContext } from './interactor-types.ts' ;
1212import { runIosRunnerCommand } from '../platforms/ios/runner-client.ts' ;
1313import { pushIosNotification } from '../platforms/ios/index.ts' ;
14- import { snapshotLinux } from '../platforms/linux/snapshot.ts' ;
1514import { isDeepLinkTarget } from './open-target.ts' ;
1615import { parseTriggerAppEventArgs , resolveAppEventUrl } from './app-events.ts' ;
17- import type { RawSnapshotNode } from '../utils/snapshot.ts' ;
1816import { emitDiagnostic , withDiagnosticTimer } from '../utils/diagnostics.ts' ;
1917import { readLocationCoordinate } from '../utils/location-coordinates.ts' ;
2018import { successText , withSuccessText } from '../utils/success-text.ts' ;
2119import type { DispatchContext } from './dispatch-context.ts' ;
22- import { shouldUseIosTapSeries , shouldUseIosDragSeries } from './dispatch-series.ts' ;
2320import {
2421 handleFillCommand ,
2522 handleFocusCommand ,
@@ -35,7 +32,6 @@ import { readNotificationPayload } from './dispatch-payload.ts';
3532import { parseDeviceRotation } from './device-rotation.ts' ;
3633
3734export { resolveTargetDevice } from './dispatch-resolve.ts' ;
38- export { shouldUseIosTapSeries , shouldUseIosDragSeries } ;
3935export type { BatchStep , CommandFlags , DispatchContext } from './dispatch-context.ts' ;
4036
4137export async function dispatchCommand (
@@ -77,9 +73,9 @@ export async function dispatchCommand(
7773 return { app, ...successText ( `Closed: ${ app } ` ) } ;
7874 }
7975 case 'press' :
80- return handlePressCommand ( device , interactor , positionals , context , runnerCtx ) ;
76+ return handlePressCommand ( device , interactor , positionals , context ) ;
8177 case 'swipe' :
82- return handleSwipeCommand ( device , interactor , positionals , context , runnerCtx ) ;
78+ return handleSwipeCommand ( device , interactor , positionals , context ) ;
8379 case 'longpress' :
8480 return handleLongPressCommand ( interactor , positionals ) ;
8581 case 'focus' :
@@ -91,7 +87,7 @@ export async function dispatchCommand(
9187 case 'scroll' :
9288 return handleScrollCommand ( interactor , positionals , context ) ;
9389 case 'pinch' :
94- return handlePinchCommand ( device , positionals , context , runnerCtx ) ;
90+ return handlePinchCommand ( device , positionals , context ) ;
9591 case 'trigger-app-event' : {
9692 const { eventName, payload } = parseTriggerAppEventArgs ( positionals ) ;
9793 const eventUrl = resolveAppEventUrl ( device . platform , eventName , payload ) ;
@@ -135,15 +131,15 @@ export async function dispatchCommand(
135131 case 'clipboard' :
136132 return handleClipboardCommand ( interactor , positionals ) ;
137133 case 'keyboard' :
138- return handleKeyboardCommand ( device , interactor , positionals , context , runnerCtx ) ;
134+ return handleKeyboardCommand ( device , positionals , context , runnerCtx ) ;
139135 case 'settings' :
140136 return handleSettingsCommand ( device , interactor , positionals , context ) ;
141137 case 'push' :
142138 return handlePushCommand ( device , positionals , context ) ;
143139 case 'snapshot' :
144- return handleSnapshotCommand ( device , positionals , context , runnerCtx ) ;
140+ return await handleSnapshotCommand ( interactor , context ) ;
145141 case 'read' :
146- return handleReadCommand ( device , positionals , context , runnerCtx ) ;
142+ return handleReadCommand ( device , positionals , context ) ;
147143 default :
148144 throw new AppError ( 'INVALID_ARGS' , `Unknown command: ${ command } ` ) ;
149145 }
@@ -230,7 +226,6 @@ async function handleClipboardCommand(
230226
231227async function handleKeyboardCommand (
232228 device : DeviceInfo ,
233- _interactor : Interactor ,
234229 positionals : string [ ] ,
235230 context : DispatchContext | undefined ,
236231 runnerCtx : RunnerContext ,
@@ -367,76 +362,18 @@ async function handlePushCommand(
367362}
368363
369364async function handleSnapshotCommand (
370- device : DeviceInfo ,
371- _positionals : string [ ] ,
365+ interactor : Interactor ,
372366 context : DispatchContext | undefined ,
373- _runnerCtx : RunnerContext ,
374367) : Promise < Record < string , unknown > > {
375- if ( device . platform === 'linux' ) {
376- const linuxResult = await withDiagnosticTimer (
377- 'snapshot_capture' ,
378- async ( ) => await snapshotLinux ( context ?. surface ) ,
379- { backend : 'linux-atspi' } ,
380- ) ;
381- return {
382- nodes : linuxResult . nodes ?? [ ] ,
383- truncated : linuxResult . truncated ?? false ,
384- backend : 'linux-atspi' ,
385- } ;
386- }
387- if ( device . platform !== 'android' ) {
388- const result = ( await withDiagnosticTimer (
389- 'snapshot_capture' ,
390- async ( ) =>
391- await runIosRunnerCommand (
392- device ,
393- {
394- command : 'snapshot' ,
395- appBundleId : context ?. appBundleId ,
396- interactiveOnly : context ?. snapshotInteractiveOnly ,
397- compact : context ?. snapshotCompact ,
398- depth : context ?. snapshotDepth ,
399- scope : context ?. snapshotScope ,
400- raw : context ?. snapshotRaw ,
401- } ,
402- {
403- verbose : context ?. verbose ,
404- logPath : context ?. logPath ,
405- traceLogPath : context ?. traceLogPath ,
406- requestId : context ?. requestId ,
407- } ,
408- ) ,
409- {
410- backend : 'xctest' ,
411- } ,
412- ) ) as { nodes ?: RawSnapshotNode [ ] ; truncated ?: boolean } ;
413- const nodes = result . nodes ?? [ ] ;
414- if ( nodes . length === 0 && device . kind === 'simulator' ) {
415- throw new AppError ( 'COMMAND_FAILED' , 'XCTest snapshot returned 0 nodes on iOS simulator.' ) ;
416- }
417- return { nodes, truncated : result . truncated ?? false , backend : 'xctest' } ;
418- }
419- const androidResult = await withDiagnosticTimer (
420- 'snapshot_capture' ,
421- async ( ) =>
422- await snapshotAndroid ( device , {
423- interactiveOnly : context ?. snapshotInteractiveOnly ,
424- compact : context ?. snapshotCompact ,
425- depth : context ?. snapshotDepth ,
426- scope : context ?. snapshotScope ,
427- raw : context ?. snapshotRaw ,
428- } ) ,
429- {
430- backend : 'android' ,
431- } ,
432- ) ;
433- return {
434- nodes : androidResult . nodes ?? [ ] ,
435- truncated : androidResult . truncated ?? false ,
436- backend : 'android' ,
437- analysis : androidResult . analysis ,
438- androidSnapshot : androidResult . androidSnapshot ,
439- } ;
368+ return await interactor . snapshot ( {
369+ appBundleId : context ?. appBundleId ,
370+ interactiveOnly : context ?. snapshotInteractiveOnly ,
371+ compact : context ?. snapshotCompact ,
372+ depth : context ?. snapshotDepth ,
373+ scope : context ?. snapshotScope ,
374+ raw : context ?. snapshotRaw ,
375+ surface : context ?. surface ,
376+ } ) ;
440377}
441378
442379function readResultMessage ( result : Record < string , unknown > ) : string | undefined {
0 commit comments