Example usage for org.openqa.selenium Keys TAB

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

Introduction

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

Prototype

Keys TAB

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

Click Source Link

Usage

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

@Override
public void typeKeys(String locator, String value) {
    WebElement webElement = getWebElement(locator);

    if (!webElement.isEnabled()) {
        return;// w  w  w .jav  a 2s.c om
    }

    if (value.contains("line-number=")) {
        value = value.replaceAll("line-number=\"\\d+\"", "");
    }

    int i = 0;

    Set<Integer> specialCharIndexes = getSpecialCharIndexes(value);

    for (int specialCharIndex : specialCharIndexes) {
        webElement.sendKeys(value.substring(i, specialCharIndex));

        String specialChar = String.valueOf(value.charAt(specialCharIndex));

        if (specialChar.equals("-")) {
            webElement.sendKeys(Keys.SUBTRACT);
        } else if (specialChar.equals("\t")) {
            webElement.sendKeys(Keys.TAB);
        } else {
            webElement.sendKeys(Keys.SHIFT, _keysSpecialChars.get(specialChar));
        }

        i = specialCharIndex + 1;
    }

    webElement.sendKeys(value.substring(i, value.length()));
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.ApplicantTesterBase.java

License:Open Source License

@Test
public void runApplicantPortletTest_C_FirstNameField() {

    BrowserDriver browserDriver = getBrowserDriver();
    String firstNameFieldXpath = getFirstNameFieldXpath();
    browserDriver.createActions().sendKeys(Keys.TAB).perform();
    browserDriver.sendKeysToElement(firstNameFieldXpath, "asdf");

    String lastNameFieldXpath = getLastNameFieldXpath();
    Action lastNameFieldClick = browserDriver.createClickElementAction(lastNameFieldXpath);
    browserDriver.performAndWaitForRerender(lastNameFieldClick, firstNameFieldXpath);

    String firstNameFieldErrorXpath = getFieldErrorXpath(firstNameFieldXpath);
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementNotDisplayed(firstNameFieldErrorXpath);
    browserDriver.clearElement(firstNameFieldXpath);
    browserDriver.performAndWaitForRerender(lastNameFieldClick, firstNameFieldXpath);
    waitingAsserter.assertTextPresentInElement("Value is required", firstNameFieldErrorXpath);
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.ApplicantTesterBase.java

License:Open Source License

protected final void sendKeysTabAndWaitForRerender(BrowserDriver browserDriver, String elementXpath,
        CharSequence... keys) {/*w  w  w  .  java2  s . c o  m*/

    Actions actions = browserDriver.createActions(elementXpath);
    WebElement element = browserDriver.findElementByXpath(elementXpath);
    actions.sendKeys(element, keys);
    actions.sendKeys(Keys.TAB);
    browserDriver.performAndWaitForRerender(actions.build(), elementXpath);
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.ButterFacesApplicantPortletTester.java

License:Open Source License

@Override
public void runApplicantPortletTest_C_FirstNameField() {

    BrowserDriver browserDriver = getBrowserDriver();
    String firstNameFieldXpath = getFirstNameFieldXpath();
    browserDriver.createActions().sendKeys(Keys.TAB).perform();
    browserDriver.sendKeysToElement(firstNameFieldXpath, "asdf");

    String lastNameFieldXpath = getLastNameFieldXpath();
    Action lastNameFieldClick = browserDriver.createClickElementAction(lastNameFieldXpath);
    browserDriver.performAndWaitForRerender(lastNameFieldClick, firstNameFieldXpath);

    String firstNameFieldErrorXpath = getFieldErrorXpath(firstNameFieldXpath);
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertElementNotDisplayed(firstNameFieldErrorXpath);
    browserDriver.clearElement(firstNameFieldXpath);
    lastNameFieldClick = browserDriver.createClickElementAction(lastNameFieldXpath);
    browserDriver.performAndWaitForRerender(lastNameFieldClick, firstNameFieldXpath);
    mouseOverElement(browserDriver, firstNameFieldXpath);
    waitingAsserter.assertTextPresentInElement("Value is required", firstNameFieldErrorXpath);
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.ButterFacesApplicantPortletTester.java

License:Open Source License

@Override
public void runApplicantPortletTest_D_EmailValidation() {

    BrowserDriver browserDriver = getBrowserDriver();
    browserDriver.createActions().sendKeys(Keys.TAB).perform();

    String emailAddressFieldXpath = getEmailAddressFieldXpath();
    sendKeysTabAndWaitForRerender(browserDriver, emailAddressFieldXpath, "test");
    mouseOverElement(browserDriver, emailAddressFieldXpath);

    String emailAddressFieldErrorXpath = getFieldErrorXpath(emailAddressFieldXpath);
    WaitingAsserter waitingAsserter = getWaitingAsserter();
    waitingAsserter.assertTextPresentInElement("Invalid e-mail address", emailAddressFieldErrorXpath);
    sendKeysTabAndWaitForRerender(browserDriver, emailAddressFieldXpath, "@liferay.com");
    waitingAsserter.assertElementNotDisplayed(emailAddressFieldErrorXpath);
}

From source file:com.liferay.faces.bridge.test.integration.demo.applicant.JSF_JSPApplicantPortletTester.java

License:Open Source License

protected final void submitPostalCodeAndWaitForPostback(BrowserDriver browserDriver,
        CharSequence... postalCode) {

    String postalCodeFieldXpath = getPostalCodeFieldXpath();
    Actions actions = browserDriver.createActions(postalCodeFieldXpath);
    WebElement postalCodeField = browserDriver.findElementByXpath(postalCodeFieldXpath);
    actions.sendKeys(postalCodeField, postalCode);
    actions.sendKeys(Keys.TAB);
    browserDriver.performAndWaitForRerender(actions.build(), postalCodeFieldXpath);
}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient/* ww w.ja  v  a  2s .  c  o  m*/
@InSequence(1500)
public void dataEntry() throws Exception {

    String foo = "";

    logger.log(Level.INFO, "clicking into the firstNameField ...");
    firstNameField.click();
    logger.log(Level.INFO, "tabbing into the next field ...");
    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));

    if (isThere(browser, firstNameFieldErrorXpath)) { // houston we have a problem
        logger.log(Level.INFO, "firstNameFieldError.isDisplayed() = " + firstNameFieldError.isDisplayed());
        assertFalse(
                "firstNameFieldError should not be displayed after simply tabbing out of the empty field, having never entered any data.  "
                        + "But we see '" + firstNameFieldError.getText() + "'",
                firstNameFieldError.isDisplayed());
    }

    logger.log(Level.INFO, "Shift tabbing back into the firstNameField ...");
    (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyDown(Keys.SHIFT).perform();

    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));

    logger.log(Level.INFO, "entering 'asdf' into the firstNameField and then tabbing out of it...");
    firstNameField.sendKeys("asdf");
    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));
    assertTrue("The data 'asdf' should be in the firstNameField after tabbing out of it",
            "asdf".equals(firstNameField.getAttribute("value")));

    logger.log(Level.INFO, "Shift tabbing back into the firstNameField ...");
    (new Actions(browser)).keyDown(Keys.SHIFT).sendKeys(Keys.TAB).keyUp(Keys.SHIFT).perform();

    firstNameField.click();
    logger.log(Level.INFO,
            "clearing the firstNameField using the BACKSPACE key, and then tabbing out of the firstNameField ...");
    firstNameField.sendKeys(Keys.ARROW_RIGHT, Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'asd' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "asd"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        logger.log(Level.INFO, "firstNameField.getText() = " + firstNameField.getText());
        assertTrue(
                "firstNameField should contain 'asd', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'as' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "as"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue(
                "firstNameField should contain 'as', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain 'a' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), "a"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue("firstNameField should contain 'a', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.BACK_SPACE);

    logger.log(Level.INFO, "Waiting for the firstNameField to contain '' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(firstNameFieldXpath), ""));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, firstNameFieldXpath)) {
            foo = firstNameField.getText();
        }
        assertTrue("firstNameField should contain '', but " + firstNameFieldXpath + " contains '" + foo + "'.",
                false);
    }

    firstNameField.sendKeys(Keys.TAB);

    logger.log(Level.INFO, "Waiting for the firstNameFieldError to contain 'Value is required' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(firstNameFieldErrorXpath),
                "Value is required"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("firstNameFieldError should be visible after tabbing out with no value," + " but "
                + firstNameFieldErrorXpath + " is not visible.", false);
    }

    logger.log(Level.INFO, "firstNameField.getAttribute('value') = " + firstNameField.getAttribute("value"));
    assertTrue(
            "The data 'asdf' should no longer be in the firstNameField after clearing it out with BACK_SPACE and then tabbing out.   "
                    + "But we see '" + firstNameField.getAttribute("value") + "'",
            "".equals(firstNameField.getAttribute("value")));
    logger.log(Level.INFO,
            "isThere(browser, firstNameFieldErrorXpath) = " + isThere(browser, firstNameFieldErrorXpath));
    assertTrue(
            "The firstNameFieldError should at least be in the DOM somewhere by this point, but it is not there",
            isThere(browser, firstNameFieldErrorXpath));
    logger.log(Level.INFO, "firstNameFieldError.getText() = " + firstNameFieldError.getText());
    assertTrue("The firstNameFieldError should say 'Value is required'",
            firstNameFieldError.getText().contains("Value is required"));

}

