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");
}
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);
}
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.");
}
}
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));
}
}
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);
}
Aggregations