Search in sources :

Example 1 with MobileElementState

use of com.axway.ats.uiengine.utilities.mobile.MobileElementState 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();
}
Also used : Actions(org.openqa.selenium.interactions.Actions) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) AndroidDriver(io.appium.java_client.android.AndroidDriver) WebElement(org.openqa.selenium.WebElement) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) MobileElementState(com.axway.ats.uiengine.utilities.mobile.MobileElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 2 with MobileElementState

use of com.axway.ats.uiengine.utilities.mobile.MobileElementState 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;
}
Also used : VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) MobileElementState(com.axway.ats.uiengine.utilities.mobile.MobileElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 3 with MobileElementState

use of com.axway.ats.uiengine.utilities.mobile.MobileElementState 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();
}
Also used : Actions(org.openqa.selenium.interactions.Actions) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) AndroidDriver(io.appium.java_client.android.AndroidDriver) WebElement(org.openqa.selenium.WebElement) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) MobileElementState(com.axway.ats.uiengine.utilities.mobile.MobileElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 4 with MobileElementState

use of com.axway.ats.uiengine.utilities.mobile.MobileElementState 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);
    }
}
Also used : MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) MobileElementState(com.axway.ats.uiengine.utilities.mobile.MobileElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 5 with MobileElementState

use of com.axway.ats.uiengine.utilities.mobile.MobileElementState 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);
    }
}
Also used : JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) MobileDriver(com.axway.ats.uiengine.MobileDriver) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) Dimension(org.openqa.selenium.Dimension) WebElement(org.openqa.selenium.WebElement) MobileOperationException(com.axway.ats.uiengine.exceptions.MobileOperationException) VerificationException(com.axway.ats.uiengine.exceptions.VerificationException) MobileElementState(com.axway.ats.uiengine.utilities.mobile.MobileElementState) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Aggregations

PublicAtsApi (com.axway.ats.common.PublicAtsApi)7 MobileOperationException (com.axway.ats.uiengine.exceptions.MobileOperationException)7 MobileElementState (com.axway.ats.uiengine.utilities.mobile.MobileElementState)7 VerificationException (com.axway.ats.uiengine.exceptions.VerificationException)5 WebElement (org.openqa.selenium.WebElement)5 VerifyEqualityException (com.axway.ats.uiengine.exceptions.VerifyEqualityException)2 VerifyNotEqualityException (com.axway.ats.uiengine.exceptions.VerifyNotEqualityException)2 AndroidDriver (io.appium.java_client.android.AndroidDriver)2 Actions (org.openqa.selenium.interactions.Actions)2 MobileDriver (com.axway.ats.uiengine.MobileDriver)1 Dimension (org.openqa.selenium.Dimension)1 JavascriptExecutor (org.openqa.selenium.JavascriptExecutor)1