use of com.axway.ats.uiengine.exceptions.MobileOperationException in project ats-framework by Axway.
the class MobileCheckBox method unCheck.
/**
* Uncheck the check box
*/
@Override
@PublicAtsApi
public void unCheck() {
new MobileElementState(this).waitToBecomeExisting();
try {
WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
if (checkboxElement.isSelected()) {
if (appiumDriver instanceof AndroidDriver) {
// checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
} else {
checkboxElement.click();
}
}
} catch (Exception se) {
throw new MobileOperationException(this, "unCheck", se);
}
UiEngineUtilities.sleep();
}
use of com.axway.ats.uiengine.exceptions.MobileOperationException in project ats-framework by Axway.
the class MobileElement method clickIfExists.
// public T click() {
//
// new MobileElementState( this ).waitToBecomeExisting();
//
// try {
// try {
// MobileElementFinder.findElement( appiumDriver, this ).click();
// } catch( ElementNotVisibleException enve ) { // element is not currently visible and may not be manipulated
//
// new MobileElementState( this ).waitToBecomeDisplayed();
// MobileElementFinder.findElement( appiumDriver, this ).click();
// }
// return ( T ) this;
// } catch( Exception e ) {
// throw new MobileOperationException( this, "click", e );
// }
// }
/**
* Click/tap the element if exists.
*
* @param waitingTimeout timeout in milliseconds to wait for the element to appear
*/
@PublicAtsApi
public boolean clickIfExists(int waitingTimeout) {
int currentStateChangeDelay = UiEngineConfigurator.getInstance().getElementStateChangeDelay();
try {
UiEngineConfigurator.getInstance().setElementStateChangeDelay(waitingTimeout);
appiumDriver.manage().timeouts().implicitlyWait(waitingTimeout, TimeUnit.MILLISECONDS);
long endTime = System.currentTimeMillis() + waitingTimeout;
new MobileElementState(this).waitToBecomeExisting();
// the element exists but may be still not clickable
do {
try {
MobileElementFinder.findElement(appiumDriver, this).click();
return true;
} catch (Exception e) {
}
UiEngineUtilities.sleep(500);
} while (endTime - System.currentTimeMillis() > 0);
} catch (VerificationException ve) {
// do nothing, the element doesn't exist
} finally {
UiEngineConfigurator.getInstance().setElementStateChangeDelay(currentStateChangeDelay);
appiumDriver.manage().timeouts().implicitlyWait(currentStateChangeDelay, TimeUnit.MILLISECONDS);
}
return false;
}
use of com.axway.ats.uiengine.exceptions.MobileOperationException in project ats-framework by Axway.
the class MobileCheckBox method check.
/**
* Check the check box
*/
@Override
@PublicAtsApi
public void check() {
new MobileElementState(this).waitToBecomeExisting();
try {
WebElement checkboxElement = MobileElementFinder.findElement(appiumDriver, this);
if (!checkboxElement.isSelected()) {
if (appiumDriver instanceof AndroidDriver) {
// checkboxElement.click(); // throwing exception (on Android) with message: Element is not clickable at point (x,y). Other element would receive the click
new Actions(appiumDriver).moveToElement(checkboxElement).click().perform();
} else {
checkboxElement.click();
}
}
} catch (Exception se) {
throw new MobileOperationException(this, "check", se);
}
UiEngineUtilities.sleep();
}
use of com.axway.ats.uiengine.exceptions.MobileOperationException in project ats-framework by Axway.
the class MobileElement method click.
/**
* Simulate tap/click action
* @return this mobile element so allows chained actions like element.click().getTextContent()
*/
@SuppressWarnings("unchecked")
@PublicAtsApi
public T click() {
long endTime = System.currentTimeMillis() + UiEngineConfigurator.getInstance().getElementStateChangeDelay();
new MobileElementState(this).waitToBecomeExisting();
try {
// the element exists but may be still not clickable (in some cases waitToBecomeDisplayed() is not working and returns true, but it is not visible)
while (true) {
try {
MobileElementFinder.findElement(appiumDriver, this).click();
return (T) this;
} catch (Exception e) {
if (endTime - System.currentTimeMillis() < 0) {
throw e;
}
}
UiEngineUtilities.sleep(500);
}
} catch (Exception e) {
throw new MobileOperationException(this, "click", e);
}
}
use of com.axway.ats.uiengine.exceptions.MobileOperationException in project ats-framework by Axway.
the class MobileElement method scrollTo.
/**
* Scroll to element (at the center of the screen)
*
* @return this mobile element which allows chained actions
*/
@SuppressWarnings("unchecked")
@PublicAtsApi
public T scrollTo() {
try {
if (MobileElementFinder.getElementContext(this).toUpperCase().startsWith("WEBVIEW")) {
// in WEBVIEWs the target element exists, while in the NATIVE context it doesn't until we scroll to it
new MobileElementState(this).waitToBecomeExisting();
Dimension screenDimensions = ((MobileDriver) getUiDriver()).getScreenDimensions();
WebElement element = MobileElementFinder.findElement(appiumDriver, this);
// window.scrollTo(0, element.getLocation().y); --> will scroll the element to top-left
int scrollToY = 0;
int screenCenter = screenDimensions.getHeight() / 2 + element.getSize().height / 2;
if (element.getLocation().y < screenCenter) {
// the element is located after the screen center if we scroll to (0, element.getLocation().y)
// because it is near the bottom of the application => we can't center it, but it is OK on that position
scrollToY = element.getLocation().y;
} else {
scrollToY = element.getLocation().y - screenCenter;
}
((JavascriptExecutor) appiumDriver).executeScript("window.scrollTo(0," + scrollToY + ")");
} else {
if (getElementProperty("name") != null) {
// only works for NATIVE context
appiumDriver.scrollTo(getElementProperty("name"));
}
}
return (T) this;
} catch (Exception e) {
throw new MobileOperationException(this, "scrollTo", e);
}
}
Aggregations