Example usage for org.openqa.selenium Keys COMMAND

List of usage examples for org.openqa.selenium Keys COMMAND

Introduction

In this page you can find the example usage for org.openqa.selenium Keys COMMAND.

Prototype

Keys COMMAND

To view the source code for org.openqa.selenium Keys COMMAND.

Click Source Link

Usage

From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java

License:Open Source License

public void zoomIn(int times) {
    WebElement html = driver.findElement(By.tagName("html"));

    for (int i = 0; i < times; i++) {
        if (isMacOS()) {
            html.sendKeys(Keys.chord(Keys.COMMAND, Keys.ADD));
        } else {//from   w w  w . j av  a 2s .  c o m
            html.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));
        }
    }
}

From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java

License:Open Source License

public void zoomOut(int times) {
    WebElement html = driver.findElement(By.tagName("html"));

    for (int i = 0; i < times; i++) {
        if (isMacOS()) {
            html.sendKeys(Keys.chord(Keys.COMMAND, Keys.SUBTRACT));
        } else {//from   ww  w. j  a  va2s .  c o  m
            html.sendKeys(Keys.chord(Keys.CONTROL, Keys.SUBTRACT));
        }
    }
}

From source file:org.nuxeo.ftest.cap.ITSafeEditTest.java

License:Apache License

/**
 * This methods checks that once a simple html input is changed within a page, the new value is stored in the
 * browser local storage in case of accidental loose (crash, freeze, network failure). The value can then be
 * restored from the local storage when re-editing the page afterwards.
 *
 * @since 5.7.1//w ww .  j  a va 2 s  .  co  m
 */
@Test
public void testAutoSaveOnChangeAndRestore() throws Exception {
    if (!runTestForBrowser()) {
        log.warn("Browser not supported. Nothing to run.");
        return;
    }

    WebElement descriptionElt, titleElt;
    login(TEST_USERNAME, TEST_PASSWORD);
    open(String.format(NXDOC_URL_FORMAT, wsId));

    DocumentBasePage documentBasePage = asPage(DocumentBasePage.class);
    documentBasePage.getEditTab();

    LocalStorage localStorage = new LocalStorage(driver);
    localStorage.clearLocalStorage();
    String currentDocumentId = getCurrentDocumentId();

    descriptionElt = driver.findElement(By.name(DESCRIPTION_ELT_ID));
    titleElt = driver.findElement(By.name(TITLE_ELT_ID));
    log.debug("1 - " + localStorage.getLocalStorageLength());

    // We change the value of the title
    Keys ctrlKey = Keys.CONTROL;
    if (Platform.MAC.equals(driver.getCapabilities().getPlatform())) {
        ctrlKey = Keys.COMMAND;
    }
    titleElt.click();
    titleElt.sendKeys(Keys.chord(ctrlKey, "a") + Keys.DELETE + NEW_WORKSPACE_TITLE);
    // weird thing in webdriver: we need to call clear on an input of the
    // form to fire an onchange event
    Locator.scrollToElement(descriptionElt);
    descriptionElt.click();
    descriptionElt.clear();
    log.debug("2 - " + localStorage.getLocalStorageLength());

    // avoid randoms: wait for the local storage to actually hold the saved values after 10s
    Locator.waitUntilGivenFunction(input -> {
        LocalStorage ls = new LocalStorage(driver);
        String content = ls.getItemFromLocalStorage(wsId);
        log.debug(content);
        return content != null && content.contains(NEW_WORKSPACE_TITLE);
    });

    // Now must have something saved in the localstorage
    String lsItem = localStorage.getItemFromLocalStorage(currentDocumentId);
    final String lookupString = "\"" + TITLE_ELT_ID + "\":\"" + NEW_WORKSPACE_TITLE + "\"";

    assertTrue(lsItem != null && lsItem.length() > 0);
    assertTrue(lsItem.contains(lookupString));

    // Let's leave the edit tab of the workspace with unsaved changes. A
    // popup should also prevent us from doing that, let's bypass it for tests
    log.debug("3 - " + localStorage.getLocalStorageLength());
    bypassPopup();
    driver.findElement(By.linkText("Sections")).click();
    log.debug("4 - " + localStorage.getLocalStorageLength());

    // Get back to edit tab. Since we didn't save, the title must be the initial one.
    open(String.format(NXDOC_URL_FORMAT, wsId));
    documentBasePage = asPage(DocumentBasePage.class);
    documentBasePage.getEditTab();
    localStorage = new LocalStorage(driver);
    titleElt = Locator.findElementWithTimeout(By.name(TITLE_ELT_ID));
    String titleEltValue = titleElt.getAttribute("value");
    assertEquals(WORKSPACE_TITLE, titleEltValue);
    log.debug("5 - " + localStorage.getLocalStorageLength());

    // We must find in the localstorage an entry matching the previous
    // document which contains the title we edited
    lsItem = localStorage.getItemFromLocalStorage(currentDocumentId);
    assertNotNull(lsItem);
    assertTrue(lsItem.contains(lookupString));
    log.debug("6 - " + localStorage.getLocalStorageLength());

    checkSafeEditRestoreProvided();

    triggerSafeEditRestore();

    // We check that the title value has actually been restored
    titleElt = driver.findElement(By.name(TITLE_ELT_ID));
    titleEltValue = titleElt.getAttribute("value");
    assertEquals(NEW_WORKSPACE_TITLE, titleEltValue);

    // try to leave again
    if (documentBasePage.useAjaxTabs()) {
        AjaxRequestManager arm = new AjaxRequestManager(driver);
        arm.begin();
        documentBasePage.clickOnDocumentTabLink(documentBasePage.contentTabLink, false);
        leaveTabPopup(false);
        arm.end();
    } else {
        documentBasePage.clickOnDocumentTabLink(documentBasePage.contentTabLink, false);
        leavePagePopup(false);
    }

    driver.findElement(By.linkText("Sections")).click();
    leavePagePopup(true);

    logout();
}

