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