Search in sources :

Example 21 with MobileElement

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

the class ActionsPress method run.

@Override
public void run() {
    super.run();
    By locator = this.readLocatorArgument("locator", null);
    Integer xOffset = this.readIntArgument("xOffset", 0);
    Integer yOffset = this.readIntArgument("yOffset", 0);
    Integer x = this.readIntArgument("x", null);
    Integer y = this.readIntArgument("y", null);
    MobileElement element = this.getElement(locator);
    if (locator != null) {
        Point position = element.getLocation();
        Dimension dimension = element.getSize();
        int xCoord = position.x + (dimension.width / 2) + xOffset;
        int yCoord = position.y + (dimension.height / 2) + yOffset;
        AppiumTestAction.getActionsInstance().press(PointOption.point(xCoord, yCoord));
    } else if (x != null && y != null) {
        AppiumTestAction.getActionsInstance().press(PointOption.point(x, y));
    } else {
        throw new RuntimeException("You must either provide the locator argument of the element to press, " + "or the x and y arguments to indicate the exact coordinates to press at.");
    }
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point)

Example 22 with MobileElement

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

the class LongPress method run.

@Override
public void run() {
    super.run();
    By locator = this.readLocatorArgument("locator");
    Integer durationMs = this.readIntArgument("durationMs", null);
    this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
    MobileElement element = this.getElement(locator);
    TouchAction action = new TouchAction((MobileDriver) driver);
    if (durationMs == null) {
        action.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(element)));
    } else {
        action.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(element)).withDuration(Duration.ofMillis(durationMs)));
    }
    action.release().perform();
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By) TouchAction(io.appium.java_client.TouchAction)

Example 23 with MobileElement

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

the class ReadElementAspect method run.

@Override
public void run() {
    super.run();
    By locator = readLocatorArgument("locator");
    this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
    MobileElement element = this.getElement(locator);
    Point point = element.getLocation();
    int x = point.getX();
    int y = point.getY();
    Dimension size = element.getSize();
    int width = size.width;
    int height = size.height;
    Logger.trace(String.format("The element aspect is (%s,%s,%s,%s)", x, y, width, height));
    this.writeOutput("x", x);
    this.writeOutput("y", y);
    this.writeOutput("width", width);
    this.writeOutput("height", height);
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point)

Example 24 with MobileElement

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

the class AssertElementChecked method run.

@Override
public void run() {
    super.run();
    By locator = readLocatorArgument("locator");
    swipeAndCheckElementVisible(locator, this.getSwipeOptions());
    MobileElement element = getElement(locator, this.getExplicitWaitSec());
    WebDriverWait wait = new WebDriverWait(this.driver, this.getExplicitWaitSec());
    wait.until(CustomConditions.attributeValueToBe(element, "checked", "true"));
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait)

Example 25 with MobileElement

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

the class AppiumHelper method createDriver.

private static AppiumDriver<MobileElement> createDriver(String url, Map<String, Object> capsMap) {
    if (url == null) {
        url = AppiumHelper.getConfig().getString("appium.appiumServerUrl", "http://127.0.0.1:4723/wd/hub");
    }
    Logger.info(String.format("Using Appium server URL \"%s\"", url));
    if (capsMap == null) {
        capsMap = new HashMap<String, Object>();
    }
    String platformLowercase = getCapabilityAsString(capsMap, "platformName", getCapabilityAsString(capsMap, "platform", config.getString("appium.desiredCapabilities.platformName", null)));
    if (platformLowercase != null) {
        platformLowercase = platformLowercase.trim().toLowerCase();
    } else {
        throw new RuntimeException("The \"platformName\" capability was not populated in " + "configuration. Please provide a value for it in the " + "\"appium.desiredCapabilities.platformName\" key. The valid " + "values are \"iOS\" or \"Android\".");
    }
    AppiumHelper.platform = platformLowercase;
    AppiumDriver<MobileElement> newDriver;
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(CapabilityType.BROWSER_NAME, "");
    caps.setCapability("newCommandTimeout", 600);
    injectCapsFromConfig(caps);
    try {
        if (platform.equalsIgnoreCase("android")) {
            caps.setCapability("deviceName", "Android Emulator");
            caps.setCapability("platformName", "Android");
            copyCapabilities(capsMap, caps);
            Logger.info("Creating Appium Android driver...");
            newDriver = new AndroidDriver<>(new URL(url), caps);
        } else if (platform.equalsIgnoreCase("ios")) {
            caps.setCapability("deviceName", "iOS Emulator");
            caps.setCapability("platformName", "iOS");
            copyCapabilities(capsMap, caps);
            Logger.info("Creating Appium iOS driver...");
            newDriver = new IOSDriver<>(new URL(url), caps);
        } else {
            throw new RuntimeException("Failed to instantiate Appium driver. The \"platformName\" " + "capability is missing or is specified incorrectly. The valid " + "values are \"iOS\" or \"Android\".");
        }
    } catch (MalformedURLException ex) {
        throw new RuntimeException("Failed to initialize Appium", ex);
    }
    return newDriver;
}
Also used : IOSDriver(io.appium.java_client.ios.IOSDriver) MalformedURLException(java.net.MalformedURLException) MobileElement(io.appium.java_client.MobileElement) DesiredCapabilities(org.openqa.selenium.remote.DesiredCapabilities) URL(java.net.URL)

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