From source file:org.nuxeo.functionaltests.ITSafeEditTest.java

License:Open Source License

/**
 * This methods checks that once a simple html input is changed within a
 * page, the new value is stored in the browser local storage in case of
 * accidental loose (crash, freeze, network failure). The value can then be
 * restored from the local storage when re-editing the page afterwards.
 *
 * @since 5.7.1/*from w  ww . j av  a 2s. c  o  m*/
 */
@Test
public void testAutoSaveOnChangeAndRestore() throws Exception {

    if (!runTestForBrowser()) {
        log.warn("Browser not supported. Nothing to run.");
        return;
    }

    prepare();

    DocumentBasePage documentBasePage;
    WebElement descriptionElt, titleElt;

    // Log as test user and edit the created workdspace
    documentBasePage = login(USERNAME, PASSWORD).getContentTab().goToDocument("Workspaces").getContentTab()
            .goToDocument(WORKSPACE_TITLE);
    documentBasePage.getEditTab();

    LocalStorage localStorage = new LocalStorage(driver);
    localStorage.clearLocalStorage();
    String currentDocumentId = getCurrentDocumentId();

    descriptionElt = driver.findElement(By.name(DESCRIPTION_ELT_ID));
    titleElt = driver.findElement(By.name(TITLE_ELT_ID));
    log.debug("1 - " + localStorage.getLocalStorageLength());

    // We change the value of the title
    Keys ctrlKey = Keys.CONTROL;
    if (Platform.MAC.equals(driver.getCapabilities().getPlatform())) {
        ctrlKey = Keys.COMMAND;
    }
    titleElt.click();
    titleElt.sendKeys(Keys.chord(ctrlKey, "a") + Keys.DELETE + NEW_WORKSPACE_TITLE);
    // weird thing in webdriver: we need to call clear on an input of the
    // form to fire an onchange event
    descriptionElt.click();
    descriptionElt.clear();
    log.debug("2 - " + localStorage.getLocalStorageLength());

    // Now must have something saved in the localstorage
    String lsItem = localStorage.getItemFromLocalStorage(currentDocumentId);
    final String lookupString = "\"" + TITLE_ELT_ID + "\":\"" + NEW_WORKSPACE_TITLE + "\"";

    assertTrue(lsItem != null && lsItem.length() > 0);
    assertTrue(lsItem.contains(lookupString));

    // Let's leave the edit tab of the workspace with unsaved changes. A
    // popup should prevent us from doing that
    try {
        documentBasePage.getContentTab();
        // Should never occur
        fail("There are unsaved modifications pending and the page can only be left after clicking \"Leave this page\"");
    } catch (UnhandledAlertException e) {
        // Expected behavior
        // The following is a workaround to by pass the popup windows which
        // is supposed to prevent the user from leaving the page with
        // unsaved modifications
        log.debug("3 - " + localStorage.getLocalStorageLength());
        byPassLeavePagePopup();
        log.debug("4 - " + localStorage.getLocalStorageLength());
    }

    // We leave the page and get back to it. Since we didn't save, the
    // title must be the initial one.
    documentBasePage.getContentTab();
    documentBasePage.getEditTab();
    localStorage = new LocalStorage(driver);
    titleElt = findElementWithTimeout(By.name(TITLE_ELT_ID));
    String titleEltValue = titleElt.getAttribute("value");
    assertTrue(titleEltValue.equals(WORKSPACE_TITLE));
    log.debug("5 - " + localStorage.getLocalStorageLength());

    // We must find in the localstorage an entry matching the previous
    // document which contains the title we edited
    lsItem = localStorage.getItemFromLocalStorage(currentDocumentId);
    assertTrue(lsItem.contains(lookupString));
    log.debug("6 - " + localStorage.getLocalStorageLength());

    checkSafeEditRestoreProvided();

    triggerSafeEditResotre();

    // We check that the title value has actually been restored
    titleElt = driver.findElement(By.name(TITLE_ELT_ID));
    titleEltValue = titleElt.getAttribute("value");
    assertTrue(titleEltValue.equals(NEW_WORKSPACE_TITLE));

    byPassLeavePagePopup();
    documentBasePage.getContentTab();
    logout();

    restoreSate();
}

