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:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java

License:Open Source License

public void runInputRichTextTest(String useCase, String boldOpen, String boldClose, String italicsOpen,
        String italicsClose, String elementToClickXpath) {

    // 1. Navigate to the appropriate "inputRichText" use case.
    BrowserDriver browserDriver = getBrowserDriver();
    navigateToUseCase(browserDriver, "inputRichText", useCase);

    // 2. Verify that the rich text editor is visible.
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementDisplayed(INPUT_RICH_TEXT_DIV_XPATH);

    if (isCheckboxDisplayedAndEnabled(browserDriver, "rendered")) {

        // 3. Click the *Rendered* checkbox.
        browserDriver.clickElement(RENDERED_CHECKBOX_XPATH);

        // 4. Verify that the rich text editor is not visible.
        waitingAsserter.assertElementNotDisplayed(INPUT_RICH_TEXT_DIV_XPATH);

        // 5. Click the *Rendered* checkbox.
        browserDriver.clickElement(RENDERED_CHECKBOX_XPATH);

        // 6. Verify that the rich text editor is visible.
        waitingAsserter.assertElementDisplayed(INPUT_RICH_TEXT_DIV_XPATH);
    }/*w w  w  .  j ava 2 s  .c o  m*/

    if (isCheckboxDisplayedAndEnabled(browserDriver, "required")) {

        // 7. Click the *Submit* button.
        browserDriver.clickElement(elementToClickXpath);

        // 8. Verify that no error messages are shown since the rich text editor is not a required field.
        waitingAsserter.assertElementNotDisplayed(valueIsRequiredError1Xpath);

        // 9. Click the *Required* checkbox.
        browserDriver.clickElement(requiredCheckbox1Xpath);

        // 10. Click the *Submit* button.
        browserDriver.clickElement(elementToClickXpath);

        // 11. Verify that a "Value is required." error message appears.
        waitingAsserter.assertElementDisplayed(valueIsRequiredError1Xpath);
    }

    // 12. Enter "Hello to the whole World!" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    String text = "Hello to the whole World!";
    browserDriver.sendKeysToElement(BODY_XPATH, text);

    // 13. Click the *Submit* button.
    submitRichText(browserDriver, elementToClickXpath, 1, text);

    // 14. Verify that "Hello to the whole World!" appears in the *Model Value*.
    waitingAsserter.assertTextPresentInElement(text, modelValue1Xpath);

    // 15. Verify that the "Value is required." error message does not appear.
    waitingAsserter.assertElementNotDisplayed(valueIsRequiredError1Xpath);

    // 16. Select the text "lo to the wh" in the rich text editor.
    // 17. Press Ctrl + b (or Cmd + b) to bold the text.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    String boldSelection = "lo to the wh";
    selectTextAndSendKeys(browserDriver, text, boldSelection, Keys.CONTROL, Keys.COMMAND, "b");

    // 18. Select the text "o the whole Wor" in the rich text editor.
    // 19. Press Ctrl + i (or Cmd + i) to italicize the text.
    String italicizedSelection = "o the whole Wor";
    selectTextAndSendKeys(browserDriver, text, italicizedSelection, Keys.CONTROL, Keys.COMMAND, "i");

    // 20. Click the *Submit* button.
    String expectedFormattedText = "Hel<strong>lo t<em>o the wh</em></strong><em>ole Wor</em>ld!";
    expectedFormattedText = expectedFormattedText.replace("<strong>", boldOpen).replace("</strong>", boldClose)
            .replace("<em>", italicsOpen).replace("</em>", italicsClose);
    submitRichText(browserDriver, elementToClickXpath, 1, expectedFormattedText);

    // 21. Verify that "Hel<strong>lo t<em>o the wh</em></strong><em>ole Wor</em>ld!" appears (with the appropriate
    // markup for the current use-case) in the *Model Value*.
    waitingAsserter.assertTextPresentInElement(expectedFormattedText, modelValue1Xpath);

    // 22. Verify that the "Value is required." error message does not appear.
    waitingAsserter.assertElementNotDisplayed(valueIsRequiredError1Xpath);
}

