@Test public void tapActionTestByCoordinates() throws Exception { Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo"); driver.startActivity(activity); AndroidElement chronometer = driver.findElementById("io.appium.android.apis:id/chronometer"); Point center1 = driver.findElementById("io.appium.android.apis:id/start").getCenter(); TouchAction startStop = new TouchAction(driver) .tap(point(center1.x, center1.y)) .tap(element(driver.findElementById("io.appium.android.apis:id/stop"), 5, 5)); startStop.perform(); String time = chronometer.getText(); assertNotEquals(time, "Initial format: 00:00"); Thread.sleep(2500); assertEquals(time, chronometer.getText()); }
@Test public void tapActionTestByElement() throws Exception { Activity activity = new Activity("io.appium.android.apis", ".view.ChronometerDemo"); driver.startActivity(activity); AndroidElement chronometer = driver.findElementById("io.appium.android.apis:id/chronometer"); TouchAction startStop = new TouchAction(driver) .tap(tapOptions().withElement(element(driver.findElementById("io.appium.android.apis:id/start")))) .waitAction(waitOptions(ofSeconds(2))) .tap(tapOptions().withElement(element(driver.findElementById("io.appium.android.apis:id/stop")))); startStop.perform(); String time = chronometer.getText(); assertNotEquals(time, "Initial format: 00:00"); Thread.sleep(2500); assertEquals(time, chronometer.getText()); }
@Test public void multiTouchTest() { MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); MobileElement e2 = driver.findElementByAccessibilityId("show alert"); TouchAction tap1 = new TouchAction(driver).tap(tapOptions().withElement(element(e))); TouchAction tap2 = new TouchAction(driver).tap(tapOptions().withElement(element(e2))); new MultiTouchAction(driver).add(tap1).add(tap2).perform(); WebDriverWait waiting = new WebDriverWait(driver, 10000); assertNotNull(waiting.until(alertIsPresent())); driver.switchTo().alert().accept(); }
public static void clickByCoordinate(int x, int y){ log.info(MyLogger.getMethodName()); log.info("X: " + x + " Y: " +y ); try { TouchAction touchAction = new TouchAction(driver); //touchAction.press(PointOption.point(x,y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform(); //touchAction.tap(PointOption.point(x,y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform(); touchAction.tap(PointOption.point(x, y)).perform(); }catch (Exception e){ e.printStackTrace(); log.error("Fail to clickByCoordinate"); } }
public static void doubleClickByCoordinate(int x, int y) { log.info(MyLogger.getMethodName()); log.info("Double click X: " + x + " Y: " +y ); try { TouchAction touchAction = new TouchAction(driver); //touchAction.press(PointOption.point(x,y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform(); //touchAction.tap(PointOption.point(x,y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(100))).release().perform(); touchAction.tap(PointOption.point(x, y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(200))).tap(PointOption.point(x, y)).perform(); }catch (Exception e){ e.printStackTrace(); log.error("Fail to doubleClickByCoordinate"); } }
@Test public void tapTest() { IOSElement intA = driver.findElementById("IntegerA"); IOSElement intB = driver.findElementById("IntegerB"); intA.clear(); intB.clear(); intA.sendKeys("2"); intB.sendKeys("4"); MobileElement e = driver.findElementByAccessibilityId("ComputeSumButton"); new TouchAction(driver).tap(tapOptions().withElement(element(e))).perform(); assertEquals(driver.findElementByXPath("//*[@name = \"Answer\"]").getText(), "6"); }
/** * Pressing bottom right button on the keyboard by coordinates: "search", * "ok", "next", etc. - various keys appear at this position. Tested at * Nexus 6P Android 8.0.0 standard keyboard. Coefficients of coordinates for * other devices and custom keyboards could be different. */ @SuppressWarnings("rawtypes") public static void pressBottomRightKey() { WebDriver driver = getDriver(); Dimension size = helper.performIgnoreException(() -> driver.manage().window().getSize()); int height = size.getHeight(); int width = size.getWidth(); PointOption<?> option = PointOption.point(Double.valueOf(width * 0.915).intValue(), Double.valueOf(height * 0.945).intValue()); new TouchAction((AndroidDriver<?>) driver).tap(option).perform(); }
/** * @author wasiq.bhamla * @since 12-May-2017 10:08:55 PM */ public void tap () { perform ("Tapping on", e -> this.touch.waitAction (WaitOptions.waitOptions (ofMillis (this.beforeTap))) .tap (TapOptions.tapOptions () .withElement (ElementOption.element (e))) .waitAction (WaitOptions.waitOptions (ofMillis (this.afterTap))) .perform ()); }
@ReplayOnError(replayDelayMs=1000) public void tap() { findElement(); createTouchAction() .moveTo(PointOption.point(detectedObjectRectangle.x + detectedObjectRectangle.width / 2, detectedObjectRectangle.y + detectedObjectRectangle.height / 2)) .tap(TapOptions.tapOptions().withTapsCount(1)).perform(); }
@Override public <T extends Actor> void performAs(T actor) { WebDriverFacade facade = (WebDriverFacade) BrowseTheWeb.as(actor).getDriver(); AndroidDriver androidDriver = (AndroidDriver) facade.getProxiedDriver(); TouchAction actions = new TouchAction(androidDriver); WebElementFacade elementFacade = SelectAccount.ONLY_ACCOUNT.resolveFor(actor); actions.tap(new TapOptions().withElement(new ElementOption().withElement(elementFacade))); actions.perform(); } }