Example usage for java.awt Robot delay

List of usage examples for java.awt Robot delay

Introduction

In this page you can find the example usage for java.awt Robot delay.

Prototype

public synchronized void delay(int ms) 

Source Link

Document

Sleeps for the specified time.

Usage

From source file:com.virtusa.isq.rft.runtime.RFTCommandBase.java

/**
 * Fires a set of java robot mouse events into the webpage.
 * /*from  ww w.j a  v a2s .  c  o  m*/
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireMouseEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = new Robot();
    final int optimumPauseBetweenKeyCombs = 10;
    final int f11KeyCode = KeyEvent.VK_F11;
    for (String fullCommand : commandSet) {
        Utils.pause(retryInterval);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];

        if ("MOVE".equalsIgnoreCase(command)) {

            String[] coords = input.split(",");
            int resolutionWidth = Integer.parseInt(coords[0]);
            int resolutionHeight = Integer.parseInt(coords[inputIndex]);
            int x = Integer.parseInt(coords[inputIndex + 1]);
            int y = Integer.parseInt(coords[inputIndex + 2]);

            int xCordinateAutual = (int) calWidth(resolutionWidth, x);
            int yCordinateAutual = (int) calHight(resolutionHeight, y);

            robot.keyPress(f11KeyCode);
            robot.delay(optimumPauseBetweenKeyCombs);
            robot.keyRelease(f11KeyCode);
            Utils.pause(retryInterval);

            // Mouse Move
            robot.mouseMove(xCordinateAutual, yCordinateAutual);

            robot.keyPress(f11KeyCode);
            Utils.pause(optimumPauseBetweenKeyCombs);
            robot.keyRelease(f11KeyCode);

        } else if ("SCROLL".equalsIgnoreCase(command)) {

            robot.mouseWheel(Integer.parseInt(input));

        } else if ("wait".equalsIgnoreCase(command)) {

            Utils.pause(Integer.parseInt(input));
        } else {
            throw new Exception("Command " + command);
        }
    }
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Performs a Java robot click on the specific coordinates. <br>
 * //w  ww.j a v a 2 s  .com
 * @param resolution
 *            the resolution
 * @param coordinates
 *            the coordinates
 * @param waitTime
 *            the wait time
 * @throws Exception
 *             the exception
 */