From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextValidationTester.java

License:Open Source License

@Test
public void runInputRichTextValidationTest() {

    // 1. Navigate to the "inputRichText" "Validation" use case.
    BrowserDriver browserDriver = getBrowserDriver();
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 2. Enter "123456789" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    StringBuilder stringBuilder = new StringBuilder();

    for (int i = 1; i < MIN_PLAIN_TEXT_CHARS; i++) {
        stringBuilder.append(i % 10);//w ww.  ja  va2s. c o m
    }

    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 3. Click the *Submit* button.
    browserDriver.getWebDriver().switchTo().parentFrame();
    browserDriver.clickElement(submitButton1Xpath);

    // 4. Verify that the "Length is less than allowable minimum of '10'" feedback message appears.
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementDisplayed(LESS_THAN_MIN_CHARS_ERROR_XPATH);

    // 5. Verify that nothing appears in the model value since the submitted value is invalid.
    waitingAsserter.assertTextNotPresentInElement(stringBuilder.toString(), modelValue1Xpath, false);

    // 6. Navigate to the "inputRichText" "Validation" use case to reset the rich text value.
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 7. Enter "123456789a" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);
    stringBuilder.append("a");
    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 8. Click the *Submit* button.
    submitRichText(browserDriver, submitButton1Xpath, 1, stringBuilder.toString());

    // 9. Verify that the "Length is less than allowable minimum of '10'" feedback message does not appear.
    waitingAsserter.assertElementNotDisplayed(LESS_THAN_MIN_CHARS_ERROR_XPATH);

    // 10. Verify that "123456789a" appears in the model value.
    waitingAsserter.assertTextPresentInElement(stringBuilder.toString(), modelValue1Xpath);

    // 11. Navigate to the "inputRichText" "Validation" use case to reset the rich text value.
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 12. Enter the maximum number of characters (144) into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);
    stringBuilder.setLength(0);

    for (int i = 0; i < MAX_PLAIN_TEXT_CHARS; i++) {

        if (i == 0) {
            stringBuilder.append("b");
        } else {
            stringBuilder.append(i % 10);
        }
    }

    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 13. Click the *Submit* button.
    submitRichText(browserDriver, submitButton1Xpath, 1, stringBuilder.toString());

    // 14. Verify that the "Length is greater than allowable maximum of '144'" feedback message does not appear.
    waitingAsserter.assertElementNotDisplayed(GREATER_THAN_MAX_CHARS_ERROR_XPATH);

    // 15. Verify that the 144 submitted characters appear in the model value.
    waitingAsserter.assertTextPresentInElement(stringBuilder.toString(), modelValue1Xpath);

    //J-
    // 16. Select the first character in the rich text editor.
    // 17. Press Ctrl + b (Cmd + b on Mac) to bold the first character.
    //J+
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);

    selectTextAndSendKeys(browserDriver, stringBuilder.toString(), "b", Keys.CONTROL, Keys.COMMAND, "b");

    // 18. Click the *Submit* button.
    String boldModelValue = stringBuilder.toString().replace("b", "<strong>b</strong>");
    submitRichText(browserDriver, submitButton1Xpath, 1, boldModelValue);

    // 19. Verify that the 144 submitted characters appear in the model value with the first character surrounded by
    // <strong> tags.
    waitingAsserter.assertTextPresentInElement(boldModelValue, modelValue1Xpath);

    // 20. Verify that the "Length is greater than allowable maximum of '144'" feedback message does not appear.
    waitingAsserter.assertElementNotDisplayed(GREATER_THAN_MAX_CHARS_ERROR_XPATH);

    // 21. Navigate to the "inputRichText" "Validation" use case to reset the rich text value.
    navigateToUseCase(browserDriver, "inputRichText", "validation");

    // 22. Enter the maximum number of characters (144) plus one "a" into the rich text editor.
    browserDriver.switchToFrame(CK_EDITOR_IFRAME_XPATH);
    stringBuilder.append("a");
    browserDriver.sendKeysToElement(BODY_XPATH, stringBuilder.toString());

    // 23. Click the *Submit* button.
    submitRichText(browserDriver, submitButton1Xpath, 1, stringBuilder.toString());

    // 24. Verify that the "Length is greater than allowable maximum of '144'" feedback message appears.
    waitingAsserter.assertElementDisplayed(GREATER_THAN_MAX_CHARS_ERROR_XPATH);

    // 25. Verify that nothing appears in the model value since the submitted value is invalid.
    waitingAsserter.assertTextNotPresentInElement(stringBuilder.toString(), modelValue1Xpath, false);
}