From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java

License:Open Source License

@Test
@RunAsClient//  ww w  . j  av  a2  s  .  c  om
@InSequence(2000)
public void validateEmail() throws Exception {

    String foo = "";

    // checks an invalid email address
    logger.log(Level.INFO, "Entering an invalid email address 'test' ...");
    emailAddressField.sendKeys("test");
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain 'Invalid e-mail address' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(emailAddressFieldErrorXpath),
                "Invalid e-mail address"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        assertTrue("emailAddressField should be visible after tabbing out with no value," + " but "
                + emailAddressFieldErrorXpath + " is not visible.", false);
    }
    logger.log(Level.INFO,
            "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value"));

    assertTrue("Invalid e-mail address validation message displayed",
            emailAddressFieldError.getText().contains("Invalid e-mail address"));
    logger.log(Level.INFO, "emailAddressFieldError.isDisplayed() = " + emailAddressFieldError.isDisplayed());
    logger.log(Level.INFO, "emailAddressFieldError.getText() = " + emailAddressFieldError.getText());

    // checks a valid email address
    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain '' ...");
    try {
        emailAddressField.clear();
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath), ""));
        logger.log(Level.INFO, "emailAddressField.getText() = '" + emailAddressField.getText() + "'");
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldXpath)) {
            foo = emailAddressField.getText();
        }
        assertTrue("emailAddressField should be clear," + " but " + emailAddressFieldXpath + " contains '" + foo
                + "'", false);
    }

    logger.log(Level.INFO, "Entering a valid email address 'test@liferay.com' ...");
    emailAddressField.click();
    emailAddressField.sendKeys("test@liferay.com");
    emailAddressField.sendKeys(Keys.TAB);
    phoneNumberField.click();

    logger.log(Level.INFO, "Waiting for the emailAddressField to contain 'test@liferay.com' ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath),
                "test@liferay.com"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldXpath)) {
            foo = emailAddressField.getText();
        }
        assertTrue("emailAddressField should contain 'test@liferay.com'," + " but " + emailAddressFieldXpath
                + " contains '" + foo + "'", false);
    }

    logger.log(Level.INFO, "Waiting for the emailAddressFieldError to disappear ...");
    try {
        WebDriverWait wait = new WebDriverWait(browser, 10);
        wait.until(ExpectedConditions
                .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(emailAddressFieldErrorXpath))));
        logger.log(Level.INFO,
                "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value"));
    } catch (Exception e) {
        logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage());
        if (isThere(browser, emailAddressFieldErrorXpath)) {
            foo = emailAddressFieldError.getText();
        }
        assertTrue("emailAddressFieldError should NOT be visible after entering 'test@liferay.com'," + " but "
                + emailAddressFieldErrorXpath + " is still there showing '" + foo + "'", false);
    }

}

