How to use release method of io.appium.java_client.TouchAction class

Best io.appium code snippet using io.appium.java_client.TouchAction.release

Utilities.java

Source:Utilities.java Github

copy

Full Screen

...43        touchAction.tap(TapOptions.tapOptions().withElement(element(myElement))).perform();44    }45    public void longPressOnElement(AndroidElement myElement){46        TouchAction touchAction=new TouchAction(StepDefinitions.driver);47        touchAction.longPress(longPressOptions().withElement(element(myElement)).withDuration(ofSeconds(2))).release().perform();48    }49    public void doubleTapOnElement(AndroidElement myElement){50        TouchAction touchAction=new TouchAction(StepDefinitions.driver);51        touchAction.tap(TapOptions.tapOptions().withElement(element(myElement))).release().perform().52                tap(TapOptions.tapOptions().withElement(element(myElement))).release().perform();53    }54    public void fnEnterTextValue(WebElement myElement,String myValue){55        myElement.sendKeys(myValue);56    }57    public void DragAndDropElement(AndroidElement fromElement,AndroidElement toElement){58        TouchAction touchAction=new TouchAction(StepDefinitions.driver);59        touchAction.longPress(longPressOptions().withElement(element(fromElement))).60                moveTo(element(toElement)).release().perform();61    }62    public void dragFirstElementToSecondElement(AndroidElement fromElement, AndroidElement toElement) {63        TouchAction touchAction=new TouchAction(StepDefinitions.driver);64        touchAction.longPress(LongPressOptions.longPressOptions().withElement(element(fromElement)))65                .moveTo(element(toElement)).release().perform();66    }67    public void userLaunchesChromeBrowserInMobile() throws MalformedURLException {68        DesiredCapabilities capabilities=new DesiredCapabilities();69        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME,"Galaxy S9+")  ;70        capabilities.setCapability(MobileCapabilityType.UDID,"42345a3836313098");71        capabilities.setCapability(MobileCapabilityType.BROWSER_NAME,"Chrome");72        capabilities.setCapability("appium:chromeOptions", ImmutableMap.of("w3c", false));73        AndroidDriver<AndroidElement> driver=new AndroidDriver<>(new URL("http://0.0.0.0:4723/wd/hub"),capabilities);74//        driver=new AndroidDriver<>(new URL("http://0.0.0.0:4723/wd/hub"),capabilities);75        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);76        driver.get("http://www.timesofindia.com");77    }78    public void userSelectsFromDropdown(String arg0) {79        AndroidElement myelement=StepDefinitions.driver.findElementById("com.androidsample.generalstore:id/spinnerCountry");80        tapOnElement(myelement);81    }82    public void scrollTillAnElementWithTextIsDisplayed(String arg0) {83     AndroidElement expectedElement = null;84     Dimension size=StepDefinitions.driver.manage().window().getSize();85        //x position set to mid-screen horizontally86        int width = size.width / 2;87        //Starting y location set to 80% of the height (near bottom)88        int startPoint = (int) (size.getHeight() * 0.80);89        //Ending y location set to 20% of the height (near top)90        int endPoint = (int) (size.getHeight() * 0.30);91     TouchAction touchAction=new TouchAction(StepDefinitions.driver);92         do {93             try{94                 expectedElement=StepDefinitions.driver.findElementByXPath("//*[@text='"+arg0+"']");95                if(expectedElement.isDisplayed()){96                    tapOnElement(expectedElement);97                    break;98                }99             }catch(Exception e){100                 touchAction.press(PointOption.point(width,startPoint)).101                         waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2))).102                         moveTo(PointOption.point(width,endPoint)).103                         release().104                         perform();105                 continue;106             }107         }while (true);108    }109    public void switchNativeToWeb() throws InterruptedException {110        Thread.sleep(10000);111        Set<String> contextNames = StepDefinitions.driver.getContextHandles();112        for (String contextName : contextNames) {113            System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1114        }115        StepDefinitions.driver.context((String) contextNames.toArray()[1]);116//        StepDefinitions.driver.context("NATIVE_APP");117    }118    public void switchWebToNative() {119        StepDefinitions.driver.context("NATIVE_APP");120    }121    public void tapOnElementUpdate(MobileElement myelement) {122    }123    public void tapOnIOSElement(WebElement activity_indicators) throws InterruptedException {124        Thread.sleep(2000);125        TouchAction touchAction=new TouchAction(StepDefinitions.IOSDriver);126        touchAction.tap(TapOptions.tapOptions().withElement(ElementOption.element(activity_indicators))).release().perform();127    }128    public void LoadProperiesFile() throws IOException {129        FileInputStream fis=new FileInputStream("config.properties");130        Utilities.properties=new Properties();131        Utilities.properties.load(fis);132        Utilities.properties.getProperty("iOSAppPath");133        System.out.println("IOSFile Path is :-"+Utilities.properties.getProperty("iOSAppPath"));134    }135    public void enterTextInIOSEditBox(IOSElement elementByXPath, String sample) {136        elementByXPath.sendKeys(sample);137        StepDefinitions.IOSDriver.hideKeyboard();138    }139    public void fnVerifyExpectedLabelFromIOSElement(IOSElement iOSElement,String sExpectedValue){140        String sActualValue=iOSElement.getAttribute("label");...