public final void mouseMoveAndClick(final String resolution, final String coordinates, final String waitTime)
        throws Exception {

    String res = resolution;
    final int f11KeyCode = KeyEvent.VK_F11;
    final int optimumPauseBetweenkeyCombs = 10;
    if (res.startsWith("prop=")) {

        String resolutionFromProp = getExecProps().getProperty((res.split("prop=")[1]));
        if (resolutionFromProp != null) {
            res = resolutionFromProp;
        } else {
            reportresult(true, "MOUSE MOVE AND CLICK:", "FAILED",
                    "MOUSE MOVE AND CLICK command: Invalid property key value passed : " + res);
            checkTrue(false, true, "MOUSE MOVE AND CLICK command: Invalid property key value passed : " + res);
        }
    }

    float screenWidht = 0;
    float screeHigt = 0;
    try {
        String[] resArr = res.split(",");
        screenWidht = Float.parseFloat(resArr[0]);
        screeHigt = Float.parseFloat(resArr[1]);
    } catch (Exception e) {

        getLog().error(e);
        reportresult(true, "MOUSE MOVE AND CLICK:", "FAILED",
                "MOUSE MOVE AND CLICK command: Invalid input value passed for resolution : " + res);
        checkTrue(false, true,
                "MOUSE MOVE AND CLICK command: Invalid input value passed for resolution : " + res);
    }

    String[] coordinatesArr = coordinates.split(",");
    float xCordinate = 0;
    float yCordinate = 0;
    try {
        xCordinate = Float.parseFloat(coordinatesArr[0]);
        yCordinate = Float.parseFloat(coordinatesArr[1]);
    } catch (Exception e) {

        getLog().error(e);
        reportresult(true, "MOUSE MOVE AND CLICK:", "FAILED",
                "MOUSE MOVE AND CLICK command: Invalid input value passed for coordinates : " + coordinates);
        checkTrue(false, true,
                "MOUSE MOVE AND CLICK command: Invalid input value passed for coordinates : " + coordinates);
    }
    String command = "";

    if (coordinatesArr.length > 2) {

        command = coordinatesArr[2];
    }

    Robot robot = new Robot();

    super.sleep(Integer.parseInt(waitTime));

    int xCordinateAutual = (int) calWidth(screenWidht, xCordinate);
    int yCordinateAutual = (int) calHight(screeHigt, yCordinate);

    robot.keyPress(f11KeyCode);
    robot.delay(optimumPauseBetweenkeyCombs);
    robot.keyRelease(f11KeyCode);
    sleep(retryInterval);

    // Mouse Move
    robot.mouseMove(xCordinateAutual, yCordinateAutual);

    // Click
    if ("".equals(command)) {

        robot.mousePress(InputEvent.BUTTON1_MASK);
        sleep(retryInterval);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        reportresult(true, "MOUSE MOVE AND CLICK : ", "PASSED",
                "MOUSE MOVE AND CLICK command: Resolution : " + res);

    } else if ("dclick".equals(command.toLowerCase(Locale.getDefault()))) {

        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        final int optimumPauseBetweenDclick = 500;
        robot.delay(optimumPauseBetweenDclick);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        reportresult(true, "MOUSE MOVE AND DOUBLE CLICK : ", "PASSED",
                "MOUSE MOVE AND DOUBLE CLICK command: Resolution: " + res);
        checkTrue(false, true, "MOUSE MOVE AND CLICK command: Resolution: " + res);

    }

    robot.keyPress(f11KeyCode);
    robot.delay(optimumPauseBetweenkeyCombs);
    robot.keyRelease(f11KeyCode);
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Fires a set of java robot mouse events into the webpage.
 * //ww  w .  ja  v  a 2 s .co m
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireMouseEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = getRobot();
    final int optimumPauseBetweenKeyCombs = 10;
    final int f11KeyCode = KeyEvent.VK_F11;
    for (String fullCommand : commandSet) {
        sleep(retryInterval);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];

        if ("MOVE".equalsIgnoreCase(command)) {

            String[] coords = input.split(",");
            int resolutionWidth = Integer.parseInt(coords[0]);
            int resolutionHeight = Integer.parseInt(coords[inputIndex]);
            int x = Integer.parseInt(coords[inputIndex + 1]);
            int y = Integer.parseInt(coords[inputIndex + 2]);

            int xCordinateAutual = (int) calWidth(resolutionWidth, x);
            int yCordinateAutual = (int) calHight(resolutionHeight, y);

            robot.keyPress(f11KeyCode);
            robot.delay(optimumPauseBetweenKeyCombs);
            robot.keyRelease(f11KeyCode);
            sleep(retryInterval);

            // Mouse Move
            robot.mouseMove(xCordinateAutual, yCordinateAutual);

            robot.keyPress(f11KeyCode);
            sleep(optimumPauseBetweenKeyCombs);
            robot.keyRelease(f11KeyCode);

        } else if ("SCROLL".equalsIgnoreCase(command)) {

            robot.mouseWheel(Integer.parseInt(input));

        } else if ("wait".equalsIgnoreCase(command)) {

            super.sleep(Integer.parseInt(input));
        } else {
            throw new Exception("Command " + command);
        }
    }
}

From source file:org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.java

public static void uploadFileWithJavaRobot(String FilePath, String FileName) throws Exception {
    StringSelection sel = new StringSelection(FilePath + FileName);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
    Thread.sleep(1000);/*w  ww .j a  v a 2 s .c o m*/
    Robot robot = new Robot();
    robot.delay(1000);

    // Release Enter
    robot.keyRelease(KeyEvent.VK_ENTER);

    // Press CTRL+V
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);

    // Release CTRL+V
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_V);
    Thread.sleep(1000);

    // Press Enter
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    Thread.sleep(3000);
}