From source file:com.liferay.faces.test.alloy.showcase.datatable.DataTableTesterBase.java

License:Open Source License

/**
 * Must build this action using keyDown(key) and keyUp(key) since Action sendKeys behaves differently than
 * WebElement sendKeys (unless the browser is phantomjs, then it would need the following script).
 * https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html#sendKeys-java.lang.CharSequence...-
 *///from   ww  w  .j a  va2s.  c om
protected void metaOrCommandClick(BrowserDriver browserDriver, String xpath) {
    Keys metaOrCommandKey = Keys.META;

    if (System.getProperty("os.name").toLowerCase(Locale.ENGLISH).contains("mac")) {
        metaOrCommandKey = Keys.COMMAND;
    }

    if ("phantomjs".equals(browserDriver.getBrowserName())) {
        browserDriver.executeScriptInCurrentWindow(
                "var element = arguments[0]; YUI().use('node-event-simulate', function(Y) { Y.one(element).simulate('click', { metaKey: true }); });",
                browserDriver.findElementByXpath(xpath));
    } else {
        Actions metaOrCommandClickBuilder = browserDriver.createActions();
        metaOrCommandClickBuilder.keyDown(metaOrCommandKey).click(browserDriver.findElementByXpath(xpath))
                .keyUp(metaOrCommandKey);

        Action metaOrCommandClick = metaOrCommandClickBuilder.build();
        metaOrCommandClick.perform();
    }
}

From source file:com.thoughtworks.selenium.webdriven.commands.SendKeys.java

License:Apache License