Full Screen

Full Screen

ChromeTest.java

Source:ChromeTest.java Github

copy

Full Screen

...147	  //press using element148	  TouchAction ac3 = new TouchAction(driver);149	  ac3.press(element(ele))150	  	 .waitAction(waitOptions(Duration.ofSeconds(2)))151	  	 .release()152	  	 .perform();153	  Thread.sleep(1000);154	  155	  //press using coordinates156	  TouchAction ac4 = new TouchAction(driver);157	  ac4.press(point(500, 700))158	    .waitAction(waitOptions(Duration.ofSeconds(2)))159	     .release()160	    .perform();161	  162	  //Swipe vertically163	  TouchAction ac5 = new TouchAction(driver);164	  ac5.press(point(540, 800))165	     .waitAction(waitOptions(ofMillis(1000)))166	     .moveTo(point(540, 400))167	     .release()168	     .perform();169	  Thread.sleep(10000);170	  171	  //Multi touch172	  TouchAction ac6 = new TouchAction(driver);173	  ac6.press(point(500, 700))174	    .waitAction(waitOptions(ofMillis(1000)))175	    .release()176	    .perform();177	  178	  new MultiTouchAction(driver)179	  	.add(ac6)180	  	.perform();181	  182	  //Long press183	  TouchAction action = new TouchAction(driver);184	  action.longPress(longPressOptions().withElement(element(ele)))185	  		.waitAction(waitOptions(ofMillis(1000)))186	  		.release()187	  		.perform();188	  189  }190  191}...

Full Screen

Full Screen

AppiumUtils.java

Source:AppiumUtils.java Github

copy

Full Screen

...26        int width = driver.manage().window().getSize().width;27        int height = driver.manage().window().getSize().height;28        TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);29        PointOption pointOption = PointOption.point(width / 2, height * 3 / 4);30        touchAction.press(pointOption).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).moveTo(PointOption.point(width / 2, height / 4)).release().perform();31    }32    /**33     * @param driver34     * @module 下滑操作35     */36    public static void swipeDown(WebDriver driver) {37        int width = driver.manage().window().getSize().width;38        int height = driver.manage().window().getSize().height;39        TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);40        PointOption pointOption = PointOption.point(width / 2, height / 4);41        touchAction.press(pointOption).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).moveTo(PointOption.point(width / 2, height * 3 / 4)).release().perform();42    }43    /**44     * @param driver45     * @module 左滑操作46     */47    public static void swipeLeft(WebDriver driver) {48        int width = driver.manage().window().getSize().width;49        int height = driver.manage().window().getSize().height;50        TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);51        PointOption pointOption = PointOption.point(width * 4 / 5, height / 2);52        touchAction.press(pointOption).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).moveTo(PointOption.point(width / 5, height / 2)).release().perform();53    }54    /**55     * @param driver56     * @module 右滑操作57     */58    public static void swipeRight(WebDriver driver) {59        int width = driver.manage().window().getSize().width;60        int height = driver.manage().window().getSize().height;61        TouchAction touchAction = new TouchAction((PerformsTouchActions) driver);62        PointOption pointOption = PointOption.point(width / 5, height / 4);63        touchAction.press(pointOption).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))).moveTo(PointOption.point(width * 4 / 5, height / 2)).release().perform();64    }65    /**66     * 执行测试前,检查各设备电量情况,电量不足发出警告67     * @param driver68     * @return 电量状态是否允许可继续执行69     */70    public static Double checkBattery(AndroidDriver driver) {71        String message = "";72        double batteryLevel = driver.getBatteryInfo().getLevel();73        String batteryState = driver.getBatteryInfo().getState().name();74        return batteryLevel;75    }76    /**77     * 执行测试前,检查网络状态...

Full Screen

Full Screen

ApolloUtils.java

Source:ApolloUtils.java Github

copy

Full Screen

...20		int scrollEnd = endHeight.intValue();2122		TouchAction action = new TouchAction(driver);23		action.press(PointOption.point(0, scrollStart)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))24				.moveTo(PointOption.point(0, scrollEnd)).release().perform();25	}2627	public static void verticalScrollMenu(AppiumDriver<WebElement> driver) {28		Dimension dimension = driver.manage().window().getSize();29		Double startHeight = dimension.getHeight() * 0.5;30		int scrollStart = startHeight.intValue();3132		Double endHeight = dimension.getHeight() * 0.2;33		int scrollEnd = endHeight.intValue();3435		Double width=dimension.width*0.75;36		int widthE=width.intValue();37		38		TouchAction action = new TouchAction(driver);39		action.press(PointOption.point(widthE, scrollStart)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))40				.moveTo(PointOption.point(widthE, scrollEnd)).release().perform();41	}42//this method works on scrollup(means scroll downwards to upwards)	43	public static void verticalScrollup(AppiumDriver<WebElement> driver) {44		Dimension dimension = driver.manage().window().getSize();45		Double startHeight = dimension.getHeight() * 0.3;46		int scrollStart = startHeight.intValue();4748		Double endHeight = (dimension.getHeight() * 0.9) - startHeight;49		int scrollEnd = endHeight.intValue();50		System.out.println("scrollStart:" + scrollStart);51		System.out.println("endHeight:" + endHeight);52		TouchAction action = new TouchAction(driver);53		action.press(PointOption.point(0, scrollStart)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))54				.moveTo(PointOption.point(0, scrollEnd)).release().perform();55	}56	57	@SuppressWarnings("hiding")58	public class ApolloUtilswidth<ScrollAmount> {59		public void verticalScrollwidth(AppiumDriver<WebElement> driver) {60			Dimension dimension = driver.manage().window().getSize();61			Double startwidth = dimension.getWidth() * 0.5;62			int scrollStart = startwidth.intValue();6364			Double endwidth = dimension.getWidth() * 0.2;65			int scrollEnd = endwidth.intValue();6667			TouchAction action = new TouchAction(driver);68			action.press(PointOption.point(0, scrollStart)).waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))69					.moveTo(PointOption.point(0, scrollEnd)).release().perform();70		}71	}72}
...

Full Screen

Full Screen

GestureSwipe.java

Source:GestureSwipe.java Github

copy

Full Screen

...18        TouchAction t = new TouchAction(driver);19        t.press(ElementOption.element(driver.findElement(steppers)))20                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))21                .moveTo(ElementOption.element(driver.findElement(activityIndicators)))22                .release()23                .perform();24        //Android25       /* By views = MobileBy.AccessibilityId("Views");26        By grid = MobileBy.AccessibilityId("Grid");27        By animation = MobileBy.AccessibilityId("Animation");28        driver.findElement(views).click();29        Dimension size = driver.manage().window().getSize();30        int startX = size.width/2;31        int endX = startX;32        int startY = (int)(size.height*0.8);33        int endY = (int)(size.height*0.2);34        for (int i=0;i<3;i++)35        {36            TouchAction t = new TouchAction(driver);37            t.press(PointOption.point(startX, startY))38                    .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))39                    .moveTo(PointOption.point(endX, endY))40                    .release()41                    .perform();42        }43            TouchAction t = new TouchAction(driver);44            t.press(ElementOption.element(driver.findElement(grid)))45                    .waitAction(WaitOptions.waitOptions(Duration.ofMillis(2000)))46                    .moveTo(ElementOption.element(driver.findElement(animation)))47                    .release()48                    .perform();*/49    }50}...

Full Screen

Full Screen

commonbase.java

Source:commonbase.java Github

copy

Full Screen

