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