@Override
protected Void handleSeleneseCommand(WebDriver driver, String locator, String value) {
    alertOverride.replaceAlertMethod(driver);

    value = value.replace("${KEY_ALT}", Keys.ALT);
    value = value.replace("${KEY_CONTROL}", Keys.CONTROL);
    value = value.replace("${KEY_CTRL}", Keys.CONTROL);
    value = value.replace("${KEY_META}", Keys.META);
    value = value.replace("${KEY_COMMAND}", Keys.COMMAND);
    value = value.replace("${KEY_SHIFT}", Keys.SHIFT);

    value = value.replace("${KEY_BACKSPACE}", Keys.BACK_SPACE);
    value = value.replace("${KEY_BKSP}", Keys.BACK_SPACE);
    value = value.replace("${KEY_DELETE}", Keys.DELETE);
    value = value.replace("${KEY_DEL}", Keys.DELETE);
    value = value.replace("${KEY_ENTER}", Keys.ENTER);
    value = value.replace("${KEY_EQUALS}", Keys.EQUALS);
    value = value.replace("${KEY_ESCAPE}", Keys.ESCAPE);
    value = value.replace("${KEY_ESC}", Keys.ESCAPE);
    value = value.replace("${KEY_INSERT}", Keys.INSERT);
    value = value.replace("${KEY_INS}", Keys.INSERT);
    value = value.replace("${KEY_PAUSE}", Keys.PAUSE);
    value = value.replace("${KEY_SEMICOLON}", Keys.SEMICOLON);
    value = value.replace("${KEY_SPACE}", Keys.SPACE);
    value = value.replace("${KEY_TAB}", Keys.TAB);

    value = value.replace("${KEY_LEFT}", Keys.LEFT);
    value = value.replace("${KEY_UP}", Keys.UP);
    value = value.replace("${KEY_RIGHT}", Keys.RIGHT);
    value = value.replace("${KEY_DOWN}", Keys.DOWN);
    value = value.replace("${KEY_PAGE_UP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PGUP}", Keys.PAGE_UP);
    value = value.replace("${KEY_PAGE_DOWN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_PGDN}", Keys.PAGE_DOWN);
    value = value.replace("${KEY_END}", Keys.END);
    value = value.replace("${KEY_HOME}", Keys.HOME);

    value = value.replace("${KEY_NUMPAD0}", Keys.NUMPAD0);
    value = value.replace("${KEY_N0}", Keys.NUMPAD0);
    value = value.replace("${KEY_NUMPAD1}", Keys.NUMPAD1);
    value = value.replace("${KEY_N1}", Keys.NUMPAD1);
    value = value.replace("${KEY_NUMPAD2}", Keys.NUMPAD2);
    value = value.replace("${KEY_N2}", Keys.NUMPAD2);
    value = value.replace("${KEY_NUMPAD3}", Keys.NUMPAD3);
    value = value.replace("${KEY_N3}", Keys.NUMPAD3);
    value = value.replace("${KEY_NUMPAD4}", Keys.NUMPAD4);
    value = value.replace("${KEY_N4}", Keys.NUMPAD4);
    value = value.replace("${KEY_NUMPAD5}", Keys.NUMPAD5);
    value = value.replace("${KEY_N5}", Keys.NUMPAD5);
    value = value.replace("${KEY_NUMPAD6}", Keys.NUMPAD6);
    value = value.replace("${KEY_N6}", Keys.NUMPAD6);
    value = value.replace("${KEY_NUMPAD7}", Keys.NUMPAD7);
    value = value.replace("${KEY_N7}", Keys.NUMPAD7);
    value = value.replace("${KEY_NUMPAD8}", Keys.NUMPAD8);
    value = value.replace("${KEY_N8}", Keys.NUMPAD8);
    value = value.replace("${KEY_NUMPAD9}", Keys.NUMPAD9);
    value = value.replace("${KEY_N9}", Keys.NUMPAD9);
    value = value.replace("${KEY_ADD}", Keys.ADD);
    value = value.replace("${KEY_NUM_PLUS}", Keys.ADD);
    value = value.replace("${KEY_DECIMAL}", Keys.DECIMAL);
    value = value.replace("${KEY_NUM_PERIOD}", Keys.DECIMAL);
    value = value.replace("${KEY_DIVIDE}", Keys.DIVIDE);
    value = value.replace("${KEY_NUM_DIVISION}", Keys.DIVIDE);
    value = value.replace("${KEY_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_NUM_MULTIPLY}", Keys.MULTIPLY);
    value = value.replace("${KEY_SEPARATOR}", Keys.SEPARATOR);
    value = value.replace("${KEY_SEP}", Keys.SEPARATOR);
    value = value.replace("${KEY_SUBTRACT}", Keys.SUBTRACT);
    value = value.replace("${KEY_NUM_MINUS}", Keys.SUBTRACT);

    value = value.replace("${KEY_F1}", Keys.F1);
    value = value.replace("${KEY_F2}", Keys.F2);
    value = value.replace("${KEY_F3}", Keys.F3);
    value = value.replace("${KEY_F4}", Keys.F4);
    value = value.replace("${KEY_F5}", Keys.F5);
    value = value.replace("${KEY_F6}", Keys.F6);
    value = value.replace("${KEY_F7}", Keys.F7);
    value = value.replace("${KEY_F8}", Keys.F8);
    value = value.replace("${KEY_F9}", Keys.F9);
    value = value.replace("${KEY_F10}", Keys.F10);
    value = value.replace("${KEY_F11}", Keys.F11);
    value = value.replace("${KEY_F12}", Keys.F12);

    finder.findElement(driver, locator).sendKeys(value);

    return null;/*from   w  w  w  . j  a  v  a 2  s . co m*/
}

From source file:org.alfresco.po.PageElement.java

License:Open Source License

/**
 * Returns COMMAND {@link Keys} if the OS is MAC OS X else CONTROL key.
 * @return {@link Keys}//from  w  w  w.  j ava2  s.co  m
 */