...22	}23	// tap functionality24	public void tap(MobileElement Element) {25		TouchAction touch = new TouchAction(ad);26		touch.tap(tapOptions().withElement(element(Element))).release().perform();27	}28	29public static void verticalSwipeByElement(MobileElement englishMedium, MobileElement fresherExp) {30		31		int startX = englishMedium.getLocation().getX() + (englishMedium.getSize().getWidth() / 2);32		int startY = englishMedium.getLocation().getY() + (englishMedium.getSize().getHeight() / 2);33		int endX = fresherExp.getLocation().getX() + (fresherExp.getSize().getWidth() / 2);34		int endY = fresherExp.getLocation().getY() + (fresherExp.getSize().getHeight() / 2);35		36		new TouchAction(ad).press(point(startX, startY)).waitAction(waitOptions(ofMillis(1000)))37				.moveTo(point(endX, endY)).release().perform();38	}39	// vertical swipe functionality40	public void vericalSwipeByPercentage(double startPercentage, double endPercentage, double anchorPercentage) {41		Dimension size = ad.manage().window().getSize();42		int anchor = (int) (size.width * anchorPercentage);43		int startPoint = (int) (size.height * startPercentage);44		int endPoint = (int) (size.width * endPercentage);45		new TouchAction(ad).press(point(anchor, startPoint)).waitAction(waitOptions(ofMillis(1000)))46				.moveTo(point(anchor, endPoint)).release().perform();47	}48}...

Full Screen

Full Screen

GesturesPressAndLongPress.java

Source:GesturesPressAndLongPress.java Github

copy

Full Screen

...13        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);14        By accessibility = MobileBy.AccessibilityId("Activity Indicators");15        TouchAction t =new TouchAction(driver);16        //t.press(ElementOption.element(driver.findElement(accessibility))).perform();17        //t.press(ElementOption.element(driver.findElement(accessibility))).release().perform();18//        t.press(ElementOption.element(driver.findElement(accessibility)))19//                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(5000))).release().perform();20        //t.longPress(ElementOption.element(driver.findElement(accessibility))).release().perform();21        t.longPress(ElementOption.element(driver.findElement(accessibility)))22                .waitAction(WaitOptions.waitOptions(Duration.ofMillis(5000))).release().perform();23    }24}...

Full Screen

Full Screen

Scrolling.java

Source:Scrolling.java Github

copy

Full Screen