From source file:com.liferay.faces.test.FACES1427PortletTest.java

License:Open Source License

@Test
@RunAsClient//from  ww  w.  ja v  a  2s  . co m
@InSequence(1300)
public void steps89012() throws Exception {

    if (isThere(browser, errorMessageXpath) && errorMessage.isDisplayed()) {
        return;
    }

    logger.log(Level.INFO, "8: textarea1.getAttribute('value') = " + textarea1.getAttribute("value"));

    // click into textarea1
    textarea1.click();
    Thread.sleep(50);

    // move to the beginning of textarea1
    textarea1.sendKeys(Keys.HOME); // firefox cursor is on the left after the last click, in chromium cursor is on
    // the right of the text ... grr
    Thread.sleep(50);

    // arrow over to the word 'initial'
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.ARROW_RIGHT);
    Thread.sleep(50);

    // delete the word 'initial'
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);
    textarea1.sendKeys(Keys.DELETE);
    Thread.sleep(50);

    // type the word 'subsequent'
    textarea1.sendKeys("subsequent");
    Thread.sleep(50);

    // select the word 'subsequent' ... easier said than done
    logger.log(Level.INFO, "8: textarea1.getAttribute('id') = '" + textarea1.getAttribute("id") + "'");

    logger.log(Level.INFO, "8: before selecting ... selectText.getSelection(id) = "
            + selectText.getSelection(textarea1.getAttribute("id")));
    Thread.sleep(500);

    logger.log(Level.INFO, "8: selectText.getSelection('id', 10, 20) ... ");
    selectText.setSelection(textarea1.getAttribute("id"), 10, 20);
    Thread.sleep(1000);

    logger.log(Level.INFO, "8: after selecting ... selectText.getSelection(id) = "
            + selectText.getSelection(textarea1.getAttribute("id")));
    Thread.sleep(500);

    logger.log(Level.INFO, "8: isThere(browser, bold1Xpath) = " + isThere(browser, bold1Xpath));
    logger.log(Level.INFO, "8: bold1.isDisplayed() = " + bold1.isDisplayed());
    logger.log(Level.INFO, "8: bold1.getAttribute('src') = " + bold1.getAttribute("src"));
    logger.log(Level.INFO, "8: bold1.getLocation() = " + bold1.getLocation());
    logger.log(Level.INFO, "8: clicking the bold1 button ...");

    // click the bold1 button to make the word 'subsequent' bold
    try {
        bold1.click();
    } catch (Exception e) { // apparently things are different in chromium
        logger.log(Level.INFO, "8: e.getMessage() = " + e.getMessage());
        (new Actions(browser)).moveToElement(bold1, 3, 3).click(bold1).build().perform();
        Thread.sleep(500);
        (new Actions(browser)).moveToElement(bold1, 3, 3).click().build().perform();
        Thread.sleep(500);
        (new Actions(browser)).moveToElement(bold1).doubleClick().build().perform();
        Thread.sleep(500);
    }

    Thread.sleep(50);

    // move into iframe1
    logger.log(Level.INFO, "9: clicking into iframe1 ...");
    iframe1.click();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.TAB).perform();
    Thread.sleep(50);

    // arrow over to the word 'initial'
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.ARROW_RIGHT).perform();
    Thread.sleep(50);

    // delete the word 'initial'
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);
    (new Actions(browser)).sendKeys(Keys.BACK_SPACE).perform();
    Thread.sleep(50);

    // type the word 'subsequent'
    (new Actions(browser)).sendKeys("subsequent").perform();
    Thread.sleep(50);

    // select the word 'subsequent' ... easier said than done
    (new Actions(browser)).keyDown(iframe1, Keys.SHIFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT)
            .sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT)
            .sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).sendKeys(Keys.LEFT).keyUp(iframe1, Keys.SHIFT).build()
            .perform();
    Thread.sleep(50);

    // click the bold2 button to make the word 'subsequent' bold
    logger.log(Level.INFO, "9: clicking on the bold button in the second editor ...");
    bold2.click();
    Thread.sleep(50);

    // Why do we need to click the iframe before clicking the submit button?  Who knows?
    iframe1.click();
    Thread.sleep(50);

    // submit the form
    logger.log(Level.INFO, "10: clicking the submit button ...");
    submit.click();
    Thread.sleep(50);

    // log some elements
    logger.log(Level.INFO, "11: comments1Output.getText() = " + comments1Output.getText());
    logger.log(Level.INFO, "12: comments2Output.getText() = " + comments2Output.getText());

    // assert to test
    assertTrue(
            "the submitted value for the FIRST editor should be 'comments1-[b]subsequent[/b]-value', but "
                    + "it is '" + comments1Output.getText() + "'",
            comments1Output.getText().equals("comments1-[b]subsequent[/b]-value"));
    assertTrue(
            "the submitted value for the SECOND editor should be 'comments2-[b]subsequent[/b]-value', but "
                    + "it is '" + comments2Output.getText() + "'",
            comments2Output.getText().equals("comments2-[b]subsequent[/b]-value"));

}

