@@ -159,12 +159,32 @@ export class MobilecliDriver implements MobilewrightDriver {
159159 }
160160
161161 async swipe ( direction : SwipeDirection , opts ?: SwipeOptions ) : Promise < void > {
162+ const screen = await this . getScreenSize ( ) ;
163+ const centerX = screen . width / 2 ;
164+ const centerY = screen . height / 2 ;
165+
166+ const startX = opts ?. startX ?? centerX ;
167+ const startY = opts ?. startY ?? centerY ;
168+
169+ const isHorizontal = direction === 'left' || direction === 'right' ;
170+ const defaultDistance = ( isHorizontal ? screen . width : screen . height ) * 0.5 ;
171+ const distance = opts ?. distance ?? defaultDistance ;
172+
173+ let endX = startX ;
174+ let endY = startY ;
175+ switch ( direction ) {
176+ case 'up' : endY = startY - distance ; break ;
177+ case 'down' : endY = startY + distance ; break ;
178+ case 'left' : endX = startX - distance ; break ;
179+ case 'right' : endX = startX + distance ; break ;
180+ }
181+
162182 await this . call ( 'device.io.swipe' , {
163- direction,
164- ...( opts ?. distance !== undefined && { distance : opts . distance } ) ,
183+ x1 : Math . round ( startX ) ,
184+ y1 : Math . round ( startY ) ,
185+ x2 : Math . round ( endX ) ,
186+ y2 : Math . round ( endY ) ,
165187 ...( opts ?. duration !== undefined && { duration : opts . duration } ) ,
166- ...( opts ?. startX !== undefined && { startX : opts . startX } ) ,
167- ...( opts ?. startY !== undefined && { startY : opts . startY } ) ,
168188 } ) ;
169189 }
170190
0 commit comments