2828import org .openqa .selenium .By ;
2929import org .openqa .selenium .Capabilities ;
3030import org .openqa .selenium .DeviceRotation ;
31- import org .openqa .selenium .Dimension ;
32- import org .openqa .selenium .Point ;
3331import org .openqa .selenium .ScreenOrientation ;
3432import org .openqa .selenium .WebDriver ;
3533import org .openqa .selenium .WebDriverException ;
6765 * for each target mobile OS (still Android and iOS)
6866*/
6967@ SuppressWarnings ("unchecked" )
70- public abstract class AppiumDriver <T extends WebElement >
68+ public class AppiumDriver <T extends WebElement >
7169 extends DefaultGenericMobileDriver <T > {
7270
7371 private static final ErrorHandler errorHandler = new ErrorHandler (new ErrorCodesMobile (), true );
@@ -214,9 +212,11 @@ public List<T> findElementsByXPath(String using) {
214212 }
215213
216214 /**
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)}.
218217 */
219- @ Override public void tap (int fingers , WebElement element , int duration ) {
218+ @ Deprecated
219+ public void tap (int fingers , WebElement element , int duration ) {
220220 MultiTouchAction multiTouch = new MultiTouchAction (this );
221221
222222 for (int i = 0 ; i < fingers ; i ++) {
@@ -227,81 +227,49 @@ public List<T> findElementsByXPath(String using) {
227227 }
228228
229229 /**
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)}.
231232 */
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 ) {
233235 MultiTouchAction multiTouch = new MultiTouchAction (this );
234236
235237 for (int i = 0 ; i < fingers ; i ++) {
236238 multiTouch .add (createTap (x , y , duration ));
237239 }
238-
239240 multiTouch .perform ();
240241 }
241242
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-
251243 /**
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)}.
253246 */
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+ }
255251
256252 /**
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)}.
266255 */
256+ @ Deprecated
267257 public void pinch (WebElement el ) {
268258 MultiTouchAction multiTouch = new MultiTouchAction (this );
269259
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 ();
286261 }
287262
288263 /**
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)}
300267 */
268+ @ Deprecated
301269 public void pinch (int x , int y ) {
302270 MultiTouchAction multiTouch = new MultiTouchAction (this );
303271
304- int scrHeight = manage ().window ().getSize ().getHeight ();
272+ int scrHeight = this . manage ().window ().getSize ().getHeight ();
305273 int yOffset = 100 ;
306274
307275 if (y - 100 < 0 ) {
@@ -313,57 +281,30 @@ public void pinch(int x, int y) {
313281 TouchAction action0 = new TouchAction (this ).press (x , y - yOffset ).moveTo (x , y ).release ();
314282 TouchAction action1 = new TouchAction (this ).press (x , y + yOffset ).moveTo (x , y ).release ();
315283
316- multiTouch .add (action0 ).add (action1 );
317-
318- multiTouch .perform ();
284+ multiTouch .add (action0 ).add (action1 ).perform ();
319285 }
320286
321287 /**
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)}.
331290 */
291+ @ Deprecated
332292 public void zoom (WebElement el ) {
333293 MultiTouchAction multiTouch = new MultiTouchAction (this );
334294
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 ();
349296 }
350297
351298 /**
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)}.
362302 */
303+ @ Deprecated
363304 public void zoom (int x , int y ) {
364305 MultiTouchAction multiTouch = new MultiTouchAction (this );
365306
366- int scrHeight = manage ().window ().getSize ().getHeight ();
307+ int scrHeight = this . manage ().window ().getSize ().getHeight ();
367308 int yOffset = 100 ;
368309
369310 if (y - 100 < 0 ) {
@@ -375,9 +316,7 @@ public void zoom(int x, int y) {
375316 TouchAction action0 = new TouchAction (this ).press (x , y ).moveTo (0 , -yOffset ).release ();
376317 TouchAction action1 = new TouchAction (this ).press (x , y ).moveTo (0 , yOffset ).release ();
377318
378- multiTouch .add (action0 ).add (action1 );
379-
380- multiTouch .perform ();
319+ multiTouch .add (action0 ).add (action1 ).perform ();
381320 }
382321
383322 @ Override public WebDriver context (String name ) {
@@ -447,11 +386,13 @@ public void zoom(int x, int y) {
447386 locationContext .setLocation (location );
448387 }
449388
389+ @ Deprecated
450390 private TouchAction createTap (WebElement element , int duration ) {
451391 TouchAction tap = new TouchAction (this );
452392 return tap .press (element ).waitAction (duration ).release ();
453393 }
454394
395+ @ Deprecated
455396 private TouchAction createTap (int x , int y , int duration ) {
456397 TouchAction tap = new TouchAction (this );
457398 return tap .press (x , y ).waitAction (duration ).release ();
0 commit comments