...8public class Scrolling extends BaseClass{9	10	public void scrollDown() {11		12		new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();13	14}15	public void scrollDownReview() {16		17		18		new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();19		new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();20		new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();21		new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();22		23	}24}...

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1TouchAction touchAction = new TouchAction(driver);2touchAction.release().perform();3TouchAction touchAction = new TouchAction(driver);4touchAction.release().perform();5TouchAction touchAction = new TouchAction(driver);6touchAction.release().perform();7TouchAction touchAction = new TouchAction(driver);8touchAction.release().perform();9TouchAction touchAction = new TouchAction(driver);10touchAction.release().perform();11TouchAction touchAction = new TouchAction(driver);12touchAction.release().perform();13TouchAction touchAction = new TouchAction(driver);14touchAction.release().perform();15TouchAction touchAction = new TouchAction(driver);16touchAction.release().perform();17TouchAction touchAction = new TouchAction(driver);18touchAction.release().perform();19TouchAction touchAction = new TouchAction(driver);20touchAction.release().perform();21TouchAction touchAction = new TouchAction(driver);22touchAction.release().perform();23TouchAction touchAction = new TouchAction(driver);24touchAction.release().perform();25TouchAction touchAction = new TouchAction(driver);26touchAction.release().perform();

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1TouchAction action = new TouchAction(driver);2action.release().perform();3WaitOptions waitOptions = new WaitOptions();4waitOptions.withDuration(Duration.ofMillis(2000));5TouchAction action = new TouchAction(driver);6action.release(waitOptions).perform();7PointOption pointOption = new PointOption();8pointOption.withCoordinates(10, 10);9TouchAction action = new TouchAction(driver);10action.release(pointOption).perform();11ElementOption elementOption = new ElementOption();12elementOption.withElement(element);13TouchAction action = new TouchAction(driver);14action.release(elementOption).perform();15ElementOption elementOption = new ElementOption();16elementOption.withElement(element);17TouchAction action = new TouchAction(driver);18action.release(elementOption).perform();19ElementOption elementOption = new ElementOption();20elementOption.withElement(element);21TouchAction action = new TouchAction(driver);22action.release(elementOption).perform();23ElementOption elementOption = new ElementOption();24elementOption.withElement(element);25TouchAction action = new TouchAction(driver);26action.release(elementOption).perform();27ElementOption elementOption = new ElementOption();28elementOption.withElement(element);29TouchAction action = new TouchAction(driver);30action.release(elementOption).perform

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1new TouchAction(driver).release().perform();2new TouchAction(driver).scroll(100, 100).perform();3new TouchAction(driver).swipe(100, 100, 200, 200).perform();4new TouchAction(driver).tap(100, 100).perform();5new TouchAction(driver).waitAction(100).perform();6new TouchAction(driver).zoom(100, 100).perform();7new TouchAction(driver).zoom(100, 100).perform();8new TouchAction(driver).zoom(100, 100).perform();9new TouchAction(driver).zoom(100, 100).perform();10new TouchAction(driver).zoom(100, 100).perform();11new TouchAction(driver).zoom(100, 100).perform();12new TouchAction(driver).zoom(100, 100).perform();13new TouchAction(driver).zoom(100, 100).perform();14new TouchAction(driver).zoom(100, 100).perform();

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1TouchAction action = new TouchAction(driver);2action.press(200, 200).release().perform();3action = TouchAction(driver)4action.press(x=200, y=200).release().perform()5var action = new TouchAction(driver);6action.press({x: 200, y: 200}).release().perform();7action.press(x: 200, y: 200).release.perform8$action = new Facebook\WebDriver\Interactions\TouchAction($driver);9$action->press($driver->findElement(WebDriverBy::id('id')))->release()->perform();10action.press(x: 200, y: 200).release.perform11let action = AppiumTouchAction(driver)12action.press(x: 200, y: 200).release().perform()13my $action = $driver->touch_action;14$action->press(x => 200, y => 200)->release->perform;15action <- Appium::TouchAction$new()16action$press(x=200, y=200)$release$perform()17val action = AppiumTouchAction(driver)18action.press(x = 200, y = 200).release().perform()19Appium_TouchAction *action = appium_touch_action_new();20appium_touch_action_press(action, 200, 200

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1TouchAction action = new TouchAction(driver);2action.press(20, 20).release().perform();3action = TouchAction(driver)4action.press(x=20, y=20).release().perform()5action = new wd.TouchAction(driver)6action.press({x: 20, y: 20})7action.release()8action.perform()9action := TouchAction{driver}10action.Press(20, 20).Release().Perform()11$action = new TouchAction($driver);12$action->press(['x' => 20, 'y' => 20])->release()->perform();13TouchAction action = new TouchAction(driver);14action.Press(20, 20).Release().Perform();15let action = TouchAction(driver)16action.press(x: 20, y: 20)17action.release()18action.perform()19action = TouchAction(driver)20action.press(x=20, y=20).release().perform()21action = new wd.TouchAction(driver)22action.press({x: 20, y: 20})23action.release()24action.perform()25action := TouchAction{driver}26action.Press(20, 20).Release().Perform()

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1TouchAction action = new TouchAction(driver);2action.press(100,200).release();3MultiTouchAction multiTouch = new MultiTouchAction(driver);4multiTouch.add(action).release();5action = TouchAction(driver)6action.press(x=100, y=200).release()7multi_action = MultiAction(driver)8multi_action.add(action).release()9action.press(x: 100, y: 200).release10multi_action.add(action).release11action = new TouchAction(driver)12action.press({x: 100, y: 200}).release()13multi_action = new MultiAction(driver)14multi_action.add(action).release()15var action = new wd.TouchAction(driver);16action.press({x: 100, y: 200}).release()17var multi_action = new wd.MultiAction(driver);18multi_action.add(action).release()19var action = new TouchAction(driver);20action.Press(100, 200).Release();21var multi_action = new MultiAction(driver);22multi_action.Add(action).Release();23$driver->touchAction([24]);25$driver->touchAction([26]);

Full Screen

Full Screen

release

Using AI Code Generation

copy

Full Screen

1TouchAction action = new TouchAction(driver);2action.press(300, 300).waitAction(2000).release().perform();3var action = new wd.TouchAction();4action.press({x: 300, y: 300}).waitAction(2000).release().perform();5action = TouchAction(self.driver)6action.press(x=300, y=300).wait(ms=2000).release().perform()7action.press(x: 300, y: 300).wait(2000).release.perform8$touchAction = new TouchAction($driver);9$touchAction->press(array('x' => 300, 'y' => 300))->waitAction(2000)->release()->perform();10action = new TouchAction(driver)11action.press(x: 300, y: 300).wait(2000).release().perform()12TouchAction action = new TouchAction(driver);13action.Press(300, 300).Wait(2000).Release().Perform();14action = new TouchAction(driver)15action.press(x: 300, y: 300).wait(2000).release().perform()16TouchAction action = new TouchAction(driver)17action.press(300, 300).waitAction(2000).release().perform()18let action = TouchAction(driver)

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