28
28
import org .openqa .selenium .By ;
29
29
import org .openqa .selenium .Capabilities ;
30
30
import org .openqa .selenium .DeviceRotation ;
31
- import org .openqa .selenium .Dimension ;
32
- import org .openqa .selenium .Point ;
33
31
import org .openqa .selenium .ScreenOrientation ;
34
32
import org .openqa .selenium .WebDriver ;
35
33
import org .openqa .selenium .WebDriverException ;
67
65
* for each target mobile OS (still Android and iOS)
68
66
*/
69
67
@ SuppressWarnings ("unchecked" )
70
- public abstract class AppiumDriver <T extends WebElement >
68
+ public class AppiumDriver <T extends WebElement >
71
69
extends DefaultGenericMobileDriver <T > {
72
70
73
71
private static final ErrorHandler errorHandler = new ErrorHandler (new ErrorCodesMobile (), true );
@@ -214,9 +212,11 @@ public List<T> findElementsByXPath(String using) {
214
212
}
215
213
216
214
/**
217
- * @see TouchShortcuts#tap(int, WebElement, int).
215
+ * This method is deprecated and it is going to be removed soon.
216
+ * Please use {@link MultiTouchAction#tap(int, WebElement, int)}.
218
217
*/
219
- @ Override public void tap (int fingers , WebElement element , int duration ) {
218
+ @ Deprecated
219
+ public void tap (int fingers , WebElement element , int duration ) {
220
220
MultiTouchAction multiTouch = new MultiTouchAction (this );
221
221
222
222
for (int i = 0 ; i < fingers ; i ++) {
@@ -227,81 +227,49 @@ public List<T> findElementsByXPath(String using) {
227
227
}
228
228
229
229
/**
230
- * @see TouchShortcuts#tap(int, int, int, int).
230
+ * This method is deprecated and it is going to be removed soon.
231
+ * Please use {@link MultiTouchAction#tap(int, int, int, int)}.
231
232
*/
232
- @ Override public void tap (int fingers , int x , int y , int duration ) {
233
+ @ Deprecated
234
+ public void tap (int fingers , int x , int y , int duration ) {
233
235
MultiTouchAction multiTouch = new MultiTouchAction (this );
234
236
235
237
for (int i = 0 ; i < fingers ; i ++) {
236
238
multiTouch .add (createTap (x , y , duration ));
237
239
}
238
-
239
240
multiTouch .perform ();
240
241
}
241
242
242
- protected void doSwipe (int startx , int starty , int endx , int endy , int duration ) {
243
- TouchAction touchAction = new TouchAction (this );
244
-
245
- // appium converts press-wait-moveto-release to a swipe action
246
- touchAction .press (startx , starty ).waitAction (duration ).moveTo (endx , endy ).release ();
247
-
248
- touchAction .perform ();
249
- }
250
-
251
243
/**
252
- * @see TouchShortcuts#swipe(int, int, int, int, int).
244
+ * This method is deprecated.
245
+ * It was moved to {@link CreatesSwipeAction#swipe(int, int, int, int, int)}.
253
246
*/
254
- @ Override public abstract void swipe (int startx , int starty , int endx , int endy , int duration );
247
+ @ Deprecated
248
+ public void swipe (int startx , int starty , int endx , int endy , int duration ) {
249
+ //does nothing
250
+ }
255
251
256
252
/**
257
- * Convenience method for pinching an element on the screen.
258
- * "pinching" refers to the action of two appendages pressing the
259
- * screen and sliding towards each other.
260
- * NOTE:
261
- * This convenience method places the initial touches around the element, if this would
262
- * happen to place one of them off the screen, appium with return an outOfBounds error.
263
- * In this case, revert to using the MultiTouchAction api instead of this method.
264
- *
265
- * @param el The element to pinch.
253
+ * This method is deprecated and it is going to be removed soon.
254
+ * Please use {@link MultiTouchAction#pinch(WebElement)}.
266
255
*/
256
+ @ Deprecated
267
257
public void pinch (WebElement el ) {
268
258
MultiTouchAction multiTouch = new MultiTouchAction (this );
269
259
270
- Dimension dimensions = el .getSize ();
271
- Point upperLeft = el .getLocation ();
272
- Point center = new Point (upperLeft .getX () + dimensions .getWidth () / 2 ,
273
- upperLeft .getY () + dimensions .getHeight () / 2 );
274
- int yOffset = center .getY () - upperLeft .getY ();
275
-
276
- TouchAction action0 =
277
- new TouchAction (this ).press (el , center .getX (), center .getY () - yOffset ).moveTo (el )
278
- .release ();
279
- TouchAction action1 =
280
- new TouchAction (this ).press (el , center .getX (), center .getY () + yOffset ).moveTo (el )
281
- .release ();
282
-
283
- multiTouch .add (action0 ).add (action1 );
284
-
285
- multiTouch .perform ();
260
+ multiTouch .pinch (el ).perform ();
286
261
}
287
262
288
263
/**
289
- * Convenience method for pinching an element on the screen.
290
- * "pinching" refers to the action of two appendages pressing the screen and
291
- * sliding towards each other.
292
- * NOTE:
293
- * This convenience method places the initial touches around the element at a distance,
294
- * if this would happen to place one of them off the screen, appium will return an
295
- * outOfBounds error. In this case, revert to using the MultiTouchAction api instead of this
296
- * method.
297
- *
298
- * @param x x coordinate to terminate the pinch on.
299
- * @param y y coordinate to terminate the pinch on.
264
+ * This method is deprecated and it is going to be removed soon.
265
+ * Please use {@link MultiTouchAction#pinch(int, int, int, int)} or
266
+ * {@link MultiTouchAction#pinch(int, int, int)}
300
267
*/
268
+ @ Deprecated
301
269
public void pinch (int x , int y ) {
302
270
MultiTouchAction multiTouch = new MultiTouchAction (this );
303
271
304
- int scrHeight = manage ().window ().getSize ().getHeight ();
272
+ int scrHeight = this . manage ().window ().getSize ().getHeight ();
305
273
int yOffset = 100 ;
306
274
307
275
if (y - 100 < 0 ) {
@@ -313,57 +281,30 @@ public void pinch(int x, int y) {
313
281
TouchAction action0 = new TouchAction (this ).press (x , y - yOffset ).moveTo (x , y ).release ();
314
282
TouchAction action1 = new TouchAction (this ).press (x , y + yOffset ).moveTo (x , y ).release ();
315
283
316
- multiTouch .add (action0 ).add (action1 );
317
-
318
- multiTouch .perform ();
284
+ multiTouch .add (action0 ).add (action1 ).perform ();
319
285
}
320
286
321
287
/**
322
- * Convenience method for "zooming in" on an element on the screen.
323
- * "zooming in" refers to the action of two appendages pressing the screen and sliding
324
- * away from each other.
325
- * NOTE:
326
- * This convenience method slides touches away from the element, if this would happen
327
- * to place one of them off the screen, appium will return an outOfBounds error.
328
- * In this case, revert to using the MultiTouchAction api instead of this method.
329
- *
330
- * @param el The element to pinch.
288
+ * This method is deprecated and it is going to be removed soon.
289
+ * Please use {@link MultiTouchAction#zoom(WebElement)}.
331
290
*/
291
+ @ Deprecated
332
292
public void zoom (WebElement el ) {
333
293
MultiTouchAction multiTouch = new MultiTouchAction (this );
334
294
335
- Dimension dimensions = el .getSize ();
336
- Point upperLeft = el .getLocation ();
337
- Point center = new Point (upperLeft .getX () + dimensions .getWidth () / 2 ,
338
- upperLeft .getY () + dimensions .getHeight () / 2 );
339
- int yOffset = center .getY () - upperLeft .getY ();
340
-
341
- TouchAction action0 = new TouchAction (this ).press (center .getX (), center .getY ())
342
- .moveTo (el , center .getX (), center .getY () - yOffset ).release ();
343
- TouchAction action1 = new TouchAction (this ).press (center .getX (), center .getY ())
344
- .moveTo (el , center .getX (), center .getY () + yOffset ).release ();
345
-
346
- multiTouch .add (action0 ).add (action1 );
347
-
348
- multiTouch .perform ();
295
+ multiTouch .zoom (el ).perform ();
349
296
}
350
297
351
298
/**
352
- * Convenience method for "zooming in" on an element on the screen.
353
- * "zooming in" refers to the action of two appendages pressing the screen
354
- * and sliding away from each other.
355
- * NOTE:
356
- * This convenience method slides touches away from the element, if this would happen to
357
- * place one of them off the screen, appium will return an outOfBounds error. In this case,
358
- * revert to using the MultiTouchAction api instead of this method.
359
- *
360
- * @param x x coordinate to start zoom on.
361
- * @param y y coordinate to start zoom on.
299
+ * This method is deprecated and it is going to be removed soon.
300
+ * Please use {@link MultiTouchAction#zoom(int, int, int, int)} or
301
+ * {@link MultiTouchAction#zoom(int, int, int)}.
362
302
*/
303
+ @ Deprecated
363
304
public void zoom (int x , int y ) {
364
305
MultiTouchAction multiTouch = new MultiTouchAction (this );
365
306
366
- int scrHeight = manage ().window ().getSize ().getHeight ();
307
+ int scrHeight = this . manage ().window ().getSize ().getHeight ();
367
308
int yOffset = 100 ;
368
309
369
310
if (y - 100 < 0 ) {
@@ -375,9 +316,7 @@ public void zoom(int x, int y) {
375
316
TouchAction action0 = new TouchAction (this ).press (x , y ).moveTo (0 , -yOffset ).release ();
376
317
TouchAction action1 = new TouchAction (this ).press (x , y ).moveTo (0 , yOffset ).release ();
377
318
378
- multiTouch .add (action0 ).add (action1 );
379
-
380
- multiTouch .perform ();
319
+ multiTouch .add (action0 ).add (action1 ).perform ();
381
320
}
382
321
383
322
@ Override public WebDriver context (String name ) {
@@ -447,11 +386,13 @@ public void zoom(int x, int y) {
447
386
locationContext .setLocation (location );
448
387
}
449
388
389
+ @ Deprecated
450
390
private TouchAction createTap (WebElement element , int duration ) {
451
391
TouchAction tap = new TouchAction (this );
452
392
return tap .press (element ).waitAction (duration ).release ();
453
393
}
454
394
395
+ @ Deprecated
455
396
private TouchAction createTap (int x , int y , int duration ) {
456
397
TouchAction tap = new TouchAction (this );
457
398
return tap .press (x , y ).waitAction (duration ).release ();
0 commit comments