Example usage for java.awt Robot keyRelease

List of usage examples for java.awt Robot keyRelease

Introduction

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

Prototype

public synchronized void keyRelease(int keycode) 

Source Link

Document

Releases a given key.

Usage

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

/**
 * Get the selected text in webpage to the clipboard and compare the value
 * with the given input./*from w ww.  j a va2  s.  c o  m*/
 * 
 * @param value
 *            the value
 * @throws Exception
 *             the exception
 */

private void fireEventVerifyValue(final String value) throws Exception {

    String clipBoardText = "";
    Robot robot = new Robot();

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    Utils.pause(retryInterval);
    Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

    try {
        if (trans != null) {
            clipBoardText = (String) trans.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (clipBoardText.equals(value)) {

        reportResults(ReportLogger.ReportLevel.SUCCESS, "Fire Event", "Success",
                "Verify value passed. Value : " + value);

    } else {

        reportResults(true, ReportLogger.ReportLevel.FAILURE, "Fire Event", "Error",
                "Verify value match expected. ::: " + "Expected value : " + value + " Actual value : "
                        + clipBoardText);
    }
}

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

/**
 * Do type./*from w ww  .  j  a  v a 2 s.  c om*/
 * 
 * @param keyCodes
 *            the key codes
 * @param offset
 *            the offset
 * @param length
 *            the length
 */
private void doTypeKeys(final int[] keyCodes, final int offset, final int length) {
    if (length == 0) {
        return;
    }
    try {
        Robot robot = new Robot();
        robot.keyPress(keyCodes[offset]);
        doTypeKeys(keyCodes, offset + 1, length - 1);
        robot.keyRelease(keyCodes[offset]);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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

/**
 * Performs a Java robot click on the specific coordinates. <br>
 * /*  ww  w. j  a  va 2  s  .  c om*/
 * @param resolution
 *            the resolution
 * @param coordinates
 *            the coordinates
 * @param waitTime
 *            the wait time
 * @throws Exception
 *             the exception
 */
@Override
public final void mouseMoveAndClick(final String resolution, final String coordinates, final String waitTime) {

    String res = resolution;
    final int f11KeyCode = KeyEvent.VK_F11;
    final int optimumPauseBetweenkeyCombs = 10;
    String[] resArr = res.split(",");
    String[] coordinatesArr = coordinates.split(",");

    float screenWidht = Float.parseFloat(resArr[0]);
    float screeHigt = Float.parseFloat(resArr[1]);
    float xCordinate = Float.parseFloat(coordinatesArr[0]);
    float yCordinate = Float.parseFloat(coordinatesArr[1]);
    String command = "";

    if (coordinatesArr.length > 2) {

        command = coordinatesArr[2];
    }

    Robot robot = null;
    try {
        robot = new Robot();
    } catch (AWTException e) {
        e.printStackTrace();
    }

    Utils.pause(Integer.parseInt(waitTime));

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

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

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

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

        robot.mousePress(InputEvent.BUTTON1_MASK);
        Utils.pause(retryInterval);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);

        reportResults(ReportLogger.ReportLevel.SUCCESS, "Mouse Move And Click", "Success",
                "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);

        reportResults(true, ReportLogger.ReportLevel.SUCCESS, "Mouse Move And Click", "Success",
                "Resolution : " + res);

    }

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

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

/**
 * Fires a set of java robot key events into the webpage.
 * /*from  w w w.  j  ava  2s . c o m*/
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireKeyEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = new Robot();
    for (String fullCommand : commandSet) {
        Utils.pause(retryInterval / 2);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            StringSelection stringSelection = new StringSelection(input);
            clipboard.setContents(stringSelection, null);

            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);

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

            type(input);
        } else if ("wait".equalsIgnoreCase(command)) {

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

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

/**
 * Fires a set of java robot mouse events into the webpage.
 * /*  w  w w  .  j  av  a  2  s .  com*/
 * @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.photon.phresco.Screens.InvalidJarBase.java

public void instantiateBrowser(String selectedBrowser, String selectedPlatform, String applicationURL,
        String applicationContext) throws ScreenException, MalformedURLException {

    if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_CHROME)) {
        try {/*from   ww  w .  j ava 2s  .c  om*/
            // "D:/Selenium-jar/chromedriver_win_19.0.1068.0/chromedriver.exe"
            chromeService = new ChromeDriverService.Builder()
                    .usingDriverExecutable(new File(getChromeLocation())).usingAnyFreePort().build();

            log.info("-------------***LAUNCHING GOOGLECHROME***--------------");

            driver = new ChromeDriver(chromeService);
            //driver.manage().window().maximize();
            //   driver = new ChromeDriver(chromeService, chromeOption);
            // driver.manage().timeouts().implicitlyWait(30,
            // TimeUnit.SECONDS);            
            //driver.navigate().to(applicationURL + applicationContext);
            driver.manage().window().maximize();
            driver.navigate().to(applicationURL + applicationContext);

        } catch (Exception e) {
            e.printStackTrace();
        }

    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_IE)) {
        log.info("---------------***LAUNCHING INTERNET EXPLORE***-----------");
        driver = new InternetExplorerDriver();
        driver.manage().window().maximize();
        driver.navigate().to(applicationURL + applicationContext);

    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_FIREFOX)) {
        log.info("-------------***LAUNCHING FIREFOX***--------------");
        driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.navigate().to(applicationURL + applicationContext);

    } else if (selectedBrowser.equalsIgnoreCase(Constants.BROWSER_OPERA)) {
        log.info("-------------***LAUNCHING OPERA***--------------");
        System.out.println("******entering window maximize********");
        try {
            System.out.println("******entering window maximize********");
            Robot robot;
            try {
                robot = new Robot();
                robot.keyPress(KeyEvent.VK_ALT);
                robot.keyPress(KeyEvent.VK_SPACE);
                robot.keyRelease(KeyEvent.VK_ALT);
                robot.keyRelease(KeyEvent.VK_SPACE);
                robot.keyPress(KeyEvent.VK_X);
                robot.keyRelease(KeyEvent.VK_X);
            } catch (AWTException e) {

                e.printStackTrace();
            }

        } catch (Exception e) {

            e.printStackTrace();
        }

    } else {
        throw new ScreenException("------Only FireFox,InternetExplore and Chrome works-----------");
    }

}

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