private Keys getOsKey() {
    Keys keys = Keys.CONTROL;
    String osName = System.getProperty("os.name");
    if (osName != null && !osName.isEmpty() && osName.toLowerCase().startsWith("mac")) {
        keys = Keys.COMMAND;
    }
    return keys;
}

From source file:org.eclipse.che.selenium.core.action.MacOSActions.java

License:Open Source License

@Override
protected CharSequence[] modifyCharSequence(CharSequence... keysToSend) {
    final List<CharSequence> modKeysToSend = newArrayList();

    for (CharSequence charSequence : keysToSend) {
        final String key = charSequence.toString();

        if (Keys.END.toString().equals(key)) {
            modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.RIGHT));
        } else if (Keys.HOME.toString().equals(key)) {
            modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.LEFT));
        } else if (Keys.PAGE_UP.toString().equals(key)) {
            modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.UP));
        } else if (Keys.PAGE_DOWN.toString().equals(key)) {
            modKeysToSend.add(Keys.chord(Keys.COMMAND, Keys.DOWN));
        } else {/*from  w  w w.  j a  v a2 s.  c  om*/
            modKeysToSend.add(charSequence);
        }
    }

    return modKeysToSend.toArray(new CharSequence[modKeysToSend.size()]);
}

From source file:org.eclipse.che.selenium.core.action.MacOSActionsTest.java

License:Open Source License

@Test
public void testShouldReplaceEndCharSequence() throws Exception {
    MacOSActions actions = new MacOSActions(webDriver);

    final CharSequence[] charSequences = actions.modifyCharSequence(Keys.ESCAPE, Keys.END);

    assertNotNull(charSequences);/*  ww  w. j ava  2 s .  c o m*/
    assertEquals(charSequences.length, 2);

    assertEquals(charSequences[0], Keys.ESCAPE);
    assertEquals(charSequences[1], Keys.chord(Keys.COMMAND, Keys.RIGHT));
}

From source file:org.eclipse.che.selenium.core.action.MacOSActionsTest.java

License:Open Source License

@Test
public void testShouldReplaceHomeCharSequence() throws Exception {
    MacOSActions actions = new MacOSActions(webDriver);

    final CharSequence[] charSequences = actions.modifyCharSequence(Keys.ESCAPE, Keys.HOME);

    assertNotNull(charSequences);/*from www  .j av  a2 s  . c  o m*/
    assertEquals(charSequences.length, 2);

    assertEquals(charSequences[0], Keys.ESCAPE);
    assertEquals(charSequences[1], Keys.chord(Keys.COMMAND, Keys.LEFT));
}

From source file:org.eclipse.che.selenium.core.action.MacOSActionsTest.java

License:Open Source License

@Test
public void testShouldReplacePageDownCharSequence() throws Exception {
    MacOSActions actions = new MacOSActions(webDriver);

    final CharSequence[] charSequences = actions.modifyCharSequence(Keys.ESCAPE, Keys.PAGE_DOWN);

    assertNotNull(charSequences);/*from  ww  w.j  ava 2s  . c  om*/
    assertEquals(charSequences.length, 2);

    assertEquals(charSequences[0], Keys.ESCAPE);
    assertEquals(charSequences[1], Keys.chord(Keys.COMMAND, Keys.DOWN));
}

From source file:org.eclipse.che.selenium.core.action.MacOSActionsTest.java

License:Open Source License

@Test
public void testShouldReplacePageUpCharSequence() throws Exception {
    MacOSActions actions = new MacOSActions(webDriver);

    final CharSequence[] charSequences = actions.modifyCharSequence(Keys.ESCAPE, Keys.PAGE_UP);

    assertNotNull(charSequences);//from  w ww. j  a  va2 s  .c  o m
    assertEquals(charSequences.length, 2);

    assertEquals(charSequences[0], Keys.ESCAPE);
    assertEquals(charSequences[1], Keys.chord(Keys.COMMAND, Keys.UP));
}