Best io.appium code snippet using io.appium.java_client.touch.offset.ElementOption.withCoordinates
Basic.java
Source:Basic.java
...79 int x = this.getInt(Data, 1, 10);80 int y = this.getInt(Data, 2, 10);81 TouchAction touchAction = new TouchAction(((MobileDriver) Driver));82 do {83 TapOptions tap = new TapOptions().withPosition(new PointOption().withCoordinates(x, y));84 touchAction.tap(tap);85 touchAction.release().perform();86 } while (--nof > 0);87 Report.updateTestLog(Action, "Tapped at co-ordinates '" + x + "','" + y + "'", Status.PASS);88 } catch (Exception ex) {89 Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);90 Logger.getLogger(Basic.class.getName()).log(Level.SEVERE, null, ex);91 }92 }93 /**94 * method for "zooming in" on an element on the screen.95 *96 * @see AppiumDriver#zoom(org.openqa.selenium.WebElement)97 */98 @Action(object = ObjectType.MOBILE, desc = "Zoom in [<Object>]")99 public void zoom() {100 try {101 if (Element != null) {102 int l = 150;103 TouchAction action0 = new TouchAction(((MobileDriver) Driver));104 TouchAction action1 = new TouchAction(((MobileDriver) Driver));105 action0.longPress(new LongPressOptions().withElement(new ElementOption().withElement(Element))).moveTo(new PointOption().withCoordinates(0, l)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).release();106 action1.longPress(new LongPressOptions().withElement(new ElementOption().withElement(Element))).moveTo(new PointOption().withCoordinates(0, -l)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).release();107 new MultiTouchAction(((MobileDriver) Driver)).add(action0).add(action1).perform();108 Report.updateTestLog(Action, "Zoomed in '" + ObjectName + "'", Status.PASS);109 } else {110 throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Condition);111 }112 } catch (ElementException ex) {113 Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);114 Logger.getLogger(Basic.class.getName()).log(Level.SEVERE, null, ex);115 }116 }117 /**118 * method for "zooming in" on an element on the screen.119 *120 * @see AppiumDriver#zoom(int, int)121 */122 @Action(object = ObjectType.BROWSER, desc = "Zoom at [<Data>]", input = InputType.YES)123 public void zoomAt() {124 try {125 int x = this.getInt(Data, 0, 10);126 int y = this.getInt(Data, 1, 10);127 int l = 100;128 TouchAction action0 = new TouchAction(((MobileDriver) Driver));129 TouchAction action1 = new TouchAction(((MobileDriver) Driver));130 action0.longPress(new LongPressOptions().withPosition(new PointOption().withCoordinates(x, y + l))).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100)))131 .moveTo(new PointOption().withCoordinates(0, 200)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100))).release();132 action1.longPress(new LongPressOptions().withPosition(new PointOption().withCoordinates(x + 50, y - l))).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100)))133 .moveTo(new PointOption().withCoordinates(0, -200)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100))).release();134 new MultiTouchAction(((MobileDriver) Driver)).add(action0).add(action1).perform();135 Report.updateTestLog(Action, "Zoomed at '" + x + "','" + y + "'", Status.PASS);136 } catch (Exception ex) {137 Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);138 Logger.getLogger(Basic.class.getName()).log(Level.SEVERE, null, ex);139 }140 }141 /**142 * method for pinching an element on the screen.143 *144 * @see AppiumDriver#pinch(org.openqa.selenium.WebElement)145 */146 @Action(object = ObjectType.MOBILE, desc = "Pinch [<Object>]")147 public void pinch() {148 try {149 if (Element != null) {150 int l = 150;151 TouchAction action0 = new TouchAction(((MobileDriver) Driver));152 TouchAction action1 = new TouchAction(((MobileDriver) Driver));153 LongPressOptions lop = new LongPressOptions();154 lop.withElement(new ElementOption().withElement(Element));155 action0.longPress(lop).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100)))156 .moveTo(new PointOption().withCoordinates(0, l)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).release();157 action1.longPress(new LongPressOptions().withElement(new ElementOption().withElement(Element))).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100)))158 .moveTo(new PointOption().withCoordinates(0, -l)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).release();159 new MultiTouchAction(((MobileDriver) Driver)).add(action0).add(action1).perform();160 Report.updateTestLog(Action, "Pinched '" + ObjectName + "'", Status.PASS);161 } else {162 throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Condition);163 }164 } catch (ElementException ex) {165 Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);166 Logger.getLogger(Basic.class.getName()).log(Level.SEVERE, null, ex);167 }168 }169 /**170 * method for pinching an element on the screen.171 *172 * @see AppiumDriver#pinch(int, int)173 */174 @Action(object = ObjectType.BROWSER, desc = "Pinch at [<Data>]", input = InputType.YES)175 public void pinchAt() {176 try {177 int x = this.getInt(Data, 0, 10);178 int y = this.getInt(Data, 1, 10);179 int l = 350;180 TouchAction action0 = new TouchAction(((MobileDriver) Driver));181 TouchAction action1 = new TouchAction(((MobileDriver) Driver));182 LongPressOptions lop = new LongPressOptions();183 lop.withPosition(new PointOption().withCoordinates(x, y - 1));184 action0.longPress(lop).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100)))185 .moveTo(new PointOption().withCoordinates(0, l - 200)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).release();186 action1.longPress(new LongPressOptions().withPosition(new PointOption().withCoordinates(x, y + l))).waitAction(new WaitOptions().withDuration(Duration.ofMillis(100)))187 .moveTo(new PointOption().withCoordinates(0, 200 - l)).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).release();188 new MultiTouchAction(((MobileDriver) Driver)).add(action0).add(action1).perform();189 Report.updateTestLog(Action, "Pinched at'" + x + "','" + y + "'", Status.PASS);190 } catch (Exception ex) {191 Report.updateTestLog(Action, ex.getMessage(), Status.DEBUG);192 Logger.getLogger(Basic.class.getName()).log(Level.SEVERE, null, ex);193 }194 }195 /**196 * Lock the device (bring it to the lock screen) for a given number of197 * seconds198 *199 * @see AppiumDriver#lockScreen(int)200 */201 @Action(object = ObjectType.BROWSER, desc = "Lock the screen", input = InputType.YES)...
Tools.java
Source:Tools.java
...66 MobileElement start = dragStart;67 TouchAction action = new TouchAction(driver);68 action.press(new ElementOption()69 .withElement(start))70 .moveTo(new PointOption().withCoordinates(x,y))71 .perform();72 }73 public static void swipeScreen(Direction dir,PointOption pointOptionStart, AndroidDriver<AndroidElement> driver) {74 System.out.println("swipeScreen(): dir: '" + dir + "'"); // always log your actions75 final int ANIMATION_TIME = 200;76 final int PRESS_TIME = 200;77 int edgeBorder = 10;78 PointOption pointOptionEnd;79 Dimension dims = driver.manage().window().getSize();80 pointOptionStart = PointOption.point(dims.width / 2, dims.height / 2);81 switch (dir) {82 case DOWN: // center of footer83 pointOptionEnd = PointOption.point(dims.width / 2, dims.height - edgeBorder);84 break;85 case UP: // center of header86 pointOptionEnd = PointOption.point(dims.width / 2, edgeBorder);87 break;88 case LEFT: // center of left side89 pointOptionEnd = PointOption.point(edgeBorder, dims.height / 2);90 break;91 case RIGHT: // center of right side92 pointOptionEnd = PointOption.point(dims.width - edgeBorder, dims.height / 2);93 break;94 default:95 throw new IllegalArgumentException("swipeScreen(): dir: '" + dir + "' NOT supported");96 }97 // execute swipe using TouchAction98 try {99 new TouchAction(driver)100 .press(pointOptionStart)101 // a bit more reliable when we add small wait102 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(PRESS_TIME)))103 .moveTo(pointOptionEnd)104 .release()105 .perform();106 } catch (Exception e) {107 System.err.println("swipeScreen(): TouchAction FAILED\n" + e.getMessage());108 return;109 }110 // always allow swipe action to complete111 try {112 Thread.sleep(ANIMATION_TIME);113 } catch (InterruptedException e) {114 // ignore115 }116 }117 public static void swipeElementAndroid(MobileElement el, Direction dir, AndroidDriver<AndroidElement> driver) {118 System.out.println("swipeElementAndroid(): dir: '" + dir + "'"); // always log your actions119 // Animation default time:120 // - Android: 300 ms121 // - iOS: 200 ms122 // final value depends on your app and could be greater123 final int ANIMATION_TIME = 200; // ms124 final int PRESS_TIME = 200; // ms125 int edgeBorder;126 PointOption pointOptionStart, pointOptionEnd;127 // init screen variables128 Rectangle rect = el.getRect();129 // sometimes it is needed to configure edgeBorders130 // you can also improve borders to have vertical/horizontal131 // or left/right/up/down border variables132 edgeBorder = 0;133 switch (dir) {134 case DOWN: // from up to down135 pointOptionStart = PointOption.point(rect.x + rect.width / 2,136 rect.y + edgeBorder);137 pointOptionEnd = PointOption.point(rect.x + rect.width / 2,138 rect.y + rect.height - edgeBorder);139 break;140 case UP: // from down to up141 pointOptionStart = PointOption.point(rect.x + rect.width / 2,142 rect.y + rect.height - edgeBorder);143 pointOptionEnd = PointOption.point(rect.x + rect.width / 2,144 rect.y + edgeBorder);145 break;146 case LEFT: // from right to left147 pointOptionStart = PointOption.point(rect.x + rect.width - edgeBorder,148 rect.y + rect.height / 2);149 pointOptionEnd = PointOption.point(rect.x + edgeBorder,150 rect.y + rect.height / 2);151 break;152 case RIGHT: // from left to right153 pointOptionStart = PointOption.point(rect.x + edgeBorder,154 rect.y + rect.height / 2);155 pointOptionEnd = PointOption.point(rect.x + rect.width - edgeBorder,156 rect.y + rect.height / 2);157 break;158 default:159 throw new IllegalArgumentException("swipeElementAndroid(): dir: '" + dir + "' NOT supported");160 }161 // execute swipe using TouchAction162 try {163 new TouchAction(driver)164 .press(pointOptionStart)165 // a bit more reliable when we add small wait166 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(PRESS_TIME)))167 .moveTo(pointOptionEnd)168 .release().perform();169 } catch (Exception e) {170 System.err.println("swipeElementAndroid(): TouchAction FAILED\n" + e.getMessage());171 return;172 }173 // always allow swipe action to complete174 try {175 Thread.sleep(ANIMATION_TIME);176 } catch (InterruptedException e) {177 // ignore178 }179 }180 public static void zoomIn(AndroidElement elem, AndroidDriver<AndroidElement> driver){181 int x = elem.getLocation().getX() + elem.getSize().getWidth()/2;182 int y = elem.getLocation().getY() + elem.getSize().getHeight()/2;183 TouchAction finger1 = new TouchAction(driver);184 finger1.press(new ElementOption()185 .withElement(elem)186 .withCoordinates(x,y-10))187 .moveTo(new ElementOption()188 .withElement(elem)189 .withCoordinates(x,y-100));190 TouchAction finger2 = new TouchAction(driver);191 finger2.press(new ElementOption()192 .withElement(elem)193 .withCoordinates(x,y+10))194 .moveTo(new ElementOption()195 .withElement(elem)196 .withCoordinates(x,y+100));197 MultiTouchAction action = new MultiTouchAction(driver);198 action.add(finger1).add(finger2).perform();199 }200 public static void zoomOut(AndroidElement elem, AndroidDriver<AndroidElement> driver){201 int x = elem.getLocation().getX() + elem.getSize().getWidth()/2;202 int y = elem.getLocation().getY() + elem.getSize().getHeight()/2;203 TouchAction finger1 = new TouchAction(driver);204 finger1.press(new ElementOption()205 .withElement(elem)206 .withCoordinates(x,y-100))207 .moveTo(new ElementOption()208 .withElement(elem)209 .withCoordinates(x,y-10));210 TouchAction finger2 = new TouchAction(driver);211 finger2.press(new ElementOption()212 .withElement(elem)213 .withCoordinates(x,y+100))214 .moveTo(new ElementOption()215 .withElement(elem)216 .withCoordinates(x,y+10));217 MultiTouchAction action = new MultiTouchAction(driver);218 action.add(finger1).add(finger2).perform();219 }220 public enum Direction {221 UP,222 DOWN,223 LEFT,224 RIGHT;225 }226}...
Gesture.java
Source:Gesture.java
...50 int distance = 100;51 Point c = ((MobileElement) Element).getCenter();52 LongPressOptions lop = new LongPressOptions();53 lop.withElement(new ElementOption().withElement((MobileElement) Element));54 lop.withPosition(new PointOption().withCoordinates(c.x + distance, c.y));55 action.longPress(lop).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).perform();56 Report.updateTestLog(Action, "Sucessfully swiped towards right", Status.DONE);57 } else {58 throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Condition);59 }60 } else {61 Dimension size = ((MobileDriver) Driver).manage().window().getSize();62 int startX, endX;63 if (Data != null && Data.contains(",")) {64 startX = (int) (size.width * (getInt(Data, 0, 20) / 100d));65 endX = (int) (size.width * (getInt(Data, 1, 80) / 100d));66 } else {67 startX = (int) (size.width * 0.20);68 endX = (int) (size.width * 0.80);69 }70 int Y = size.height / 2;71 swipe(startX, Y, endX, Y, Duration.ofMillis(getInt(Data, 2, defWaitTimeOut)));72 Report.updateTestLog(Action, "Sucessfully swiped towards right", Status.DONE);73 }74 } catch (Exception ex) {75 Report.updateTestLog(Action, ex.getMessage(), Status.FAIL);76 Logger.getLogger(Gesture.class.getName()).log(Level.SEVERE, null, ex);77 }78 }79 @Action(object = ObjectType.BROWSER, desc = "Swipe left [<Data>]", input = InputType.OPTIONAL)80 public void swipeLeft() {81 try {82 if (!browserAction()) {83 if (Element != null) {84 TouchAction action = new TouchAction(((MobileDriver) Driver));85 int distance = 100;86 Point c = ((MobileElement) Element).getCenter();87 LongPressOptions lop = new LongPressOptions();88 lop.withElement(new ElementOption().withElement((MobileElement) Element));89 lop.withPosition(new PointOption().withCoordinates(c.x - distance, c.y));90 action.longPress(lop).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).perform();91 Report.updateTestLog(Action, "Sucessfully swiped towards left", Status.DONE);92 } else {93 throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Condition);94 }95 } else {96 Dimension size = ((MobileDriver) Driver).manage().window().getSize();97 int startX, endX;98 if (Data != null && Data.contains(",")) {99 startX = (int) (size.width * (getInt(Data, 0, 80) / 100d));100 endX = (int) (size.width * (getInt(Data, 1, 20) / 100d));101 } else {102 startX = (int) (size.width * 0.80);103 endX = (int) (size.width * 0.20);104 }105 int Y = size.height / 2;106 swipe(startX, Y, endX, Y, Duration.ofMillis(getInt(Data, 2, defWaitTimeOut)));107 Report.updateTestLog(Action, "Sucessfully swiped towards left", Status.DONE);108 }109 } catch (Exception ex) {110 Report.updateTestLog(Action, ex.getMessage(), Status.FAIL);111 Logger.getLogger(Gesture.class.getName()).log(Level.SEVERE, null, ex);112 }113 }114 private void swipe(int startX, int startY, int endX, int endY, Duration wt) {115 TouchAction touchAction = new TouchAction(((MobileDriver) Driver));116 touchAction.press(new PointOption().withCoordinates(startX, startY)).waitAction(new WaitOptions().withDuration(wt)).moveTo(new PointOption().withCoordinates(endX, endY))117 .release().perform();118 }119 @Action(object = ObjectType.ANY, desc = "Swipe down [<Data>]", input = InputType.OPTIONAL)120 public void swipeDown() {121 try {122 if (!browserAction()) {123 if (Element != null) {124 TouchAction action = new TouchAction(((MobileDriver) Driver));125 int distance = 100;126 Point c = ((MobileElement) Element).getCenter();127 LongPressOptions lop = new LongPressOptions();128 lop.withElement(new ElementOption().withElement((MobileElement) Element));129 lop.withPosition(new PointOption().withCoordinates(c.x, c.y + distance));130 action.longPress(lop).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).perform();131 Report.updateTestLog(Action, "Sucessfully swiped towards down", Status.DONE);132 } else {133 throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Condition);134 }135 } else {136 Dimension size = ((MobileDriver) Driver).manage().window().getSize();137 int startY, endY;138 if (Data != null && Data.contains(",")) {139 startY = (int) (size.height * (getInt(Data, 0, 20) / 100d));140 endY = (int) (size.height * (getInt(Data, 1, 80) / 100d));141 } else {142 startY = (int) (size.height * 0.20);143 endY = (int) (size.height * 0.80);144 }145 int X = size.width / 2;146 swipe(X, startY, X, endY, Duration.ofMillis(getInt(Data, 2, defWaitTimeOut)));147 Report.updateTestLog(Action, "Sucessfully swiped towards down", Status.DONE);148 }149 } catch (Exception ex) {150 Report.updateTestLog(Action, ex.getMessage(), Status.FAIL);151 Logger.getLogger(Gesture.class.getName()).log(Level.SEVERE, null, ex);152 }153 }154 @Action(object = ObjectType.ANY, desc = "Swipe up [<Data>]", input = InputType.OPTIONAL)155 public void swipeUp() {156 try {157 if (!browserAction()) {158 if (Element != null) {159 TouchAction action = new TouchAction(((MobileDriver) Driver));160 int distance = 100;161 Point c = ((MobileElement) Element).getCenter();162 LongPressOptions lop = new LongPressOptions();163 lop.withElement(new ElementOption().withElement((MobileElement) Element));164 lop.withPosition(new PointOption().withCoordinates(c.x, c.y - distance));165 action.longPress(lop).waitAction(new WaitOptions().withDuration(Duration.ofMillis(500))).perform();166 Report.updateTestLog(Action, "Sucessfully swiped towards up", Status.DONE);167 } else {168 throw new ElementException(ElementException.ExceptionType.Element_Not_Found, Condition);169 }170 } else {171 Dimension size = ((MobileDriver) Driver).manage().window().getSize();172 int startY, endY;173 if (Data != null && Data.contains(",")) {174 startY = (int) (size.width * (getInt(Data, 0, 80) / 100d));175 endY = (int) (size.width * (getInt(Data, 1, 20) / 100d));176 } else {177 startY = (int) (size.width * 0.80);178 endY = (int) (size.width * 0.20);...
CommonPage.java
Source:CommonPage.java
...54 }55 public void scroll(WebElement elementoOrigem, WebElement elementoDestino) {56 Dimension size = getDriver().manage().window().getSize();57 new TouchAction(getDriver())58 .press(new PointOption().withCoordinates(elementoOrigem.getLocation()))59 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))60 .moveTo(new PointOption().withCoordinates(elementoDestino.getLocation()))61 .release()62 .perform();63 }64 public void swipe(double inicio, double fim) {65 Dimension size = getDriver().manage().window().getSize();66 int xStart = (int) (size.width * inicio);67 int xEnd = (int) (size.width * fim);68 int y = size.height / 2;69 new TouchAction(getDriver())70 .press(PointOption.point(xStart, y))71 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))72 .moveTo(PointOption.point(xEnd, y))73 .release()74 .perform();75 }76 public void swipeElement(WebElement element, double inicio, double fim) {77 int y = element.getLocation().y + (element.getSize().height / 2);78 int xStart = (int) (element.getSize().width * inicio);79 int xEnd = (int) (element.getSize().width * fim);80 new TouchAction(getDriver())81// .press(ElementOption.element(element, xStart, y))82 .press(PointOption.point(xStart, y))83 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))84// .moveTo(ElementOption.element(element, xEnd, y))85 .moveTo(PointOption.point(xEnd, y))86 .release()87 .perform();88 }89 public void dragAndDrop(WebElement elementoOrigem, WebElement elementoDestino) {90 /*new Actions(getDriver())91 .clickAndHold(elementoOrigem)92 .dragAndDrop(elementoOrigem, elementoDestino)93 .release()94 .perform();*/95 new TouchAction(getDriver())96 .longPress(new LongPressOptions().withElement(new ElementOption().withElement(elementoOrigem)))97 .moveTo(new PointOption().withCoordinates(elementoDestino.getLocation()))98 .release()99 .perform();100 }101 public void singleTap(By by){102 WebElement element = getElement(by);103 TouchActions action = new TouchActions(getDriver());104 action.singleTap(element).perform();105 }106 public void doubleTap(By by){107 WebElement element = getElement(by);108 TouchActions action = new TouchActions(getDriver());109 action.doubleTap(element).perform();110 }111 public void tap(int x, int y) {...
BasePage.java
Source:BasePage.java
...44 return getTxt(By.id("android:id/message"));45 }46 public void taps(int x, int y) {47 TouchAction touchAction = new TouchAction(getDriver());48 touchAction.tap(new PointOption().withCoordinates(x,y)).perform();49 }50 public void scrollDown() {51 scroll(0.9,0.1);52 }53 public void scrollUp() {54 scroll(0.1,0.9);55 }56 public void swipeLeft() {57 swipe(0.1,0.9);58 }59 public void swipeRight() {60 swipe(0.9,0.1);61 }62 public void scroll(double inicio, double fim) {63 Dimension size = getDriver().manage().window().getSize();64 int x = size.width / 2;65 int y = (int) (size.height * inicio);66 int end_y = (int) (size.height * fim);67 TouchAction touchAction = new TouchAction(getDriver());68 touchAction.press(new PointOption().withCoordinates(x,y))69 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))70 .moveTo(new PointOption().withCoordinates(x,end_y))71 .release()72 .perform();73 }74 public void swipe(double inicio, double fim) {75 Dimension size = getDriver().manage().window().getSize();76 int y = size.height / 2;77 int start_x = (int) (size.width * inicio);78 int end_x = (int) (size.width * fim);79 TouchAction touchAction = new TouchAction(getDriver());80 touchAction.press(new PointOption().withCoordinates(start_x,y))81 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))82 .moveTo(new PointOption().withCoordinates(end_x,y))83 .release()84 .perform();85 }86 public void swipeElement(MobileElement element, double inicio, double fim) {87 int y = element.getLocation().y + (element.getSize().height / 2);88 int start_x = (int) (element.getSize().width * inicio);89 int end_x = (int) (element.getSize().width * fim);90 TouchAction touchAction = new TouchAction(getDriver());91 touchAction.press(new PointOption().withCoordinates(start_x,y))92 .waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))93 .moveTo(new PointOption().withCoordinates(end_x,y))94 .release()95 .perform();96 }97 public void longClick(By by) {98 WebElement test = getDriver().findElement(by);99 TouchAction touchAction = new TouchAction(getDriver());100 touchAction.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(test))).perform();101 }102}...
Scrolling1.java
Source:Scrolling1.java
...32 33 Thread.sleep(2000);34 35 // Perform scrolling from point1(425,1766) to point 2 (360,564)36 ta.press(new PointOption().withCoordinates(509,1679)).moveTo(new PointOption().withCoordinates(520,625))37 .release()38 .perform();39 40 ta.press(new PointOption().withCoordinates(509,1679)).moveTo(new PointOption().withCoordinates(520,625))41 .release()42 .perform();43 44 ta.press(new PointOption().withCoordinates(509,1679)).moveTo(new PointOption().withCoordinates(520,625))45 .release()46 .perform();47 48 Thread.sleep(3000);49 //Scroll 3 times , and tap on textfields50 51 MobileElement e2 = driver.findElementByAccessibilityId("TextFields");52 53 ta.tap(ElementOption.element(e2)).release().perform();54 55 Thread.sleep(3000);56 57 driver.findElementById("io.appium.android.apis:id/edit").sendKeys("A");58 ...
ScrollingApiDemos.java
Source:ScrollingApiDemos.java
...30 31 for(int i =0; i<5;i++)32 {33 34 ta.press(new PointOption().withCoordinates(601,1182))35 .moveTo(new PointOption().withCoordinates(588, 516))36 .release()37 .perform();38 39 40 }41 42 MobileElement e1 = driver.findElementByAccessibilityId("TextFields");43 44 ta.tap(TapOptions.tapOptions().withElement(ElementOption.element(e1))).perform();45 46 47 driver.findElementById("io.appium.android.apis:id/edit").sendKeys("A");48 49 driver.pressKey(new KeyEvent(AndroidKey.P));...
ClockPage.java
Source:ClockPage.java
...14 private AndroidElement minutes_start_location;15 @Step16 public void changeHour(AndroidDriver driver) {17 TouchAction touch = new TouchAction(driver);18 touch.press(new ElementOption().withElement(hour_start_location)).moveTo(new ElementOption().withCoordinates(282, 894)).release().perform();19 touch.press(new ElementOption().withElement(minutes_start_location)).moveTo(new ElementOption().withCoordinates(251, 776)).release().perform();20 }21}...
withCoordinates
Using AI Code Generation
1import io.appium.java_client.TouchAction;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.touch.offset.ElementOption;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.remote.DesiredCapabilities;8import org.testng.annotations.AfterTest;9import org.testng.annotations.BeforeTest;10import org.testng.annotations.Test;11import java.net.MalformedURLException;12import java.net.URL;13import java.util.concurrent.TimeUnit;14public class DragAndDrop {15 AndroidDriver<AndroidElement> driver;16 public void setUp() throws MalformedURLException {17 DesiredCapabilities capabilities = new DesiredCapabilities();18 capabilities.setCapability("deviceName", "Android Device");19 capabilities.setCapability("platformName", "Android");20 capabilities.setCapability("platformVersion", "9.0");21 capabilities.setCapability("appPackage", "com.android.chrome");22 capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");23 capabilities.setCapability("noReset", "true");
withCoordinates
Using AI Code Generation
1import org.openqa.selenium.WebElement;2import org.openqa.selenium.interactions.touch.TouchActions;3import org.openqa.selenium.remote.DesiredCapabilities;4import io.appium.java_client.AppiumDriver;5import io.appium.java_client.MobileElement;6import io.appium.java_client.android.AndroidDriver;7import io.appium.java_client.touch.offset.ElementOption;8public class appium {9 public static void main(String[] args) throws MalformedURLException {10 DesiredCapabilities caps = new DesiredCapabilities();11 caps.setCapability("deviceName", "Redmi");12 caps.setCapability("udid", "f1c3d3b7");13 caps.setCapability("platformName", "Android");14 caps.setCapability("platformVersion", "9");15 caps.setCapability("appPackage", "com.google.android.apps.messaging");16 caps.setCapability("appActivity", "com.google.android.apps.messaging.ui.ConversationListActivity");17 caps.setCapability("noReset", "true");
withCoordinates
Using AI Code Generation
1TouchAction action = new TouchAction(driver);2action.press(ElementOption.element(element)).moveTo(ElementOption.element(element2)).release().perform();3TouchAction action = new TouchAction(driver);4action.press(PointOption.point(100, 100)).moveTo(PointOption.point(200, 200)).release().perform();5TouchAction action = new TouchAction(driver);6action.press(PointOption.point(element)).moveTo(PointOption.point(element2)).release().perform();7TouchAction action = new TouchAction(driver);8action.press(PointOption.point(element.getLocation())).moveTo(PointOption.point(element2.getLocation())).release().perform();9TouchAction action = new TouchAction(driver);10action.press(PointOption.point(element2.getLocation())).moveTo(PointOption.point(element.getLocation())).release().perform();11TouchAction action = new TouchAction(driver);12action.press(PointOption.point(element.getLocation())).moveTo(PointOption.point(element.getLocation())).release().perform();13TouchAction action = new TouchAction(driver);14action.press(PointOption.point(element2.getLocation())).moveTo(PointOption.point(element2.getLocation())).release().perform();15TouchAction action = new TouchAction(driver);16action.press(PointOption.point(element.getLocation())).moveTo(PointOption.point(element2.getLocation())).release().perform();17TouchAction action = new TouchAction(driver);18action.press(PointOption.point(element2.getLocation())).moveTo(PointOption.point(element.getLocation())).release().perform();19TouchAction action = new TouchAction(driver);20action.press(PointOption.point(element2.getLocation())).moveTo(PointOption.point(element.getLocation())).release().perform();
withCoordinates
Using AI Code Generation
1TouchAction action = new TouchAction(driver);2action.tap(ElementOption.element(element1)).perform();3TouchAction action = new TouchAction(driver);4action.tap(PointOption.point(element1.getLocation().getX(), element1.getLocation().getY())).perform();5action = TouchAction(self._driver)6action.tap(element=element1).perform()7action = TouchAction(self._driver)8action.tap(x=element1.location['x'], y=element1.location['y']).perform()9action.tap(element: element1).perform10action.tap(x: element1.location.x, y: element1.location.y).perform11var action = new appium.TouchAction();12action.tap({element: element1}).perform();13var action = new appium.TouchAction();14action.tap({x: element1.getLocation().x, y: element1.getLocation().y}).perform();15AppiumTouchAction action = new AppiumTouchAction(driver);16action.Tap(element1).Perform();17AppiumTouchAction action = new AppiumTouchAction(driver);18action.Tap(element1.Location.X, element1.Location.Y).Perform();19$action = new Appium\AppiumTouchAction($this->getDriver());20$action->tap(array('element' => $element1))->perform();21$action = new Appium\AppiumTouchAction($this->get
withCoordinates
Using AI Code Generation
1TouchAction touchAction = new TouchAction(driver);2touchAction.longPress(element).moveTo(element2).release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.longPress(element).moveTo(PointOption.point(100, 100)).release().perform();5TouchAction touchAction = new TouchAction(driver);6touchAction.longPress(element).moveTo(PointOption.point(element2)).release().perform();7TouchAction touchAction = new TouchAction(driver);8touchAction.longPress(element).moveTo(PointOption.point(element2, 100, 100)).release().perform();9TouchAction touchAction = new TouchAction(driver);10touchAction.longPress(element).moveTo(PointOption.point(100, 100, element2)).release().perform();11TouchAction touchAction = new TouchAction(driver);12touchAction.longPress(element).moveTo(PointOption.point(100, 100, element2, 100, 100)).release().perform();13TouchAction touchAction = new TouchAction(driver);14touchAction.longPress(element).moveTo(PointOption.point(100, 100, element2, 100, 100, 100, 100)).release().perform();15TouchAction touchAction = new TouchAction(driver);16touchAction.longPress(element).moveTo(PointOption.point(100, 100, element2, 100, 100, 100, 100, 100, 100)).release().perform();
withCoordinates
Using AI Code Generation
1((AndroidDriver)driver).tap(1, ((AndroidDriver)driver).findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.android.packageinstaller:id/permission_allow_button\")")), 1000);2((AndroidDriver)driver).tap(1, new PointOption().withCoordinates(100, 200), 1000);3((AndroidDriver)driver).tap(1, new PointOption().withCoordinates(100, 200), 1000);4((AndroidDriver)driver).tap(1, new PointOption().withCoordinates(100, 200), 1000);5((AndroidDriver)driver).tap(1, ((AndroidDriver)driver).findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.android.packageinstaller:id/permission_allow_button\")")), 1000);6((AndroidDriver)driver).tap(1, new PointOption().withCoordinates(100, 200), 1000);7((AndroidDriver)driver).tap(1, new PointOption().withCoordinates(100, 200), 1000);8((AndroidDriver)driver).tap(1, new PointOption().withCoordinates(100, 200), 1000);9((AndroidDriver)driver).tap(1, ((AndroidDriver)driver).findElement(MobileBy.AndroidUIAutomator("new UiSelector().resourceId(\"com.android.packageinstaller:id/permission_allow_button\")")), 1000);
withCoordinates
Using AI Code Generation
1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.MobileBy;6import io.appium.java_client.MobileElement;7import io.appium.java_client.android.AndroidDriver;8import io.appium.java_client.touch.WaitOptions;9import io.appium.java_client.touch.offset.ElementOption;10import static java.time.Duration.ofSeconds;11public class swipeDown {12 public static void main(String[] args) throws MalformedURLException, InterruptedException {13 DesiredCapabilities cap = new DesiredCapabilities();14 cap.setCapability("deviceName", "Redmi");15 cap.setCapability("udid", "c3b6a7a6");16 cap.setCapability("platformName", "Android");17 cap.setCapability("platformVersion", "9");18 cap.setCapability("appPackage", "com.miui.calculator");19 cap.setCapability("appActivity", "com.miui.calculator.cal.CalculatorActivity");
withCoordinates
Using AI Code Generation
1import io.appium.java_client.MobileBy;2import io.appium.java_client.TouchAction;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidElement;5import io.appium.java_client.touch.WaitOptions;6import io.appium.java_client.touch.offset.ElementOption;7import org.openqa.selenium.By;8import org.openqa.selenium.Dimension;9import org.openqa.selenium.WebElement;10import org.openqa.selenium.remote.DesiredCapabilities;11import java.net.MalformedURLException;12import java.net.URL;13import java.time.Duration;14import java.util.concurrent.TimeUnit;15public class Swipe {16 public static void main(String[] args) throws MalformedURLException, InterruptedException {17 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();18 desiredCapabilities.setCapability("platformName", "Android");19 desiredCapabilities.setCapability("deviceName", "Pixel_2_API_29");20 desiredCapabilities.setCapability("appPackage", "io.appium.android.apis");21 desiredCapabilities.setCapability("appActivity", ".ApiDemos");22 desiredCapabilities.setCapability("automationName", "UiAutomator2");23 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);24 driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Views\"))"));25 driver.findElementByAccessibilityId("Views").click();26 driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"WebView\"))"));27 driver.findElementByAccessibilityId("WebView").click();28 driver.context("WEBVIEW_io.appium.android.apis");29 driver.findElementByLinkText("i am a link").click();30 driver.context("NATIVE_APP");31 driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"WebView\"))"));
withCoordinates
Using AI Code Generation
1import java.net.MalformedURLException;2import java.net.URL;3import java.util.concurrent.TimeUnit;4import org.openqa.selenium.By;5import org.openqa.selenium.Dimension;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.remote.DesiredCapabilities;8import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.remote.MobileCapabilityType;10import io.appium.java_client.touch.offset.ElementOption;11public class AppiumJavaClient {12 public static void main(String[] args) throws MalformedURLException, InterruptedException {13 DesiredCapabilities cap = new DesiredCapabilities();14 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Device");15 cap.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");16 cap.setCapability("appPackage", "com.example.android.apis");17 cap.setCapability("appActivity", "com.example.android.apis.ApiDemos");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!