Search in sources :

Example 1 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method pinch.

@ReplayOnError(waitAfterAction = true)
public void pinch() {
    PerformsTouchActions performTouchActions = checkForMobile();
    MobileElement mobElement = (MobileElement) getUnderlyingElement(getRealElementNoSearch());
    // code taken from appium
    MultiTouchAction multiTouch = new MultiTouchAction(performTouchActions);
    Point upperLeft = mobElement.getLocation();
    Point center = mobElement.getCenter();
    int yOffset = center.getY() - upperLeft.getY();
    TouchAction<?> action0 = createTouchAction().press(ElementOption.element(mobElement, center.getX(), center.getY() - yOffset)).moveTo(ElementOption.element(mobElement)).release();
    TouchAction<?> action1 = createTouchAction().press(ElementOption.element(mobElement, center.getX(), center.getY() + yOffset)).moveTo(ElementOption.element(mobElement)).release();
    multiTouch.add(action0).add(action1).perform();
}
Also used : MultiTouchAction(io.appium.java_client.MultiTouchAction) MobileElement(io.appium.java_client.MobileElement) Point(org.openqa.selenium.Point) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 2 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method waitForPresent.

/**
 * Wait element to present using Explicit Waits with timeout in seconds. This
 * method is used for special element which needs long time to present. This
 * method is replayed because it may fail if frame is not present at start. The
 * replay is not done if TimeOutException raises (see ReplayAction class)
 *
 * @param timeout timeout in seconds. Set a minimal value of 1 sec to avoid not
 *                searching for element
 */
@ReplayOnError
public void waitForPresent(int timeout) {
    // refresh driver
    setDriver(updateDriver());
    try {
        setImplicitWaitTimeout(510, TimeUnit.MILLISECONDS);
        Clock clock = Clock.systemUTC();
        Instant end = clock.instant().plusSeconds(Math.max(1, timeout));
        while (end.isAfter(clock.instant())) {
            try {
                WebElement elt = new WebDriverWait(getDriver(), 0).ignoring(ConfigurationException.class, ScenarioException.class).until(ExpectedConditionsC.presenceOfElementLocated(this));
                outlineElement(elt);
                return;
            } catch (TimeoutException e) {
            // nothing to do
            }
        }
        throw new TimeoutException("Element is not present", new NoSuchElementException(toString()));
    } finally {
        setImplicitWaitTimeout(SeleniumTestsContextManager.getThreadContext().getImplicitWaitTimeout());
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) Instant(java.time.Instant) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) Clock(java.time.Clock) WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) ScenarioException(com.seleniumtests.customexception.ScenarioException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 3 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method zoom.

@ReplayOnError(waitAfterAction = true)
public void zoom() {
    PerformsTouchActions performTouchActions = checkForMobile();
    MobileElement mobElement = (MobileElement) getUnderlyingElement(getRealElementNoSearch());
    MultiTouchAction multiTouch = new MultiTouchAction(performTouchActions);
    Point upperLeft = mobElement.getLocation();
    Point center = mobElement.getCenter();
    int yOffset = center.getY() - upperLeft.getY();
    TouchAction<?> action0 = createTouchAction().press(PointOption.point(center.getX(), center.getY())).moveTo(ElementOption.element(mobElement, center.getX(), center.getY() - yOffset)).release();
    TouchAction<?> action1 = createTouchAction().press(PointOption.point(center.getX(), center.getY())).moveTo(ElementOption.element(mobElement, center.getX(), center.getY() + yOffset)).release();
    multiTouch.add(action0).add(action1).perform();
}
Also used : MultiTouchAction(io.appium.java_client.MultiTouchAction) MobileElement(io.appium.java_client.MobileElement) Point(org.openqa.selenium.Point) PerformsTouchActions(io.appium.java_client.PerformsTouchActions) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 4 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class HtmlElement method swipe.

/**
 * Convenience method for swiping on the given element to the given direction
 *
 * @param xOffset X offset from the top-left corner of the element
 * @param yOffset Y offset from the top-left corner of the element
 * @param xMove   Movement amplitude on x axis
 * @param yMove   Movement amplitude on y axis
 */
@ReplayOnError(waitAfterAction = true)
public void swipe(int xOffset, int yOffset, int xMove, int yMove) {
    MobileElement mobElement = (MobileElement) getUnderlyingElement(getRealElementNoSearch());
    createTouchAction().press(ElementOption.element(mobElement, xOffset, yOffset)).waitAction().moveTo(ElementOption.element(mobElement, xMove, yMove)).release().perform();
}
Also used : MobileElement(io.appium.java_client.MobileElement) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Example 5 with ReplayOnError

use of com.seleniumtests.uipage.ReplayOnError in project seleniumRobot by bhecquet.

the class PictureElement method clickAt.

/**
 * Click at the coordinates xOffset, yOffset of the center of the found picture. Use negative offset to click on the left or
 * top of the picture center
 * In case the size ratio between searched picture and found picture is not 1, then, offset is
 * the source offset so that it's compatible with any screen size and resolution
 */
@ReplayOnError(replayDelayMs = 1000, waitAfterAction = true)
public void clickAt(int xOffset, int yOffset) {
    findElement();
    Point intoElementPos = intoElement.getCoordinates().onPage();
    int relativeX = detectedObjectRectangle.x + detectedObjectRectangle.width / 2 - intoElementPos.x;
    int relativeY = detectedObjectRectangle.y + detectedObjectRectangle.height / 2 - intoElementPos.y;
    moveAndClick(intoElement, relativeX + (int) (xOffset * pictureSizeRatio), relativeY + (int) (yOffset * pictureSizeRatio));
}
Also used : Point(org.openqa.selenium.Point) Point(org.openqa.selenium.Point) ReplayOnError(com.seleniumtests.uipage.ReplayOnError)

Aggregations

ReplayOnError (com.seleniumtests.uipage.ReplayOnError)24 Point (org.openqa.selenium.Point)11 WebElement (org.openqa.selenium.WebElement)7 PerformsTouchActions (io.appium.java_client.PerformsTouchActions)5 MobileElement (io.appium.java_client.MobileElement)4 ScenarioException (com.seleniumtests.customexception.ScenarioException)3 CustomEventFiringWebDriver (com.seleniumtests.driver.CustomEventFiringWebDriver)3 DriverConfig (com.seleniumtests.driver.DriverConfig)3 MultiTouchAction (io.appium.java_client.MultiTouchAction)3 ArrayList (java.util.ArrayList)3 Matcher (java.util.regex.Matcher)3 NoSuchElementException (org.openqa.selenium.NoSuchElementException)3 Actions (org.openqa.selenium.interactions.Actions)2 RemoteWebElement (org.openqa.selenium.remote.RemoteWebElement)2 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)1 Clock (java.time.Clock)1 Instant (java.time.Instant)1 InvalidElementStateException (org.openqa.selenium.InvalidElementStateException)1 Rectangle (org.openqa.selenium.Rectangle)1 TimeoutException (org.openqa.selenium.TimeoutException)1