From source file:com.liferay.faces.test.FACES1439PortletTest.java

License:Open Source License

@Test
@RunAsClient/*  w ww  .ja  v a2  s  .  c om*/
@InSequence(1100)
public void htmlEditor1() throws Exception {

    logger.log(Level.INFO, "Typing into htmlEditor1 ...");

    iframe1.click();
    // Apparently sending a TAB key brings the iframe into focus, so that you can type into it
    (new Actions(browser)).sendKeys(Keys.TAB).perform();

    iframe1.sendKeys("Hello world 1");

    if (comments1Output.getText().contains("Hello world 1")) {
        logger.log(Level.INFO, "comments1Output.getText() = " + comments1Output.getText()
                + " ... immediately after entering the keys");
    } else {
        Thread.sleep(80);

        if (comments1Output.getText().contains("Hello world 1")) {
            logger.log(Level.INFO,
                    "comments1Output.getText() = " + comments1Output.getText() + " ... after 80 millis");
        } else {
            Thread.sleep(80);

            if (comments1Output.getText().contains("Hello world 1")) {
                logger.log(Level.INFO,
                        "comments1Output.getText() = " + comments1Output.getText() + " ... after 160 millis");
            } else {
                Thread.sleep(80);

                if (comments1Output.getText().contains("Hello world 1")) {
                    logger.log(Level.INFO, "comments1Output.getText() = " + comments1Output.getText()
                            + " ... after 240 millis");
                } else {
                    Thread.sleep(80);

                    if (comments1Output.getText().contains("Hello world 1")) {
                        logger.log(Level.INFO, "comments1Output.getText() = " + comments1Output.getText()
                                + " ... after 320 millis");
                    } else {
                        Thread.sleep(80);

                        if (comments1Output.getText().contains("Hello world 1")) {
                            logger.log(Level.INFO, "comments1Output.getText() = " + comments1Output.getText()
                                    + " ... after 400 millis");
                        }
                    }
                }
            }
        }
    }

    assertTrue("Model bean should have updated via ajax when characters were typed",
            comments1Output.getText().contains("Hello world 1"));

    // hide iframe 1
    showHideOne.click();

    logger.log(Level.INFO, "comments1Output.getText() = " + comments1Output.getText() + " ... after hide");

    // show iframe 1
    showHideOne.click();
    // Now wait for the comments to actually show
    Thread.sleep(250);

    browser.switchTo().frame(iframe1);

    WebElement iframe1active = browser.switchTo().activeElement();
    logger.log(Level.INFO, "iframe1active.getText() = " + iframe1active.getText() + " ... after hide and show");

    String textFromIframe1 = iframe1active.getText();
    browser.switchTo().defaultContent();

    assertTrue("The first text editor should contain 'Hello world 1', but contains '" + textFromIframe1 + "'",
            textFromIframe1.contains("Hello world 1"));

}