How to use AndroidTouchAction class of io.appium.java_client.android package

Best io.appium code snippet using io.appium.java_client.android.AndroidTouchAction

AppiumTest4.java

Source:AppiumTest4.java Github

copy

Full Screen

...19import io.appium.java_client.MobileElement;20import io.appium.java_client.TouchAction;21import io.appium.java_client.android.AndroidDriver;22import io.appium.java_client.android.AndroidElement;23import io.appium.java_client.android.AndroidTouchAction;24import io.appium.java_client.android.nativekey.AndroidKey;25import io.appium.java_client.android.nativekey.KeyEvent;26import io.appium.java_client.service.local.AppiumDriverLocalService;27import io.appium.java_client.service.local.AppiumServiceBuilder;28import io.appium.java_client.service.local.flags.GeneralServerFlag;29import io.appium.java_client.touch.LongPressOptions;30import io.appium.java_client.touch.WaitOptions;31import io.appium.java_client.touch.offset.ElementOption;32import io.appium.java_client.touch.offset.PointOption;33public class AppiumTest4 {34 public static void main(String[] args) throws MalformedURLException, InterruptedException {35 // TODO Auto-generated method stub36 AppiumDriverLocalService service = AppiumDriverLocalService.buildService(new AppiumServiceBuilder()37 38 .usingDriverExecutable(new File("C:\\Program Files\\nodejs\\node.exe"))39 .withAppiumJS(new File("C:\\Users\\Sanjay\\AppData\\Local\\Programs\\Appium\\resources\\app\\node_modules\\appium\\build\\lib\\main.js"))40 .withLogFile(new File("C:\\Users\\Sanjay\\Appium\\eclipse-workspace\\AppiumTest1\\src\\test\\resources\\Logs\\AppiumLogs\\Logs.log"))41 .withArgument(GeneralServerFlag.LOCAL_TIMEZONE));42 43 service.start(); 44 45 DesiredCapabilities dc = new DesiredCapabilities();46 dc.setCapability("deviceName", "65f651f31e00");47 dc.setCapability("platformName", "Android");48 dc.setCapability("automationName", "uiAutomator2");49 dc.setCapability("appPackage","in.amazon.mShop.android.shopping");50 dc.setCapability("appActivity","com.amazon.mShop.home.HomeActivity");51 52 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"),dc);53 driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);54 Thread.sleep(6000);55 driver.findElement(By.xpath("//android.widget.ImageView[@content-desc=\"Continue in English\"]")).click();56 driver.findElement(By.id("in.amazon.mShop.android.shopping:id/skip_sign_in_button")).click();57 58 Thread.sleep(2000);59 60 61 62 63 64 driver.findElement(MobileBy.AndroidUIAutomator(65 "new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().textContains(\"Deals of the Day\"))"));66 67 68 Wait<AndroidDriver> wait= new FluentWait(driver)69 .pollingEvery(Duration.ofMillis(300))70 .withTimeout(Duration.ofSeconds(10))71 .ignoring(NoSuchElementException.class)72 .ignoring(TimeoutException.class);73 74 MobileElement dealOftheDayELement= wait.until(new Function<AndroidDriver,MobileElement>(){75 @Override76 public MobileElement apply(AndroidDriver t) {77 // TODO Auto-generated method stub78 MobileElement element = driverfindElement(MobileBy.AndroidUIAutomator("new UiSelector().textContains(\"iQOO Z3 Series | India s first SD 768G 5G ₹ 19,990.00 - ₹ 22,990.00\")"));79 System.out.println(element.getAttribute("content-desc"));80 if(element.getAttribute("content-desc").equals("iQOO Z3 Series | India s first SD 768G 5G ₹ 19,990.00 - ₹ 22,990.00"))81 return element;82 else 83 return null;84 }85 private MobileElement driverfindElement(By androidUIAutomator) {86 // TODO Auto-generated method stub87 return null;88 }89 90 });91 92 93 TouchAction actions = new TouchAction(driver);94 actions.press(ElementOption.element(dealOftheDayELement)).release().perform();95 96 97 //driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()).flingForward()"));98 99 Thread.sleep(6000);100 101 102 //scrollDown(driver); 103 //scrollUp(driver); 104 105 driver.quit();106 service.stop();107 108 }109 110 111 public static void scrollDown(AndroidDriver<AndroidElement> driver)112 {113 114 Dimension size = driver.manage().window().getSize();115 int center_x = (int) (size.width*0.5);116 int bottom_y = (int) (size.height*0.8);117 118 int top_y=(int) (size.height*0.2);119 120 121 for(int i=1;i<=10;i++) {122 123 AndroidTouchAction action = new AndroidTouchAction(driver);124 action.press(PointOption.point(center_x, bottom_y)).moveTo(PointOption.point(center_x, top_y)).release().perform();125 126 } 127 }128 129 130 public static void scrollUp(AndroidDriver<AndroidElement> driver)131 {132 Dimension size = driver.manage().window().getSize();133 int center= size.width/2;134 int top = 20;135 int bottom = size.height-10;136 for(int i=1;i<=10;i++) {137 138 AndroidTouchAction action = new AndroidTouchAction(driver);139 action.press(PointOption.point(center, top)).moveTo(PointOption.point(center, bottom)).release().perform();140 141 }142 }143 144}...

Full Screen

Full Screen

ThirdTest.java

Source:ThirdTest.java Github

copy

Full Screen

...12import org.testng.annotations.Test;13import io.appium.java_client.TouchAction;14import io.appium.java_client.android.AndroidDriver;15import io.appium.java_client.android.AndroidElement;16import io.appium.java_client.android.AndroidTouchAction;17import io.appium.java_client.touch.WaitOptions;18import io.appium.java_client.touch.offset.PointOption;19public class ThirdTest {20 static AndroidDriver<AndroidElement> driver;21 @Test22 public void mySecondTest() throws InterruptedException, MalformedURLException {23 DesiredCapabilities caps = new DesiredCapabilities();24 // Set your access credentials25 caps.setCapability("browserstack.user", "sathishkumar93");26 caps.setCapability("browserstack.key", "s14LDSWxcnzPK3LqoHzs");27 // Set URL of the application under test28 29 caps.setCapability("app", "bs://c282c3e0c822c7bc2fbea4f890790cb9610410d5");30 // Specify device and os_version for testing31 caps.setCapability("device", "Google Pixel 3");32 caps.setCapability("os_version", "9.0");33 // Set other BrowserStack capabilities34 caps.setCapability("project", "First Java Project");35 caps.setCapability("build", "Java Android");36 caps.setCapability("name", "Drag_Drop_Test");37 // Initialise the remote Webdriver using BrowserStack remote URL38 // and desired capabilities defined above39 //AppiumDriver<MobileElement> mdriver = new IOSDriver<MobileElement>(new URL("http://hub.browserstack.com/wd/hub"), caps);40 AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(41 new URL("http://hub.browserstack.com/wd/hub"), caps);42// AndroidElement animationelemt = driver.findElementByXPath("//android.widget.TextView[@content-desc=\"Animation\"]");43// tapAnElement(driver,animationelemt);44 driver.findElement(By.xpath("//android.widget.TextView[@content-desc=\"Views\"]")).click();45// driver.findElement(By.xpath("//android.widget.TextView[@content-desc=\"Drag and Drop\"]")).click();46// AndroidElement source =driver.findElement(By.id("io.appium.android.apis:id/drag_dot_1"));47// AndroidElement destine =driver.findElement(By.id("io.appium.android.apis:id/drag_dot_2"));48// DragAndDrop(driver, source, destine);49 50 ScrollAndClick(driver, "Radio Group");51 driver.findElement(By.xpath("//*[@content-desc=\"Radio Group\"]")).click();52 53 Thread.sleep(20000);54 driver.quit();55 }56 public void tapAnElement(AndroidDriver<AndroidElement> driver, AndroidElement elementparam) {57 TouchAction ta = new AndroidTouchAction(driver);58 ta.tap(tapOptions().withElement(element(elementparam))).perform();59 60 }61 62 public void SwipeAnElement(AndroidDriver driver, AndroidElement start, AndroidElement end) {63 TouchAction ta = new AndroidTouchAction(driver);64 ta.longPress(longPressOptions().withElement(element(start)).withDuration(Duration.ofSeconds(5))).moveTo(element(end)).release().perform();65 66 }67 public void tapOnCoordinates(AndroidDriver driver, int x, int y) {68 TouchAction ta = new AndroidTouchAction(driver);69 ta.tap(point(x, y)).perform();70 }71 public void longPress(AndroidDriver driver, AndroidElement elementparam) {72 TouchAction ta = new AndroidTouchAction(driver);73 ta.longPress(longPressOptions().withElement(element(elementparam)).withDuration(Duration.ofSeconds(5))).perform();74 }75 public void DragAndDrop(AndroidDriver driver, AndroidElement source, AndroidElement destine) {76 TouchAction ta = new AndroidTouchAction(driver);77 ta.longPress(longPressOptions().withElement(element(source))).moveTo(element(destine)).release().perform();78 }79 public void ScrollAndClick(AndroidDriver driver, String textvalue) {80 driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\""+textvalue+"\").instance(0))");81 }82 public void ScrollFindTheMobileElementAndClick(By by) {83 while(driver.findElements(by).size()==0) 84 {85 Dimension dimensions = driver.manage().window().getSize();86 Double screenHeightStart = dimensions.getHeight() * 0.5;87 int scrollStart = screenHeightStart.intValue();88 Double screenHeightEnd = dimensions.getHeight() * 0.2;89 int scrollEnd = screenHeightEnd.intValue();90 int center = (int)(dimensions.width*0.5);91 TouchAction ta = new AndroidTouchAction(driver);92 ta.press(PointOption.point(center, scrollStart)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).moveTo(PointOption.point(center, scrollEnd)).release().perform();93 }94 }95}...

Full Screen

Full Screen

MobileGesturesTest.java

Source:MobileGesturesTest.java Github

copy

Full Screen

1package com.training;2import io.appium.java_client.android.AndroidDriver;3import io.appium.java_client.android.AndroidElement;4import io.appium.java_client.android.AndroidTouchAction;5import io.appium.java_client.touch.LongPressOptions;6import io.appium.java_client.touch.TapOptions;7import io.appium.java_client.touch.WaitOptions;8import io.appium.java_client.touch.offset.ElementOption;9import io.appium.java_client.touch.offset.PointOption;10import org.openqa.selenium.remote.DesiredCapabilities;11import java.net.MalformedURLException;12import java.net.URL;13import java.time.Duration;14public class MobileGesturesTest {15 //Mobile Gesture --> tap,tap using coordinates, double tap ,long press, swipe, drag ana drop16 //Extent reports17 //Screenshot18 //recording of our local tests19 public static void main(String[] args) throws MalformedURLException {20 DesiredCapabilities capabilities = new DesiredCapabilities();21 capabilities.setCapability("app", "bs://b38557fcfe3048b6b46e26dc35ddb4f3c870832f");22 capabilities.setCapability("browserstack.user","amuthansakthivel1");23 capabilities.setCapability("browserstack.key","xET1z5tchDwDZ4Anwepa");24 capabilities.setCapability("device","Google Pixel 3");//lot of devices25 capabilities.setCapability("os_version","9.0"); //lot of version26 capabilities.setCapability("project", "First Java Project"); //to distinguish project27 capabilities.setCapability("build", "Java Android"); //to diff release28 capabilities.setCapability("name", "myFirstBSTest"); //to diff tests29 capabilities.setCapability("appPackage","io.appium.android.apis");30 capabilities.setCapability("appActivity",".ApiDemos");31 AndroidDriver<AndroidElement> driver =32 new AndroidDriver<AndroidElement>(new URL("http://hub.browserstack.com/wd/hub"),capabilities);33 //click on Views34 //1. tap on views35 AndroidElement views = driver.findElementByAccessibilityId("Views");36 views.click();37 driver.findElementByAccessibilityId("Drag and Drop").click();38 AndroidElement source = driver.findElementById("io.appium.android.apis:id/drag_dot_1");39 AndroidElement target = driver.findElementById("io.appium.android.apis:id/drag_dot_2");40 dragAndDrop(driver,source,target);41 System.out.println(driver.findElementById("io.appium.android.apis:id/drag_result_text").getText());42 driver.quit(); //to call driver.quit even when there is a failure in the test43 }44 private static void dragAndDrop(AndroidDriver<AndroidElement> driver, AndroidElement source, AndroidElement target) {45 AndroidTouchAction ta = new AndroidTouchAction(driver);46 ta.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(source))).47 waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).48 moveTo(ElementOption.element(target)).release().perform();49 }50 private static void swipe(AndroidDriver<AndroidElement> driver, AndroidElement source, AndroidElement target) {51 AndroidTouchAction ta = new AndroidTouchAction(driver);52 ta.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(source))).53 moveTo(ElementOption.element(target)).release().perform();54 }55 private static void click(AndroidElement element) {56 element.click();57 }58 private static void tapUsingCoordinates(AndroidDriver<AndroidElement> driver, int x, int y) {59 AndroidTouchAction ta = new AndroidTouchAction(driver);60 ta.tap(PointOption.point(x,y)).perform();61 }62 private static void tapOnElement(AndroidDriver<AndroidElement> driver, AndroidElement element) {63 AndroidTouchAction ta = new AndroidTouchAction(driver);64 ta.tap(TapOptions.tapOptions().withElement(ElementOption.element(element))).perform();65 }66 /*67 tapUsingCoordinates(driver,490,1080);68 click(driver.findElementByAccessibilityId("2. Inline"));//failure69 click(driver.findElementByAccessibilityId("3"));70 AndroidElement source = driver.findElementByAccessibilityId("15");71 AndroidElement target = driver.findElementByAccessibilityId("45");72 swipe(driver,source,target);73 System.out.println(driver.findElementById("android:id/minutes").getText());74 */75}...

Full Screen

Full Screen

BaseAction.java

Source:BaseAction.java Github

copy

Full Screen

...12import io.appium.java_client.MultiTouchAction;13import io.appium.java_client.TouchAction;14import io.appium.java_client.android.AndroidDriver;15import io.appium.java_client.android.AndroidElement;16import io.appium.java_client.android.AndroidTouchAction;17import io.appium.java_client.touch.LongPressOptions;18import io.appium.java_client.touch.WaitOptions;19import io.appium.java_client.touch.offset.ElementOption;20import io.appium.java_client.touch.offset.PointOption;2122public class BaseAction {23 public AndroidDriver<AndroidElement> driver;24 public AndroidTouchAction action;2526 public BaseAction(AndroidDriver<AndroidElement> driver) {27 this.driver = driver;28 action = new AndroidTouchAction(driver);2930 }3132 /**33 * @param by34 */35 public void click(By by) {36 driver.findElement(by).click();37 }3839 public void click(WebElement elemnet) {40 elemnet.click();41 }4243 /**44 * 输入45 * 46 * @param by47 * @param value48 */49 public void type(By by, String value) {50 driver.findElement(by).clear();51 driver.findElement(by).sendKeys(value);5253 }5455 public void type(WebElement element, String context) {56 element.clear();57 element.sendKeys(context);58 }5960 /**61 * 长按62 * 63 * @param element64 */65 public void longPress(WebElement element) {66 LongPressOptions longPressOptions = LongPressOptions.longPressOptions();67 longPressOptions.withElement(ElementOption.element(element));68 action.longPress(longPressOptions).release().perform();69 }7071 /**72 * 坐标点的滑动73 * 74 * @param fromOption75 * @param toOption76 */77 public void slide(PointOption fromOption, PointOption toOption) {78 action.press(fromOption).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).moveTo(toOption)79 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).release().perform();80 }8182 /**83 * 元素间的滑动84 * 85 * @param fromEle86 * @param toEle87 */88 public void slide(WebElement fromEle, WebElement toEle) {8990 slide(ElementOption.element(fromEle), ElementOption.element(toEle));91 }9293 /**94 * 长按拖动95 * 96 * @param element97 */98 public void dragAndSlide(AndroidElement element) {99100 LongPressOptions longPressOptions = LongPressOptions.longPressOptions();101 longPressOptions.withElement(ElementOption.element(element));102103 action.longPress(longPressOptions).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))104 .moveTo(PointOption.point(100, element.getLocation().getY()))105 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1))).release().perform();106 }107/**108 * 多点触控功能实现109 * @param x1110 * @param y1111 * @param x2112 * @param y2113 * @param x3114 * @param y3115 */116 public void multiTouch(int x1, int y1, int x2, int y2, int x3, int y3) {117 MultiTouchAction multiAction = new MultiTouchAction(driver);118 AndroidTouchAction action1 = new AndroidTouchAction(driver);119 AndroidTouchAction action2 = new AndroidTouchAction(driver);120 AndroidTouchAction action3 = new AndroidTouchAction(driver);121 AndroidTouchAction action4 = new AndroidTouchAction(driver);122 AndroidTouchAction action5 = new AndroidTouchAction(driver);123124 action1.longPress(PointOption.point(x1, y1)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))125 .release();126 action2.longPress(PointOption.point(x2, y2)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))127 .release();128 action3.longPress(PointOption.point(x3, y3)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))129 .release();130131 multiAction.add(action1).add(action2).add(action3).add(action4).add(action5).perform();132 }133/**134 * 返回Toast的文本信息135 */136 public String getToast() { ...

Full Screen

Full Screen

GestureOperation.java

Source:GestureOperation.java Github

copy

Full Screen

1package com.wut.service.impl;2import com.wut.page.*;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidElement;5import io.appium.java_client.android.AndroidTouchAction;6import io.appium.java_client.functions.ActionSupplier;7import io.appium.java_client.functions.AppiumFunction;8import io.appium.java_client.touch.offset.PointOption;9import org.apache.commons.logging.Log;10import org.apache.commons.logging.LogFactory;11import org.openqa.selenium.Point;12import org.springframework.beans.factory.annotation.Autowired;13import org.springframework.stereotype.Service;14import static io.appium.java_client.touch.TapOptions.tapOptions;15import static io.appium.java_client.touch.offset.ElementOption.element;16import static io.appium.java_client.touch.WaitOptions.waitOptions;17import static java.time.Duration.ofSeconds;18/**19 * Package_Name: com.wut.service20 * Description: 手势操作lambda定义,同时也是所以service实现类的父类21 *22 * @author yangzheng23 * Date: 2020/08/0924 */25@Service26public abstract class GestureOperation {27 /**28 * Logger available to subclasses.29 */30 final Log logger = LogFactory.getLog(getClass());31 AndroidDriver<AndroidElement> driver;32 private AndroidTouchAction action;33 @Autowired34 LearningIndexPage learningIndexPage;35 @Autowired36 ContentDetailsPage contentDetailsPage;37 @Autowired38 SubscribePage subscribePage;39 @Autowired40 MyTotalPage myTotalPage;41 @Autowired42 MySubscribePage mySubscribePage;43 // 屏幕宽度44 private int width;45 // 屏幕高度46 private int height;47 public GestureOperation(AndroidDriver<AndroidElement> driver) {48 this.driver = driver;49 action = new AndroidTouchAction(driver);50 width = driver.manage().window().getSize().getWidth();51 height = driver.manage().window().getSize().getHeight();52 }53 // 点击元素54 // @param element 被点击的元素55 AppiumFunction<AndroidElement, AndroidTouchAction> tapElement = (element) ->56 action.tap(tapOptions().withElement(element(element)));57 // 点击坐标58 // @param point 坐标点 对象59 AppiumFunction<Point, AndroidTouchAction> tapCoordinate = (point) ->60 action.tap(PointOption.point(point));61 // 等待时间62 AppiumFunction<Long, AndroidTouchAction> waitForTime = (millis) ->63 action.waitAction(waitOptions(ofSeconds(millis)));64 // 下拉刷新65 ActionSupplier<AndroidTouchAction> dropDownRefresh = () ->66 action.press(PointOption.point(width / 2, height / 3))67 .waitAction(waitOptions(ofSeconds(1)))68 .moveTo(PointOption.point(width / 2, height / 2))69 .release();70 // 上拉加载71 ActionSupplier<AndroidTouchAction> pullUpLoading = () ->72 action73 .press(PointOption.point(width / 2, height / 10 * 9))74 .waitAction(waitOptions(ofSeconds(3)))75 .moveTo(PointOption.point(width / 2, height / 10))76 .release();77 // 横向左滑动一级导航栏78 ActionSupplier<AndroidTouchAction> horizontalSwipeLeft = () ->79 action80 .press(PointOption.point(1100, 400))81 .waitAction(waitOptions(ofSeconds(1)))82 .moveTo(PointOption.point(100, 400))83 .release();84}...

Full Screen

Full Screen

Actions.java

Source:Actions.java Github

copy

Full Screen

2import org.openqa.selenium.Point;3import org.openqa.selenium.WebElement;4import io.appium.java_client.TouchAction;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.android.AndroidTouchAction;7import io.appium.java_client.touch.offset.PointOption;8import static io.appium.java_client.touch.LongPressOptions.longPressOptions;9import static io.appium.java_client.touch.WaitOptions.waitOptions;10import static io.appium.java_client.touch.offset.ElementOption.element;11import static io.appium.java_client.touch.offset.PointOption.point;12import static java.time.Duration.ofSeconds;13public class Actions {14 AndroidDriver driver;15// AndroidTouchAction aca;16// TouchAction dragDrop;17 public Actions(AndroidDriver driver){18 this.driver = driver;19 }20 //单个元素的输入21 public void type(WebElement element,String Context){22 element.sendKeys(Context);23 }24 //点击25 public void click(WebElement element){26 element.click();27 }28 //长按29 public void longPress(WebElement ele){30// this.dragDrop.longPress(element(ele)).perform();31 WebElement node = driver.findElementById("com.example.todolist:id/toDoItemDetailTv");32 TouchAction LongPress = new TouchAction(driver);33 LongPress.longPress(element(node)).perform();34 }35 //坐标点间的滑动36 public void swip(PointOption fromOption, PointOption toOption, int time){37 AndroidTouchAction aca = new AndroidTouchAction(driver);38 aca.press(fromOption).waitAction(waitOptions(ofSeconds(time))).moveTo(toOption).perform();39 }40 //元素间的滑动41 public void swip(WebElement formEle,WebElement toEle,long time){42 AndroidTouchAction aca = new AndroidTouchAction(driver);43 aca.press(element(formEle)).waitAction(waitOptions(ofSeconds(time))).44 moveTo(element(toEle)).perform();45 }46 //元素间拖动47 public void drop(WebElement fromele,WebElement toele){48 AndroidTouchAction aca = new AndroidTouchAction(driver);49 aca.longPress(longPressOptions()50 .withElement(element(fromele))51 .withDuration(ofSeconds(2)))52 .moveTo(element(toele))53 .release()54 .perform();55 }56 //坐标间拖动57 public void drop(Point center1, Point center2) {58 AndroidTouchAction aca = new AndroidTouchAction(driver);59 aca.longPress(longPressOptions()60 .withPosition(point(center1.x, center1.y))61 .withDuration(ofSeconds(2)))62 .moveTo(point(center2.x, center2.y))63 .release()64 .perform();65 }66}...

Full Screen

Full Screen

TestBase.java

Source:TestBase.java Github

copy

Full Screen

1import io.appium.java_client.AppiumDriver;2import io.appium.java_client.MobileElement;3import io.appium.java_client.android.AndroidDriver;4import io.appium.java_client.android.AndroidTouchAction;5import io.appium.java_client.touch.WaitOptions;6import io.appium.java_client.touch.offset.PointOption;7import org.openqa.selenium.Dimension;8import org.openqa.selenium.remote.DesiredCapabilities;9import org.testng.annotations.AfterTest;10import org.testng.annotations.BeforeTest;11import java.net.MalformedURLException;12import java.net.URL;13import java.time.Duration;14public class TestBase {15 AppiumDriver driver;16 public AndroidTouchAction touchAction;17 public void setup() throws MalformedURLException {18 DesiredCapabilities caps = new DesiredCapabilities();19 caps.setCapability("platformName","Android");20 caps.setCapability("platformVersion","9");21 caps.setCapability("deviceName","afcfe42c");22 caps.setCapability("automationName","UiAutomator2");23 caps.setCapability("appActivity","com.swaglabsmobileapp.MainActivity");24 caps.setCapability("appPackage","com.swaglabsmobileapp");25 driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"),caps);26 }27 // Method for scrolling down28 public void scrollDown(AppiumDriver appiumDriver)29 {30 Dimension dimension = appiumDriver.manage().window().getSize();31 int scrollStart = (int)(dimension.getHeight() * 0.8);32 int scrollEnd = (int)(dimension.getHeight() * 0.1);33 touchAction = new AndroidTouchAction(appiumDriver)34 .press(PointOption.point(0,scrollStart))35 .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(5)))36 .moveTo(PointOption.point(0,scrollEnd))37 .release()38 .perform();39 }40 @AfterTest41 public void tearDown()42 {43 if(null !=driver)44 {45 driver.quit();46 }47 }...

Full Screen

Full Screen

DragAndDrop.java

Source:DragAndDrop.java Github

copy

Full Screen

...6import org.testng.annotations.Test;78import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.android.AndroidElement;10import io.appium.java_client.android.AndroidTouchAction;11import io.appium.java_client.touch.LongPressOptions;12import io.appium.java_client.touch.offset.ElementOption;1314public class DragAndDrop extends Demo1{1516 public static AndroidDriver<AndroidElement> driver;17 18 @Test19 public void dragAndDrop() throws IOException {20 // TODO Auto-generated method stub21 driver = capanilities();22 driver.findElementByXPath("//android.widget.TextView[@text='Views']").click();23 driver.findElementByXPath("//android.widget.TextView[@text='Drag and Drop']").click();24 AndroidElement source = driver.findElementsByClassName("android.view.View").get(0);25 AndroidElement destination = driver.findElementsByClassName("android.view.View").get(1);26 27 AndroidTouchAction ata = new AndroidTouchAction(driver);28 ata.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(source))).moveTo(ElementOption.element(destination)).release().perform();29 30 }3132} ...

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touch = new AndroidTouchAction(driver);2touch.tap(100, 100).perform();3AndroidTouchAction touch = new AndroidTouchAction(driver);4touch.tap(100, 100).perform();5AndroidTouchAction touch = new AndroidTouchAction(driver);6touch.tap(100, 100).perform();7AndroidTouchAction touch = new AndroidTouchAction(driver);8touch.tap(100, 100).perform();9AndroidTouchAction touch = new AndroidTouchAction(driver);10touch.tap(100, 100).perform();11AndroidTouchAction touch = new AndroidTouchAction(driver);12touch.tap(100, 100).perform();13AndroidTouchAction touch = new AndroidTouchAction(driver);14touch.tap(100, 100).perform();15AndroidTouchAction touch = new AndroidTouchAction(driver);16touch.tap(100, 100).perform();17AndroidTouchAction touch = new AndroidTouchAction(driver);18touch.tap(100, 100).perform();19AndroidTouchAction touch = new AndroidTouchAction(driver);20touch.tap(100, 100).perform();21AndroidTouchAction touch = new AndroidTouchAction(driver);22touch.tap(100, 100).perform();

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touch = new AndroidTouchAction(driver);2touch.press(100, 100).moveTo(200, 200).release().perform();3TouchAction touch = new TouchAction(driver);4touch.press(100, 100).moveTo(200, 200).release().perform();5touch = TouchAction(driver)6touch.press(x=100, y=100).move_to(x=200, y=200).release().perform()7touch.press(x: 100, y: 100).move_to(x: 200, y: 200).release.perform8touch = new appium.TouchAction(driver);9touch.press({x: 100, y: 100}).moveTo({x: 200, y: 200}).release().perform();10TouchAction touch = new TouchAction(driver);11touch.Press(100, 100).MoveTo(200, 200).Release().Perform();12$touch = new TouchAction($driver);13$touch->press(['x' => 100, 'y' => 100])->moveTo(['x' => 200, 'y' => 200])->release()->perform();14touch = new appium.TouchAction(driver)15touch.press(x: 100, y: 100).moveTo(x: 200, y: 200).release().perform()16touch = new_appium_TouchAction(driver);17touch_press(touch, 100, 100);18touch_move_to(touch, 200, 200);19touch_release(touch);20touch_perform(touch);

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction action = new AndroidTouchAction(driver);2action.tap(100, 200, 1).perform();3TouchAction action = new TouchAction(driver);4action.tap(100, 200).perform();5touch_action.tap(x: 100, y: 200).perform6var action = new appium.TouchAction(driver);7action.tap({x: 100, y: 200}).perform();8var action = new webdriver.TouchAction(driver);9action.tap({x: 100, y: 200}).perform();10var action = new wd.TouchAction(driver);11action.tap({x: 100, y: 200}).perform();12var action = new protractor.TouchAction(driver);13action.tap({x: 100, y: 200}).perform();14var action = new wdio.TouchAction(driver);15action.tap({x: 100, y: 200}).perform();16action = TouchAction(driver)17action.tap(x=100, y=200).perform()18TouchAction action = new TouchAction(driver);19action.Tap(100, 200).Perform();20AndroidTouchAction action = new AndroidTouchAction(driver);21action.Tap(100, 200).Perform();22IOSTouchAction action = new IOSTouchAction(driver);23action.Tap(100

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touch = new AndroidTouchAction(driver);2touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();3TouchAction touch = new TouchAction(driver);4touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();5TouchAction touch = new TouchAction(driver);6touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();7TouchAction touch = new TouchAction(driver);8touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();9TouchAction touch = new TouchAction(driver);10touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();11TouchAction touch = new TouchAction(driver);12touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();13TouchAction touch = new TouchAction(driver);14touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();15TouchAction touch = new TouchAction(driver);16touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();17TouchAction touch = new TouchAction(driver);18touch.longPress(longPressOptions().withElement(element(longPressElement)).withDuration(ofSeconds(2))).release().perform();

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touchAction = new AndroidTouchAction(driver);2touchAction.longPress(driver.findElement(By.id("element_id"))).release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.longPress(driver.findElement(By.id("element_id"))).release().perform();5LongPressOptions longPressOptions = new LongPressOptions();6longPressOptions.withElement(ElementOption.element(driver.findElement(By.id("element_id"))));7TouchAction touchAction = new TouchAction(driver);8touchAction.longPress(longPressOptions).release().perform();9TouchAction touchAction = new TouchAction(driver);10touchAction.longPress(driver.findElement(By.id("element_id")), 1000).release().perform();11TouchAction touchAction = new TouchAction(driver);12touchAction.longPress(driver.findElement(By.id("element_id")), 1000, 1000).release().perform();13TouchAction touchAction = new TouchAction(driver);14touchAction.longPress(PointOption.point(1000, 1000)).release().perform();15TouchAction touchAction = new TouchAction(driver);16touchAction.longPress(driver.findElement(By.id("element_id")), PointOption.point(1000, 1000)).release().perform();17LongPressOptions longPressOptions = new LongPressOptions();18longPressOptions.withPosition(PointOption.point(1000, 1000));19TouchAction touchAction = new TouchAction(driver);20touchAction.longPress(longPressOptions).release().perform();21TouchAction touchAction = new TouchAction(driver);22touchAction.longPress(PointOption.point(1000, 1000), Duration.ofMillis(

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1import java.net.MalformedURLException;2import java.net.URL;3import java.time.Duration;4import java.util.concurrent.TimeUnit;5import org.openqa.selenium.By;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.remote.DesiredCapabilities;8import io.appium.java_client.android.AndroidDriver;9import io.appium.java_client.android.AndroidTouchAction;10import io.appium.java_client.android.nativekey.AndroidKey;11import io.appium.java_client.android.nativekey.KeyEvent;12import io.appium.java_client.remote.MobileCapabilityType;13import io.appium.java_client.touch.TapOptions;14import io.appium.java_client.touch.WaitOptions;15import io.appium.java_client.touch.offset.ElementOption;16public class Appium {17 public static void main(String[] args) throws MalformedURLException, InterruptedException {18 DesiredCapabilities cap = new DesiredCapabilities();19 cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");20 cap.setCapability("platformName", "Android");21 cap.setCapability("platformVersion", "10.0");22 cap.setCapability("appPackage", "com.android.chrome");23 cap.setCapability("appActivity", "com.google.android.apps.chrome.Main");24 cap.setCapability("noReset", "true");25 cap.setCapability("chromedriverExecutable", "C:\\Users\\Arun\\Downloads\\chromedriver_win32\\chromedriver.exe");

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touchAction = new AndroidTouchAction(driver);2driver.pressKeyCode(AndroidKeyCode.BACK);3driver.press_keycode(AndroidKeyCode.BACK)4driver.press_keycode(AndroidKeyCode::BACK)5Appium::TouchAction.new.press(keycode: AndroidKeyCode::BACK)6driver.pressKeyCode(AndroidKeyCode.BACK)7driver.press_keycode(AndroidKeyCode::BACK)8driver.press_keycode(AndroidKeyCode::BACK)9driver.pressKeyCode(AndroidKeyCode.BACK)10Appium::TouchAction.new.press(keycode: AndroidKeyCode::BACK)11driver.press_keycode(AndroidKeyCode.BACK)12driver.press_keycode(AndroidKeyCode::BACK)13AndroidTouchAction touchAction = new AndroidTouchAction(driver);14driver.pressKeyCode(AndroidKeyCode.BACK);15driver.pressKeyCode(AndroidKeyCode.BACK)16Appium::TouchAction.new.press(keycode: AndroidKeyCode::BACK)17driver.press_keycode(AndroidKeyCode::BACK)

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touch=new AndroidTouchAction(driver);2touch.longPress(100, 100).moveTo(500, 500).release().perform();3AndroidTouchAction touch=new AndroidTouchAction(driver);4touch.longPress(100, 100).moveTo(500, 500).release().perform();5AndroidTouchAction touch=new AndroidTouchAction(driver);6touch.longPress(100, 100).moveTo(500, 500).release().perform();7AndroidTouchAction touch=new AndroidTouchAction(driver);8touch.longPress(100, 100).moveTo(500, 500).release().perform();9AndroidTouchAction touch=new AndroidTouchAction(driver);10touch.longPress(100, 100).moveTo(500, 500).release().perform();11AndroidTouchAction touch=new AndroidTouchAction(driver);12touch.longPress(100, 100).moveTo(500, 500).release().perform();13AndroidTouchAction touch=new AndroidTouchAction(driver);14touch.longPress(100, 100).moveTo(500, 500).release().perform();15AndroidTouchAction touch=new AndroidTouchAction(driver);16touch.longPress(100, 100).moveTo(500, 500).release().perform();17AndroidTouchAction touch=new AndroidTouchAction(driver);18touch.longPress(100, 100).moveTo(500, 500).release().perform();

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touch = new AndroidTouchAction(driver);2touch.tap(100, 200).perform();3touch.tap(100, 200, 2).perform();4touch.tap(100, 200, 1, 500).perform();5touch.tap(100, 200, 2, 500).perform();6touch.longPress(100, 200).release().perform();7touch.longPress(100, 200, 500).release().perform();8touch.longPress(100, 200, 500, 500).release().perform();9touch.longPress(100, 200, 500, 500, 2).release().perform();10touch.longPress(100, 200, 500, 500, 2, 500).release().perform();11touch.longPress(100, 200, 500, 500, 2, 500, 500).release().perform();12touch.longPress(100, 200, 500, 500, 2, 500, 500, 500).release().perform();13touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500).release().perform();14touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500, 2).release().perform();15touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500, 2, 500).release().perform();16touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500, 2, 500, 500).release().perform();17touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500, 2, 500, 500, 500).release().perform();18touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500, 2, 500, 500, 500, 500).release().perform();19touch.longPress(100, 200, 500, 500, 2, 500, 500, 500, 500

Full Screen

Full Screen

AndroidTouchAction

Using AI Code Generation

copy

Full Screen

1AndroidTouchAction touchAction = new AndroidTouchAction(driver);2touchAction.press(200, 200).moveTo(200, 300).release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.press(200, 200).moveTo(200, 300).release().perform();5AndroidTouchAction touchAction = new AndroidTouchAction(driver);6touchAction.press(200, 200).moveTo(200, 300).release().perform();7TouchAction touchAction = new TouchAction(driver);8touchAction.press(200, 200).moveTo(200, 300).release().perform();9AndroidTouchAction touchAction = new AndroidTouchAction(driver);10touchAction.press(200, 200).moveTo(200, 300).release().perform();11TouchAction touchAction = new TouchAction(driver);12touchAction.press(200, 200).moveTo(200, 300).release().perform();13AndroidTouchAction touchAction = new AndroidTouchAction(driver);14touchAction.press(200, 200).moveTo(200, 300).release().perform();15TouchAction touchAction = new TouchAction(driver);16touchAction.press(200, 200).moveTo(200, 300).release().perform();

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful