Example usage for org.openqa.selenium.interactions.touch TouchActions up

List of usage examples for org.openqa.selenium.interactions.touch TouchActions up

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions.touch TouchActions up.

Prototype

public TouchActions up(int x, int y) 

Source Link

Document

Allows the execution of the gesture 'up' on the screen.

Usage

From source file:jp.co.nssol.h5.test.selenium.testcase.TouchTest.java

License:Apache License

public void touchActionsDoubleTap() throws InterruptedException, MalformedURLException {
    TouchActions touch = new TouchActions(getDriver());
    touch.singleTap(getElementsByClassName("backgroundPiece").get(0));
    touch.singleTap(getElementById("load"));
    touch.singleTap(getElementById("drawModeSwitch"));
    touch.build().perform();//w  w  w. java2 s.c o  m

    TouchActions touch2 = new TouchActions(getDriver());

    Thread.sleep(1000);

    // O
    touch2.down(300, 450);
    touch2.move(280, 470);
    touch2.move(280, 550);
    touch2.move(300, 570);
    touch2.move(340, 570);
    touch2.move(360, 550);
    touch2.move(360, 470);
    touch2.move(340, 450);
    touch2.move(300, 450);
    touch2.up(300, 450);

    // K
    touch2.down(450, 450);
    touch2.move(450, 570);
    touch2.up(450, 570);
    touch2.down(450, 510);
    touch2.move(520, 450);
    touch2.up(520, 450);
    touch2.down(450, 510);
    touch2.move(520, 570);
    touch2.up(520, 570);
    touch2.build().perform();

    takeScreenShot();
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

public static void longtap(WebDriver driver, WebElement element) {
    if (driver instanceof HasTouchScreen) {
        TouchActions longtap = new TouchActions(driver);
        Point center = getCenter(element);
        longtap.down(center.getX(), center.getY());
        longtap.perform();//w ww.  j  a  v a 2s  .  com
        try {
            Thread.sleep(750);
        } catch (InterruptedException e) {
        }
        longtap.up(center.getX(), center.getY());
        longtap.perform();
    } else {
        Locatable locatable = (Locatable) element;
        Coordinates coords = locatable.getCoordinates();
        Mouse mouse = ((HasInputDevices) driver).getMouse();
        mouse.mouseDown(coords);
        try {
            Thread.sleep(750);
        } catch (InterruptedException e) {
        }
        mouse.mouseUp(coords);
    }
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

public static void track(WebDriver driver, WebElement element, int x, int y, int step) {
    if (driver instanceof HasTouchScreen) {
        if (step == 0) {
            step = 1;/*w ww.j av a  2  s .com*/
            // TODO: no move if step == 0
        }

        Point center = getCenter(element);

        int posX = center.getX();
        int posY = center.getY();

        int endX = posX + x;
        int endY = posY + y;

        TouchActions touchAction = new TouchActions(driver);
        touchAction.down(posX, posY);

        while ((x < 0 && posX > endX || x > 0 && posX < endX)
                || (y < 0 && posY > endY || y > 0 && posY < endY)) {
            if (x > 0 && posX < endX) {
                if (posX + step > endX) {
                    posX += endX - (posX + step);
                } else {
                    posX += step;
                }
            }

            else if (x < 0 && posX > endX) {
                if (posX - step < endX) {
                    posX -= endX + (posX - step);
                } else {
                    posX -= step;
                }
            }

            if (y > 0 && posY < endY) {
                if (posY + step > endY) {
                    posY += endY - (posY + step);
                } else {
                    posY += step;
                }
            }

            else if (y < 0 && posY > endY) {
                if (posY - step < endY) {
                    posY -= endY + (posY - step);
                } else {
                    posY -= step;
                }
            }

            touchAction.move(posX, posY);
        }

        touchAction.up(posX, posY).perform();
    } else {
        Actions mouseAction = new Actions(driver);
        mouseAction.dragAndDropBy(element, x, y);
    }
}