/**
 * Get the selected text in webpage to the clipboard and compare the value
 * with the given input./*from  ww  w  .ja  v  a 2 s .co  m*/
 * 
 * @param value
 *            the value
 * @throws Exception
 *             the exception
 */

private void fireEventVerifyValue(final String value) throws Exception {

    String clipBoardText = "";
    Robot robot = getRobot();

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    sleep(retryInterval);
    Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

    try {
        if (trans != null) {
            clipBoardText = (String) trans.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (clipBoardText.equals(value)) {

        reportresult(true, "FIRE EVENT : VERIFY VALUE " + value + "", "PASSED", "");
    } else {

        reportresult(true, "FIRE EVENT : VERIFY VALUE " + value + "", "FAILED",
                "FIRE EVENT : VERIFY VALUE : value match expected. Actual : " + clipBoardText + " Expected : "
                        + value + "");
        checkTrue(false, true, "FIRE EVENT : VERIFY VALUE : value match expected. Actual : " + clipBoardText
                + " Expected : " + value + "");
    }
}

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

/**
 * Do type.//from ww w  .j  a  v a2 s  . c  o  m
 * 
 * @param keyCodes
 *            the key codes
 * @param offset
 *            the offset
 * @param length
 *            the length
 */
private void doTypeKeys(final int[] keyCodes, final int offset, final int length) {
    if (length == 0) {
        return;
    }
    Robot robot = getRobot();
    try {
        robot.keyPress(keyCodes[offset]);
        doTypeKeys(keyCodes, offset + 1, length - 1);
        robot.keyRelease(keyCodes[offset]);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

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

/**
 * Performs a Java robot click on the specific coordinates. <br>
 * /*from www.ja va 2 s . c  o  m*/
 * @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 key events into the webpage.
 * /*from  w w  w . jav  a2  s  . com*/
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireKeyEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = getRobot();
    for (String fullCommand : commandSet) {
        sleep(retryInterval / 2);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {

            StringSelection stringSelection = new StringSelection(input);
            clipboard.setContents(stringSelection, null);

            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);

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

            type(input);
        } else if ("wait".equalsIgnoreCase(command)) {

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