Example usage for org.openqa.selenium.remote RemoteWebDriver getKeyboard

List of usage examples for org.openqa.selenium.remote RemoteWebDriver getKeyboard

Introduction

In this page you can find the example usage for org.openqa.selenium.remote RemoteWebDriver getKeyboard.

Prototype

@Override
    public Keyboard getKeyboard() 

Source Link

Usage

From source file:com.comcast.dawg.house.LoginPageIT.java

License:Apache License

private void loginWithUserName(RemoteWebDriver driver, String user) {
    driver.findElementById(LoginPage.USER_INPUT_ID).click();
    driver.getKeyboard().sendKeys(user);
    driver.getKeyboard().pressKey(Keys.ENTER);
}

From source file:com.screenslicer.core.service.HttpStatus.java

License:Open Source License

public static int status(RemoteWebDriver driver, boolean wait) {
    if (WebApp.DEBUG) {
        System.out.println("check status...");
    }//from ww w . jav  a 2s .c  om
    int totalWait = 0;
    String src = null;
    while (totalWait < TIMEOUT) {
        src = null;
        try {
            src = driver.getPageSource();
            if (!CommonUtil.isEmpty(src)) {
                synchronized (lock) {
                    prevLen = len;
                    len = src.length();
                }
            }
        } catch (Throwable t) {
            synchronized (lock) {
                src = null;
                prevLen = 0;
                len = 0;
            }
            Log.exception(t);
        }
        if (WebApp.DEBUG) {
            synchronized (lock) {
                System.out.println("status=" + status);
            }
        }
        synchronized (lock) {
            if (status != 0) {
                break;
            }
        }
        boolean validLen;
        synchronized (lock) {
            validLen = prevLen == len && len > MIN_LEN;
        }
        if (validLen && hasContent(null, src)) {
            try {
                driver.getKeyboard().sendKeys(Keys.ESCAPE);
            } catch (Throwable t) {
                Log.exception(t);
            }
            Util.driverSleepVeryShort();
            if (!hasContent(driver, src)) {
                synchronized (lock) {
                    status = 204;
                }
            }
            break;
        }
        if (wait) {
            if (WebApp.DEBUG) {
                System.out.println("waiting for status...");
            }
            try {
                Thread.sleep(SLEEP);
            } catch (InterruptedException e) {
                Log.exception(e);
            }
            totalWait += SLEEP;
        } else {
            break;
        }
    }
    int myStatus;
    synchronized (lock) {
        myStatus = status;
        status = -1;
    }
    return myStatus;
}

From source file:com.screenslicer.core.util.Util.java

License:Open Source License

public static void get(RemoteWebDriver driver, String url, Node urlNode, boolean retry) throws ActionFailed {
    boolean exception = true;
    boolean success = true;
    String origHandle = null;/*w  w  w  .j  a va 2  s. c om*/
    try {
        String source = null;
        boolean badUrl = true;
        boolean statusFail = true;
        if (urlNode != null) {
            origHandle = driver.getWindowHandle();
        }
        for (int i = 0; i < REFRESH_TRIES
                && (badUrl || statusFail || exception || CommonUtil.isEmpty(source)); i++) {
            badUrl = false;
            statusFail = false;
            exception = false;
            source = null;
            if (WebApp.DEBUG) {
                System.out.println("getting url...");
            }
            try {
                driver.getKeyboard().sendKeys(Keys.ESCAPE);
            } catch (Throwable t) {
                Log.exception(t);
            }
            if (urlNode != null) {
                try {
                    cleanUpNewWindows(driver, origHandle);
                } catch (Throwable t) {
                    Log.exception(t);
                }
            }
            try {
                Util.driverSleepVeryShort();
                if (urlNode != null) {
                    try {
                        Util.clickToNewWindow(driver, toElement(driver, urlNode));
                        Set<String> newHandles = driver.getWindowHandles();
                        for (String newHandle : newHandles) {
                            if (!origHandle.equals(newHandle)) {
                                driver.switchTo().window(newHandle);
                                break;
                            }
                        }
                    } catch (Throwable t) {
                        exception = true;
                        Log.exception(t);
                        Util.cleanUpNewWindows(driver, origHandle);
                    }
                } else {
                    driver.get("about:blank");
                    try {
                        driver.get(url);
                    } catch (TimeoutException e) {
                        Log.exception(e);
                    }
                }
                if (!exception) {
                    Util.driverSleepShort();
                    Util.driverSleepLong();
                    statusFail = HttpStatus.status(driver, urlNode != null) != 200;
                    driver.switchTo().defaultContent();
                    source = driver.getPageSource();
                    try {
                        new URL(driver.getCurrentUrl());
                        badUrl = false;
                    } catch (Throwable t) {
                        badUrl = true;
                    }
                }
            } catch (Throwable t) {
                Log.exception(t);
                exception = true;
            }
            if ((!retry || i + 1 == REFRESH_TRIES)
                    && (badUrl || statusFail || exception || CommonUtil.isEmpty(source))) {
                try {
                    driver.getKeyboard().sendKeys(Keys.ESCAPE);
                    Util.driverSleepVeryShort();
                } catch (Throwable t) {
                    Log.exception(t);
                }
                success = false;
                if (!retry) {
                    break;
                }
            }
        }
        if (WebApp.DEBUG) {
            System.out.println("getting url - done");
        }
    } catch (Throwable t) {
        Log.exception(t);
        success = false;
    }
    if (!success) {
        if (urlNode != null && origHandle != null) {
            try {
                cleanUpNewWindows(driver, origHandle);
            } catch (Throwable t) {
                Log.exception(t);
            }
        }
        throw new ActionFailed();
    }
}

From source file:com.screenslicer.core.util.Util.java

License:Open Source License

public static String newWindow(RemoteWebDriver driver) throws ActionFailed {
    try {// w  w  w .  j  a  v a 2  s. c  om
        String origHandle = driver.getWindowHandle();
        cleanUpNewWindows(driver, origHandle);
        try {
            driver.getKeyboard().sendKeys(Keys.chord(Keys.CONTROL + "n"));
        } catch (Throwable t) {
            Log.exception(t);
        }
        Util.driverSleepStartup();
        Collection<String> handles = new HashSet<String>(driver.getWindowHandles());
        handles.remove(origHandle);
        if (!handles.isEmpty()) {
            driver.switchTo().window(handles.iterator().next());
        } else {
            driver.executeScript("window.open('');");
            Util.driverSleepStartup();
            handles = new HashSet<String>(driver.getWindowHandles());
            handles.remove(origHandle);
            if (!handles.isEmpty()) {
                driver.switchTo().window(handles.iterator().next());
            }
        }
        return driver.getWindowHandle();
    } catch (Throwable t) {
        Log.exception(t);
        throw new ActionFailed(t);
    }
}

From source file:com.screenslicer.core.util.Util.java

License:Open Source License

private static boolean click(RemoteWebDriver driver, WebElement toClick, boolean shift) {
    try {/*  w ww.  ja va  2  s.c  o  m*/
        Actions action = new Actions(driver);
        driverSleepVeryShort();
        action.moveToElement(toClick).perform();
        if (shift) {
            driver.getKeyboard().pressKey(Keys.SHIFT);
        }
        toClick.click();
        if (shift) {
            driver.getKeyboard().releaseKey(Keys.SHIFT);
        }
        Util.driverSleepVeryShort();
    } catch (Throwable t) {
        return false;
    }
    return true;
}