Search in sources :

Example 26 with MobileElement

use of io.appium.java_client.MobileElement in project opentest by mcdcorp.

the class SendKeys method run.

@Override
public void run() {
    super.run();
    By locator = this.readLocatorArgument("locator", null);
    String text = this.readStringArgument("text");
    Boolean clearContent = this.readBooleanArgument("clearContent", this.readBooleanArgument("clear", Boolean.FALSE));
    Boolean hideKeyboard = this.readBooleanArgument("hideKeyboard", true);
    Boolean useKeyboardService = this.readBooleanArgument("useKeyboardService", Boolean.FALSE);
    try {
        MobileElement element = null;
        if (locator != null) {
            this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
            element = this.getElement(locator);
        }
        if (clearContent && element != null) {
            element.clear();
        }
        if (useKeyboardService) {
            if (element != null) {
                element.click();
            }
            driver.getKeyboard().sendKeys(text);
        } else {
            if (element != null) {
                element.sendKeys(text);
            } else {
                throw new RuntimeException("Can't perform action. You must either specify the locator of the element to send " + "the keys to, or set the \"useKeyboardService\" argument's value to true.");
            }
        }
        if (hideKeyboard) {
            this.hideKeyboard();
        }
    } catch (Exception ex) {
        if (locator != null) {
            throw new RuntimeException(String.format("Failed sending keys \"%s\" to element %s", text, locator.toString()), ex);
        } else {
            throw new RuntimeException(String.format("Failed sending keys \"%s\"", text), ex);
        }
    }
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By)

Example 27 with MobileElement

use of io.appium.java_client.MobileElement in project opentest by mcdcorp.

the class Tap method run.

@Override
public void run() {
    super.run();
    By locator = this.readLocatorArgument("locator", null);
    Integer xOffset = this.readIntArgument("xOffset", null);
    Integer yOffset = this.readIntArgument("yOffset", null);
    Integer x = this.readIntArgument("x", null);
    Integer y = this.readIntArgument("y", null);
    if (locator != null) {
        this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
        MobileElement element = this.getElement(locator);
        if (xOffset == null || yOffset == null) {
            element.click();
        } else {
            (new TouchAction(driver)).tap(TapOptions.tapOptions().withElement(ElementOption.element(element, xOffset != null ? xOffset : 0, yOffset != null ? yOffset : 0))).perform();
        }
    } else if (x != null && y != null) {
        (new TouchAction(driver)).tap(TapOptions.tapOptions().withPosition(PointOption.point(x, y))).perform();
    } else {
        throw new RuntimeException("You must either provide the locator argument of the element to tap, " + "or the x and y arguments to indicate the exact coordinates to tap at.");
    }
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By) TouchAction(io.appium.java_client.TouchAction)

Aggregations

MobileElement (io.appium.java_client.MobileElement)27 Test (org.junit.Test)12 By (org.openqa.selenium.By)11 Point (org.openqa.selenium.Point)7 TouchAction (io.appium.java_client.TouchAction)6 Dimension (org.openqa.selenium.Dimension)6 MultiTouchAction (io.appium.java_client.MultiTouchAction)4 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)3 PublicAtsApi (com.axway.ats.common.PublicAtsApi)1 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)1 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)1 AndroidElement (io.appium.java_client.android.AndroidElement)1 IOSDriver (io.appium.java_client.ios.IOSDriver)1 ElementOption (io.appium.java_client.touch.offset.ElementOption)1 PointOption.point (io.appium.java_client.touch.offset.PointOption.point)1 Rectangle (java.awt.Rectangle)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 AppiumHelper.getCapabilityAsString (org.getopentest.appium.core.AppiumHelper.getCapabilityAsString)1 Config (org.getopentest.util.Config)1