File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -122,4 +122,9 @@ export declare class UIElement {
122122 * Easy to use in order to chain and search for nested elemetns
123123 */
124124 driver ( ) : any ;
125+ /**
126+ * Swipe element left/right
127+ * @param direction
128+ */
129+ swipe ( direction : Direction ) : Promise < void > ;
125130}
Original file line number Diff line number Diff line change @@ -317,4 +317,41 @@ export class UIElement {
317317 public driver ( ) {
318318 return this . _element . browser ;
319319 }
320+
321+ /**
322+ * Swipe element left/right
323+ * @param direction
324+ */
325+ public async swipe ( direction : Direction ) {
326+ const rectangle = await this . getRectangle ( ) ;
327+ const centerX = rectangle . x + rectangle . width / 2 ;
328+ const centerY = rectangle . y + rectangle . height / 2 ;
329+ let swipeX ;
330+ if ( direction == Direction . right ) {
331+ const windowSize = await this . _driver . getWindowSize ( ) ;
332+ swipeX = windowSize . width - 10 ;
333+ } else if ( direction == Direction . left ) {
334+ swipeX = 10 ;
335+ } else {
336+ console . log ( "Provided direction must be left or right !" ) ;
337+ }
338+
339+ if ( this . _args . isAndroid ) {
340+ const action = new this . _wd . TouchAction ( this . _driver ) ;
341+ action . press ( { x : centerX , y : centerY } )
342+ . wait ( 100 )
343+ . moveTo ( { x : swipeX , y : centerY } )
344+ . release ( ) ;
345+ await action . perform ( ) ;
346+ }
347+ else {
348+ await this . _driver . execute ( 'mobile: dragFromToForDuration' , {
349+ duration : 2.0 ,
350+ fromX : centerX ,
351+ fromY : centerY ,
352+ toX : swipeX ,
353+ toY : centerY
354+ } ) ;
355+ }
356+ }
320357}
You can’t perform that action at this time.
0 commit comments