Example usage for org.openqa.selenium.interactions Actions Actions

List of usage examples for org.openqa.selenium.interactions Actions Actions

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions Actions.

Prototype

public Actions(WebDriver driver) 

Source Link

Usage

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

License:Open Source License

@Override
public void mouseRelease() {
    WebElement bodyWebElement = getWebElement("//body");

    WrapsDriver wrapsDriver = (WrapsDriver) bodyWebElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    actions.release();/*from  w  ww . j  a  v  a 2 s  .  c om*/

    Action action = actions.build();

    action.perform();
}

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

License:Open Source License

@Override
public void mouseUp(String locator) {
    WebElement webElement = getWebElement(locator);

    scrollWebElementIntoView(webElement);

    WrapsDriver wrapsDriver = (WrapsDriver) webElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    actions.release(webElement);//w  w  w  .  ja v a  2 s.co  m

    Action action = actions.build();

    action.perform();
}

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

License:Open Source License

@Override
public void mouseUpAt(String locator, String coordString) {
    WebElement webElement = getWebElement(locator);

    scrollWebElementIntoView(webElement);

    WrapsDriver wrapsDriver = (WrapsDriver) webElement;

    WebDriver webDriver = wrapsDriver.getWrappedDriver();

    Actions actions = new Actions(webDriver);

    if (Validator.isNotNull(coordString) && coordString.contains(",")) {
        String[] coords = coordString.split(",");

        int x = GetterUtil.getInteger(coords[0]);
        int y = GetterUtil.getInteger(coords[1]);

        actions.moveToElement(webElement, x, y);

        actions.release();/* www.  ja v a 2s.c  o  m*/
    } else {
        actions.moveToElement(webElement);
        actions.release(webElement);
    }

    Action action = actions.build();

    action.perform();
}

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

License:Open Source License

@Test
@RunAsClient//from  ww  w .  j a va  2s  .c  om
@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.FACES1427PortletTest.java

License:Open Source License

@Test
@RunAsClient/* w ww .ja v  a2 s .com*/
@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//from   w w w. ja  va 2 s .c  o m
@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"));

}

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

License:Open Source License

@Test
@RunAsClient//w  w  w.j  a va  2 s . co m
@InSequence(1200)
public void htmlEditor2() throws Exception {

    logger.log(Level.INFO, "Typing into htmlEditor2 ...");
    iframe2.click();

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

    iframe2.sendKeys("Hello world 2");
    logger.log(Level.INFO,
            "comments2Output.getText() = " + comments2Output.getText() + " ... before tabbing out");
    assertFalse("Model bean should not be updated yet since we have not tabbed-out of the field",
            comments2Output.getText().contains("Hello world 2"));

    // sending a tab now should tab out of the iframe
    (new Actions(browser)).sendKeys(Keys.TAB).perform();

    // Now wait for the Model bean to be updated
    Thread.sleep(250);

    logger.log(Level.INFO,
            "comments2Output.getText() = " + comments2Output.getText() + " ... after tabbing out");
    assertTrue("Model bean needs to have been updated via ajax after tabbing-out of field",
            comments2Output.getText().contains("Hello world 2"));

    // hide iframe2
    showHideTwo.click();
    logger.log(Level.INFO, "comments2Output.getText() = " + comments2Output.getText() + " ... after hide");

    // show iframe2
    showHideTwo.click();

    browser.switchTo().frame(iframe2);

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

    String textFromIframe2 = iframe2active.getText();
    browser.switchTo().defaultContent();

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

}

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

License:Open Source License

@Test
@RunAsClient//from www.j av  a2  s .  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.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.PlutoTest.java

License:Open Source License

@Test
@RunAsClient/*www. j a  v a2 s.  co m*/
@InSequence(1500)
public void dataEntry() throws Exception {

    logger.log(Level.INFO, "clicking into the firstNameField ...");
    firstNameField.click();
    Thread.sleep(50);
    logger.log(Level.INFO, "tabbing into the next field ...");
    firstNameField.sendKeys(Keys.TAB);
    Thread.sleep(500);
    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();
    Thread.sleep(50);
    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);
    Thread.sleep(50);
    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).keyDown(Keys.SHIFT).perform();
    Thread.sleep(50);
    logger.log(Level.INFO,
            "clearing the firstNameField using the BACKSPACE key, and then tabbing out of the firstNameField ...");
    firstNameField.sendKeys(Keys.BACK_SPACE);
    Thread.sleep(50);
    firstNameField.sendKeys(Keys.BACK_SPACE);
    Thread.sleep(50);
    firstNameField.sendKeys(Keys.BACK_SPACE);
    Thread.sleep(50);
    firstNameField.sendKeys(Keys.BACK_SPACE);
    Thread.sleep(50);
    firstNameField.sendKeys(Keys.TAB);
    Thread.sleep(50);
    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.Primefaces4UsersPortletTest.java

License:Open Source License

@Test // Not applicable for Liferay Portal 6.0
@RunAsClient/*ww w.  j a  va2s.c  o m*/
@InSequence(0)
public void testSetupActivateUser() throws Exception {
    browser.manage().window().maximize();
    signIn(browser);
    (new Actions(browser)).click(dropdownTestSetup);

    if (!controlPanelTestSetup.isDisplayed()) {
        dropdownTestSetup.click();
    }

    controlPanelTestSetup.click();
    waitForElement(browser, usersLinkTestSetupXpath);
    usersLinkTestSetup.click();
    waitForElement(browser, searchAllUsersLinkTestSetupXpath);

    if (!isThere(browser, johnAdamsTestSetupXpath) || !johnAdamsTestSetup.isDisplayed()) {

        searchAllUsersLinkTestSetup.click();
        waitForElement(browser, backLinkTestSetupXpath);

        if (isThere(browser, advancedSearchLinkTestSetupXpath) && advancedSearchLinkTestSetup.isDisplayed()) {
            advancedSearchLinkTestSetup.click();
        }

        waitForElement(browser, selectStatusTestSetupXpath);
        selectStatusTestSetup.click();
        (new Actions(browser)).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.TAB).perform();
        Thread.sleep(250);

        if (isThere(browser, johnAdamsTestSetupXpath)) {
            //no-op
        } else {
            selectStatusTestSetup.submit();
            Thread.sleep(250);
        }

        if (isThere(browser, johnAdamsTestSetupXpath)) {
            johnAdamsMenuTestSetup.click();
            activateJohnAdamsTestSetup.click();
        }

        waitForElement(browser, usersLinkTestSetupXpath);
    }
}