From source file:org.safs.selenium.webdriver.lib.WDLibrary.java

License:Open Source License

/**
 * Convert a Java KEYCODE to a Selenium WebDriver Keys Enum
 * @param keycode int, a java keycode//from   ww w.  ja va  2 s .co  m
 * @return Keys enum for (primarily) non-printable (control) characters, or null.
 */
public static Keys convertToKeys(int keycode) {
    Keys key = null;
    switch (keycode) {
    case java.awt.event.KeyEvent.VK_ADD:
        key = Keys.ADD;
        break;
    case java.awt.event.KeyEvent.VK_ALT:
        key = Keys.ALT;
        break;
    case java.awt.event.KeyEvent.VK_KP_DOWN:
        key = Keys.ARROW_DOWN;
        break;
    case java.awt.event.KeyEvent.VK_KP_LEFT:
        key = Keys.ARROW_LEFT;
        break;
    case java.awt.event.KeyEvent.VK_KP_RIGHT:
        key = Keys.ARROW_RIGHT;
        break;
    case java.awt.event.KeyEvent.VK_KP_UP:
        key = Keys.ARROW_UP;
        break;
    case java.awt.event.KeyEvent.VK_BACK_SPACE:
        key = Keys.BACK_SPACE;
        break;
    case java.awt.event.KeyEvent.VK_CANCEL:
        key = Keys.CANCEL;
        break;
    case java.awt.event.KeyEvent.VK_CLEAR:
        key = Keys.CLEAR;
        break;
    case java.awt.event.KeyEvent.VK_WINDOWS:
        key = Keys.COMMAND;
        break;
    case java.awt.event.KeyEvent.VK_CONTROL:
        key = Keys.CONTROL;
        break;
    case java.awt.event.KeyEvent.VK_DECIMAL:
        key = Keys.DECIMAL;
        break;
    case java.awt.event.KeyEvent.VK_DELETE:
        key = Keys.DELETE;
        break;
    case java.awt.event.KeyEvent.VK_DIVIDE:
        key = Keys.DIVIDE;
        break;
    case java.awt.event.KeyEvent.VK_DOWN:
        key = Keys.DOWN;
        break;
    case java.awt.event.KeyEvent.VK_END:
        key = Keys.END;
        break;
    case java.awt.event.KeyEvent.VK_ENTER:
        key = Keys.ENTER;
        break;
    case java.awt.event.KeyEvent.VK_EQUALS:
        key = Keys.EQUALS;
        break;
    case java.awt.event.KeyEvent.VK_ESCAPE:
        key = Keys.ESCAPE;
        break;
    case java.awt.event.KeyEvent.VK_F1:
        key = Keys.F1;
        break;
    case java.awt.event.KeyEvent.VK_F2:
        key = Keys.F2;
        break;
    case java.awt.event.KeyEvent.VK_F3:
        key = Keys.F3;
        break;
    case java.awt.event.KeyEvent.VK_F4:
        key = Keys.F4;
        break;
    case java.awt.event.KeyEvent.VK_F5:
        key = Keys.F5;
        break;
    case java.awt.event.KeyEvent.VK_F6:
        key = Keys.F6;
        break;
    case java.awt.event.KeyEvent.VK_F7:
        key = Keys.F7;
        break;
    case java.awt.event.KeyEvent.VK_F8:
        key = Keys.F8;
        break;
    case java.awt.event.KeyEvent.VK_F9:
        key = Keys.F9;
        break;
    case java.awt.event.KeyEvent.VK_F10:
        key = Keys.F10;
        break;
    case java.awt.event.KeyEvent.VK_F11:
        key = Keys.F11;
        break;
    case java.awt.event.KeyEvent.VK_F12:
        key = Keys.F12;
        break;
    case java.awt.event.KeyEvent.VK_HELP:
        key = Keys.HELP;
        break;
    case java.awt.event.KeyEvent.VK_HOME:
        key = Keys.HOME;
        break;
    case java.awt.event.KeyEvent.VK_INSERT:
        key = Keys.INSERT;
        break;
    case java.awt.event.KeyEvent.VK_LEFT:
        key = Keys.LEFT;
        break;
    case java.awt.event.KeyEvent.VK_META:
        key = Keys.META;
        break;
    case java.awt.event.KeyEvent.VK_MULTIPLY:
        key = Keys.MULTIPLY;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD0:
        key = Keys.NUMPAD0;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD1:
        key = Keys.NUMPAD1;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD2:
        key = Keys.NUMPAD2;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD3:
        key = Keys.NUMPAD3;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD4:
        key = Keys.NUMPAD4;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD5:
        key = Keys.NUMPAD5;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD6:
        key = Keys.NUMPAD6;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD7:
        key = Keys.NUMPAD7;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD8:
        key = Keys.NUMPAD8;
        break;
    case java.awt.event.KeyEvent.VK_NUMPAD9:
        key = Keys.NUMPAD9;
        break;
    case java.awt.event.KeyEvent.VK_PAGE_DOWN:
        key = Keys.PAGE_DOWN;
        break;
    case java.awt.event.KeyEvent.VK_PAGE_UP:
        key = Keys.PAGE_UP;
        break;
    case java.awt.event.KeyEvent.VK_PAUSE:
        key = Keys.PAUSE;
        break;
    case java.awt.event.KeyEvent.VK_RIGHT:
        key = Keys.RIGHT;
        break;
    case java.awt.event.KeyEvent.VK_SEMICOLON:
        key = Keys.SEMICOLON;
        break;
    case java.awt.event.KeyEvent.VK_SEPARATOR:
        key = Keys.SEPARATOR;
        break;
    case java.awt.event.KeyEvent.VK_SHIFT:
        key = Keys.SHIFT;
        break;
    case java.awt.event.KeyEvent.VK_SPACE:
        key = Keys.SPACE;
        break;
    case java.awt.event.KeyEvent.VK_SUBTRACT:
        key = Keys.SUBTRACT;
        break;
    case java.awt.event.KeyEvent.VK_TAB:
        key = Keys.TAB;
        break;
    case java.awt.event.KeyEvent.VK_UP:
        key = Keys.UP;
        break;
    }
    return key;
}