List of usage examples for org.openqa.selenium.support.ui ExpectedConditions textToBePresentInElementLocated
public static ExpectedCondition<Boolean> textToBePresentInElementLocated(final By locator, final String text)
From source file:com.ggasoftware.uitest.control.Element.java
License:Open Source License
/** * Wait until element is changed text./*from ww w . j a v a 2 s .c o m*/ * * @param text before change * @param timeoutSec seconds to wait until element is changed text * @param checkCondition log assert for expected conditions. * @return Parent instance */ public ParentPanel waitForTextChanged(final String text, final int timeoutSec, final boolean checkCondition) { boolean isChanged; logAction(this, getParentClassName(), format("waitForTextChanged[%s]: %s", text, locator)); long start = System.currentTimeMillis() / 1000; WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec) .ignoring(StaleElementReferenceException.class); try { isChanged = wait.until(ExpectedConditions .not(ExpectedConditions.textToBePresentInElementLocated(avatar.byLocator, text))); } catch (TimeoutException e) { logTechnical(format("waitForTextChanged: [ %s ] during: [ %d ] sec ", locator, System.currentTimeMillis() / 1000 - start)); isChanged = false; } if (checkCondition) { logAssertTrue(BUSINESS_LEVEL, isChanged, format("waitForTextChanged - '%s' text '%s' should be changed", getName(), text), takePassedScreenshot); } return parent; }
From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java
License:Open Source License
/** * Wait until any element with text presents at web page. * * @param text - element text to be presents. * @param timeoutSec to wait until presents. * @param checkCondition log assert for expected conditions. *///from w w w . j av a2 s . c o m public static void waitForTextToBePresent(String text, int timeoutSec, boolean checkCondition) { ReporterNGExt.logAction(getDriver(), "", String.format("waitForTextToBePresent: %s", text)); boolean isPresent; long start = System.currentTimeMillis() / 1000; WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec) .ignoring(StaleElementReferenceException.class); setTimeout(timeoutSec); try { isPresent = wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*"), text)); } catch (TimeoutException ignored) { ReporterNGExt.logTechnical(String.format("waitForTextToBePresent: [ %s ] during: [ %d ] sec ", text, System.currentTimeMillis() / 1000 - start)); isPresent = false; } setTimeout(TIMEOUT); if (checkCondition) { ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isPresent, String.format("waitForTextToBePresent: element with text '%s' should be exists", text), TestBaseWebDriver.takePassedScreenshot); } }
From source file:com.ggasoftware.uitest.utils.WebDriverWrapper.java
License:Open Source License
/** * Wait until any element with text not presents at web page. * * @param text - element text to not be presents. * @param timeoutSec to wait until not presents. * @param checkCondition log assert for expected conditions. */// w ww .j a v a 2 s .c o m public static void waitForTextToNotBePresent(String text, int timeoutSec, boolean checkCondition) { ReporterNGExt.logAction(getDriver(), "", String.format("waitForTextToNotBePresent: %s", text)); boolean isNotPresent; long start = System.currentTimeMillis() / 1000; WebDriverWait wait = (WebDriverWait) new WebDriverWait(getDriver(), timeoutSec) .ignoring(StaleElementReferenceException.class); setTimeout(timeoutSec); try { isNotPresent = wait.until(ExpectedConditions .not(ExpectedConditions.textToBePresentInElementLocated(By.xpath("//*"), text))); } catch (TimeoutException ignored) { ReporterNGExt.logTechnical(String.format("waitForTextToNotBePresent: [ %s ] during: [ %d ] sec ", text, System.currentTimeMillis() / 1000 - start)); isNotPresent = false; } setTimeout(TIMEOUT); if (checkCondition) { ReporterNGExt.logAssertTrue(ReporterNGExt.BUSINESS_LEVEL, isNotPresent, String.format("waitForTextToNotBePresent: element with text '%s' should not be exists", text), TestBaseWebDriver.takePassedScreenshot); } }
From source file:com.java.cukes.CheckoutSteps.java
License:Apache License
@Then("^I should see products$") public void I_should_see_products() throws Throwable { new WebDriverWait(driver, 120).until(ExpectedConditions.textToBePresentInElementLocated(By.tagName("h1"), "SEARCH RESULTS FOR 'SAMSUNG'")); // assertEquals(driver.findElement(By.cssSelector("h1")).getText(), "SEARCH RESULTS FOR 'SAMSUNG'"); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient//from w ww .j a v a 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.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient/*from ww w . j a v a 2s . c o m*/ @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.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient/*from w w w. jav a 2 s.c o m*/ @InSequence(5000) public void allFieldsRequiredUponSubmit() throws Exception { logger.log(Level.INFO, "Waiting for the firstNameField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(firstNameFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("firstNameField should be visible after reset," + " but " + firstNameFieldXpath + " is not visible.", false); } logger.log(Level.INFO, "clearing fields ..."); firstNameField.clear(); lastNameField.clear(); emailAddressField.clear(); phoneNumberField.clear(); try { dateOfBirthField.clear(); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); } cityField.clear(); postalCodeField.clear(); logger.log(Level.INFO, "clicking submit ..."); submitButton.click(); 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 submitting the form with no value," + " but " + firstNameFieldErrorXpath + " is not visible.", false); } logger.log(Level.INFO, "firstNameFieldError.getText() = " + firstNameFieldError.getText()); logger.log(Level.INFO, "lastNameFieldError.getText() = " + lastNameFieldError.getText()); logger.log(Level.INFO, "emailAddressFieldError.getText() = " + emailAddressFieldError.getText()); logger.log(Level.INFO, "phoneNumberFieldError.getText() = " + phoneNumberFieldError.getText()); logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText()); logger.log(Level.INFO, "cityFieldError.getText() = " + cityFieldError.getText()); logger.log(Level.INFO, "isThere(browser, provinceIdFieldXpath) = " + isThere(browser, provinceIdFieldXpath)); logger.log(Level.INFO, "isThere(browser, provinceIdFieldErrorXpath) = " + isThere(browser, provinceIdFieldErrorXpath)); assertTrue( "firstNameFieldError should contain 'Value is required', but instead contains '" + firstNameFieldError.getText() + "'", firstNameFieldError.getText().contains("Value is required")); assertTrue( "lastNameFieldError should contain 'Value is required', but instead contains '" + lastNameFieldError.getText() + "'", lastNameFieldError.getText().contains("Value is required")); assertTrue( "emailAddressFieldError should contain 'Value is required', but instead contains '" + emailAddressFieldError.getText() + "'", emailAddressFieldError.getText().contains("Value is required")); assertTrue( "phoneNumberFieldError should contain 'Value is required', but instead contains '" + phoneNumberFieldError.getText() + "'", phoneNumberFieldError.getText().contains("Value is required")); assertTrue( "dateOfBirthFieldError should contain 'Value is required', but instead contains '" + dateOfBirthFieldError.getText() + "'", dateOfBirthFieldError.getText().contains("Value is required")); assertTrue("cityFieldError should contain 'Value is required', but instead contains '" + cityFieldError.getText() + "'", cityFieldError.getText().contains("Value is required")); assertTrue( "provinceIdFieldError should contain 'Value is required', but instead contains '" + provinceIdFieldError.getText() + "'", provinceIdFieldError.getText().contains("Value is required")); assertTrue( "postalCodeFieldError should contain 'Value is required', but instead contains '" + postalCodeFieldError.getText() + "'", postalCodeFieldError.getText().contains("Value is required")); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient// w w w . j a v a 2 s . c om @InSequence(7000) public void commentsFunctioning() throws Exception { String testing123 = "testing 1, 2, 3"; logger.log(Level.INFO, "Waiting for the showCommentsLink to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(showCommentsLinkXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("showCommentsLink should be visible," + " but " + showCommentsLinkXpath + " is not visible.", false); } showCommentsLink.click(); logger.log(Level.INFO, "Waiting for the hideCommentsLink to contain 'Hide Comments' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(hideCommentsLinkXpath), "Hide Comments")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("'Hide Comments' should be visible after clicking 'Show Comments'," + " but //a[contains(text(),'Hide Comments')] is not visible.", false); } logger.log(Level.INFO, "comments.isDisplayed() = " + comments.isDisplayed()); assertTrue("comments textarea is displayed", comments.isDisplayed()); comments.sendKeys(testing123); phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the hideCommentsLinkXpath to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(hideCommentsLinkXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("hideCommentsLink should be visible," + " but " + hideCommentsLinkXpath + " is not visible.", false); } hideCommentsLink.click(); logger.log(Level.INFO, "Waiting for the showCommentsLink to contain 'Show Comments' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(showCommentsLinkXpath), "Show Comments")); logger.log(Level.INFO, "showCommentsLink.isDisplayed() = " + showCommentsLink.isDisplayed()); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("'Show Comments' should be visible after clicking 'Hide Comments'," + " but " + showCommentsLinkXpath + " is not visible.", false); } showCommentsLink.click(); logger.log(Level.INFO, "Waiting for the commentsXpath to contain '" + testing123 + "' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(commentsXpath), testing123)); logger.log(Level.INFO, "after hide and show comments.getAttribute('value') = " + comments.getAttribute("value")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("comments should be visible after clicking 'Hide Comments'," + " but " + commentsXpath + " is not visible.", false); } assertTrue( "comments should be there after hide and then show, but comments value is '" + comments.getAttribute("value") + "' after clicking show comments.", testing123.equals(comments.getAttribute("value"))); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient// www . ja va2 s.c o m @InSequence(8000) public void dateValidation() throws Exception { String foo = ""; // checks an invalid dateOfBirth try { dateOfBirthField.clear(); logger.log(Level.INFO, "No exceptions occured when clearing the dateOfBirthField"); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "No exceptions should occur when clearing the dateOfBirthField, but one did occur with the following message: " + e.getMessage(), false); } logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), "")); logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, dateOfBirthFieldErrorXpath)) { foo = dateOfBirthFieldError.getText(); } assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath + " contains '" + foo + "'.", false); } logger.log(Level.INFO, "Entering an invalid value for the date of birth ... 12/34/5678 ..."); dateOfBirthField.sendKeys("12/34/5678"); logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '12/34/5678' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(dateOfBirthFieldXpath), "12/34/5678")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, dateOfBirthFieldErrorXpath)) { foo = dateOfBirthFieldError.getText(); } assertTrue("dateOfBirthField should contain '12/34/5678'," + " but " + dateOfBirthFieldXpath + " contains '" + foo + "'.", false); } submitButton.click(); logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to contain 'Invalid date format' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldErrorXpath), "Invalid date format")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("dateOfBirthFieldError should be visible after submitting with '12/34/5678'," + " but " + dateOfBirthFieldErrorXpath + " is not visible.", false); } logger.log(Level.INFO, "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); logger.log(Level.INFO, "dateOfBirthFieldError.isDisplayed() = " + dateOfBirthFieldError.isDisplayed()); logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText()); assertTrue( "dateOfBirthFieldError should contain 'Invalid date format', but insteead contains '" + dateOfBirthFieldError.getText() + "'", dateOfBirthFieldError.getText().contains("Invalid date format")); // checks with no dateOfBirth dateOfBirthField.clear(); logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), "")); logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, dateOfBirthFieldErrorXpath)) { foo = dateOfBirthFieldError.getText(); } assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath + " contains '" + foo + "'.", false); } phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to contain 'Value is required' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldErrorXpath), "Value is required")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "dateOfBirthFieldError should be visible after entering '12/34/5678' and clicking into another field," + " but " + dateOfBirthFieldErrorXpath + " does not contain 'Value is required'.", false); } logger.log(Level.INFO, "dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); logger.log(Level.INFO, "dateOfBirthFieldError.isDisplayed() = " + dateOfBirthFieldError.isDisplayed()); logger.log(Level.INFO, "dateOfBirthFieldError.getText() = " + dateOfBirthFieldError.getText()); // checks a valid dateOfBirth foo = ""; dateOfBirthField.clear(); logger.log(Level.INFO, "Waiting for the dateOfBirthField to contain '' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(dateOfBirthFieldXpath), "")); logger.log(Level.INFO, "after clearing dateOfBirthField.getAttribute('value') = " + dateOfBirthField.getAttribute("value")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, dateOfBirthFieldErrorXpath)) { foo = dateOfBirthFieldError.getText(); } assertTrue("dateOfBirthField should be empty after clearing," + " but " + dateOfBirthFieldXpath + " contains '" + foo + "'.", false); } logger.log(Level.INFO, "Entering a valid dateOfBirth = 01/02/3456 ..."); dateOfBirthField.sendKeys("01/02/3456"); logger.log(Level.INFO, "Clicking into the phoneNumberField ..."); phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the dateOfBirthFieldError to disappear ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions .not(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(dateOfBirthFieldErrorXpath)))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, dateOfBirthFieldErrorXpath)) { foo = dateOfBirthFieldError.getText(); } assertTrue("dateOfBirthFieldError should NOT be visible after entering 01/02/3456," + " but " + dateOfBirthFieldErrorXpath + " is still there showing '" + foo + "'", false); } }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient/* w w w . j a v a2 s .c o m*/ @InSequence(9000) public void submitAndValidate() throws Exception { String foo = ""; logger.log(Level.INFO, "clearing fields ..."); logger.log(Level.INFO, "Waiting for the dateOfBirthField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(dateOfBirthFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("dateOfBirthField should be visible after fileUpload," + " but " + dateOfBirthFieldXpath + " is not visible.", false); } try { dateOfBirthField.clear(); logger.log(Level.INFO, "No exceptions occured when clearing the dateOfBirthField"); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); } emailAddressField.clear(); postalCodeField.clear(); if (isThere(browser, hideCommentsLinkXpath)) { waitForElement(browser, "//textarea[contains(@id,':comments')]"); } int commentsTextAreas = browser.findElements(By.xpath("//textarea[contains(@id,':comments')]")).size(); logger.log(Level.INFO, "# of commentsTextAreas = " + commentsTextAreas); if (commentsTextAreas == 0) { // if comments were not previously exercised, then we may need to show the // comments text area. try { waitForElement(browser, showCommentsLinkXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "showCommentsLinkXpath should be visible when their is no text area for comments showing," + " but the " + showCommentsLinkXpath + " is not visible.", e == null); } showCommentsLink.click(); logger.log(Level.INFO, "Waiting for the comments textrea to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(commentsXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("comments textarea should be visible after clicking 'Show Comments'," + " but " + commentsXpath + " is not visible.", false); } commentsTextAreas = browser.findElements(By.xpath(commentsXpath)).size(); logger.log(Level.INFO, "# of commentsTextAreas = " + commentsTextAreas); } assertTrue("The commentsTextArea should be showing, but it is not visible.", commentsTextAreas == 1); comments.clear(); logger.log(Level.INFO, "Waiting for the emailAddressField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(emailAddressFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("emailAddressField should be visible after clearing comments field," + " but " + emailAddressFieldXpath + " is not visible.", false); } logger.log(Level.INFO, "fields were cleared now, but let's see ..."); logger.log(Level.INFO, "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value")); assertTrue("emailAddressField is empty after clearing and clicking into another field", "".equals(emailAddressField.getAttribute("value"))); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(firstNameFieldXpath))); logger.log(Level.INFO, "isThere(browser, firstNameFieldXpath) = " + isThere(browser, firstNameFieldXpath)); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); boolean firstNameFieldIsThere = isThere(browser, firstNameFieldXpath); logger.log(Level.INFO, "firstNameFieldIsThere = " + firstNameFieldIsThere); if (firstNameFieldIsThere) { foo = firstNameField.getAttribute("value"); } assertTrue("firstNameField should be correct after entering 'David'," + " but " + firstNameFieldXpath + " contains '" + foo + "'.", false); } logger.log(Level.INFO, "entering data ..."); firstNameField.sendKeys("David"); lastNameField.sendKeys("Samuel"); emailAddressField.sendKeys("no_need@just.pray"); phoneNumberField.sendKeys("(way) too-good"); try { dateOfBirthField.sendKeys("01/02/3456"); logger.log(Level.INFO, "No exceptions occured when entering the dateOfBirthField"); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); } postalCodeField.sendKeys("32801"); logger.log(Level.INFO, "Clicking into phone number field ..."); phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the commentsXpath to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(commentsXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("comments should be visible after clicking into the phoneNumberField," + " but " + commentsXpath + " is not visible.", false); } String genesis11 = "Indeed the people are one and they all have one language, and this is what they begin to do ..."; comments.sendKeys(genesis11); logger.log(Level.INFO, "Waiting for the comments to contain '" + genesis11 + "' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(commentsXpath), genesis11)); logger.log(Level.INFO, "comments.getText() = " + comments.getText()); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, commentsXpath)) { foo = comments.getText(); } assertTrue("comments should be correct after entering," + " but " + commentsXpath + " contains '" + foo + "'.", false); } // asserting correct data is still there assertTrue( "asserting that firstNameField.getText().equals('David'), " + "but it is '" + firstNameField.getAttribute("value") + "'", firstNameField.getAttribute("value").equals("David")); assertTrue( "asserting that lastNameField.getText().equals('Samuel'), " + "but it is '" + lastNameField.getAttribute("value") + "'", lastNameField.getAttribute("value").equals("Samuel")); assertTrue( "asserting that emailAddressField.getText().equals('no_need@just.pray'), " + "but it is '" + emailAddressField.getAttribute("value") + "'", emailAddressField.getAttribute("value").equals("no_need@just.pray")); assertTrue( "asserting that phoneNumberField.getText().equals('(way) too-good'), " + "but it is '" + phoneNumberField.getAttribute("value") + "'", phoneNumberField.getAttribute("value").equals("(way) too-good")); assertTrue( "asserting that dateOfBirthField.getText().equals('01/02/3456'), " + "but it is '" + dateOfBirthField.getAttribute("value") + "'", dateOfBirthField.getAttribute("value").equals("01/02/3456")); assertTrue( "asserting that postalCodeField.getText().equals('32801'), " + "but it is '" + postalCodeField.getAttribute("value") + "'", postalCodeField.getAttribute("value").equals("32801")); assertTrue("asserting that comments.getText().equals(genesis11), " + "but it is '" + comments.getAttribute("value") + "'", comments.getAttribute("value").equals(genesis11)); logger.log(Level.INFO, "Correct data asserted. Clicking submit button ..."); submitButton.click(); logger.log(Level.INFO, "Waiting for the text 'Dear ' to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(formTagXpath), "Dear ")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("formTag should contain 'Dear '," + " but " + formTagXpath + " does not contain 'Dear '.", false); } }