Search in sources :

Example 6 with MobileElement

use of io.appium.java_client.MobileElement in project java-client by appium.

the class IOSTouchTest method tapTest.

@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");
}
Also used : MobileElement(io.appium.java_client.MobileElement) TouchAction(io.appium.java_client.TouchAction) MultiTouchAction(io.appium.java_client.MultiTouchAction) Test(org.junit.Test)

Example 7 with MobileElement

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

the class AppiumTestAction method calculateSwipeCoordinates.

protected SwipeCoordinates calculateSwipeCoordinates(SwipeOptions options) {
    // First, figure out the position and size of the swipe container
    Rectangle containerAspect;
    if (options.swipeContainer == null) {
        Dimension screenSize;
        screenSize = driver.manage().window().getSize();
        containerAspect = new Rectangle(0, 0, screenSize.width, screenSize.height);
    } else {
        MobileElement swipeContainer = this.getElement(options.swipeContainer);
        Point position = swipeContainer.getLocation();
        Dimension size = swipeContainer.getSize();
        containerAspect = new Rectangle(position.x, position.y, size.width, size.height);
    }
    int topY = (int) (containerAspect.y + containerAspect.height * options.offsetTop);
    int bottomY = (int) (containerAspect.y + containerAspect.height - (containerAspect.height * options.offsetBottom));
    int leftX = (int) (containerAspect.x + containerAspect.width * options.offsetLeft);
    int rightX = (int) (containerAspect.x + containerAspect.width - (containerAspect.width * options.offsetRight));
    int fromX, fromY, toX, toY;
    switch(options.direction) {
        case "bottom":
            options.swipeToEdge = true;
            fromX = toX = containerAspect.x + containerAspect.width / 2;
            fromY = bottomY;
            toY = topY;
            break;
        case "down":
            fromX = toX = containerAspect.x + containerAspect.width / 2;
            if (!AppiumHelper.getInvertVerticalSwipe()) {
                fromY = bottomY;
                toY = topY;
            } else {
                fromY = topY;
                toY = bottomY;
            }
            break;
        case "rightmost":
            options.swipeToEdge = true;
            fromY = toY = containerAspect.y + containerAspect.height / 2;
            fromX = rightX;
            toX = leftX;
            break;
        case "right":
            fromY = toY = containerAspect.y + containerAspect.height / 2;
            if (!AppiumHelper.getInvertHorizontalSwipe()) {
                fromX = rightX;
                toX = leftX;
            } else {
                fromX = leftX;
                toX = rightX;
            }
            break;
        case "top":
            options.swipeToEdge = true;
            fromX = toX = containerAspect.x + containerAspect.width / 2;
            fromY = topY;
            toY = bottomY;
            break;
        case "up":
            fromX = toX = containerAspect.x + containerAspect.width / 2;
            if (!AppiumHelper.getInvertVerticalSwipe()) {
                fromY = topY;
                toY = bottomY;
            } else {
                fromY = bottomY;
                toY = topY;
            }
            break;
        case "leftmost":
            options.swipeToEdge = true;
            fromY = toY = containerAspect.y + containerAspect.height / 2;
            fromX = leftX;
            toX = rightX;
            break;
        case "left":
            fromY = toY = containerAspect.y + containerAspect.height / 2;
            if (!AppiumHelper.getInvertHorizontalSwipe()) {
                fromX = leftX;
                toX = rightX;
            } else {
                fromX = rightX;
                toX = leftX;
            }
            break;
        default:
            throw new RuntimeException(String.format("Direction \"%s\" is not a valid swipe direction. The supported values " + "are: up, down, left, right.", options.direction));
    }
    return new SwipeCoordinates(fromX, fromY, toX, toY);
}
Also used : MobileElement(io.appium.java_client.MobileElement) Rectangle(java.awt.Rectangle) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point) Point(org.openqa.selenium.Point)

Example 8 with MobileElement

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

the class ActionsTap 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().tap(PointOption.point(xCoord, yCoord));
    } else if (x != null && y != null) {
        AppiumTestAction.getActionsInstance().tap(PointOption.point(x, y));
    } 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) Point(org.openqa.selenium.Point) Dimension(org.openqa.selenium.Dimension) Point(org.openqa.selenium.Point)

Example 9 with MobileElement

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

the class AssertElementNotChecked method run.

@Override
public void run() {
    super.run();
    By locator = this.readLocatorArgument("locator");
    this.swipeAndCheckElementVisible(locator, this.getSwipeOptions());
    MobileElement element = this.getElement(locator);
    String checkedState = element.getAttribute("checked");
    if (!checkedState.equalsIgnoreCase("false")) {
        throw new RuntimeException(String.format("Expected element's checked state to be \"false\", but it was" + "found to be \"%s\"", checkedState));
    }
}
Also used : MobileElement(io.appium.java_client.MobileElement) By(org.openqa.selenium.By)

Example 10 with MobileElement

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

the class InitAppium method run.

@Override
public void run() {
    super.run();
    String platform = this.readStringArgument("platform", null);
    String configUrl = AppiumHelper.getConfig().getString("appium.appiumServerUrl", null);
    String appiumUrl = this.readStringArgument("url", configUrl);
    Map<String, Object> capsMap = this.readMapArgument("desiredCapabilities", new HashMap<>());
    if (appiumUrl == null) {
        throw new RuntimeException("The URL of the Appium server was not specified. You must either " + "provide it the \"url\" argument, or specify it in the actor's " + "configuration file using the \"appium.appiumServerUrl\" parameter.");
    }
    if (platform == null) {
        Config config = AppiumHelper.getConfig();
        platform = getCapabilityAsString(capsMap, "platformName", getCapabilityAsString(capsMap, "platform", config.getString("appium.desiredCapabilities.platformName", null)));
    }
    if (platform != null) {
        platform = platform.trim().toLowerCase();
        if (platform.equals("android")) {
            capsMap.put("platformName", "Android");
        } else if (platform.equals("ios")) {
            capsMap.put("platformName", "iOS");
        }
    }
    AppiumHelper.discardDriver();
    AppiumDriver<MobileElement> driver = AppiumHelper.createDriverWithRetries(appiumUrl, capsMap);
// TODO: Use the AppiumDriverSerializer class so we can avoid the stack overflow when the driver output is serialized to JSON
// this.writeOutput("driver", driver);
}
Also used : Config(org.getopentest.util.Config) MobileElement(io.appium.java_client.MobileElement) AppiumHelper.getCapabilityAsString(org.getopentest.appium.core.AppiumHelper.getCapabilityAsString)

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