List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient//from w ww. j a va 2 s.c om @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//ww w . j av a2 s .c om @InSequence(6000) public void cityAndStateAutoPopulate() throws Exception { logger.log(Level.INFO, "Waiting for the cityField to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(cityFieldXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("cityField should be visible after submitting the form," + " but " + cityFieldXpath + " is not visible.", false); } logger.log(Level.INFO, "before cityField.getAttribute('value') = " + cityField.getAttribute("value")); logger.log(Level.INFO, "before provinceIdField.getAttribute('value') = " + provinceIdField.getAttribute("value")); logger.log(Level.INFO, "before postalCodeField.getAttribute('value') = " + postalCodeField.getAttribute("value")); assertTrue("cityField is empty", (cityField.getAttribute("value") == null || cityField.getAttribute("value").length() == 0)); assertTrue("provinceIdField is empty", (provinceIdField.getAttribute("value") == null || provinceIdField.getAttribute("value").length() == 0)); assertTrue("postalCodeField is empty", (postalCodeField.getAttribute("value") == null || postalCodeField.getAttribute("value").length() == 0)); postalCodeField.sendKeys("32801"); phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the cityField to contain 'Orlando' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(cityFieldXpath), "Orlando")); logger.log(Level.INFO, "after cityField.getAttribute('value') = " + cityField.getAttribute("value")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "cityField should conatin 'Orlando' after entering postal code 32801 and clicking into another field," + " but " + cityFieldXpath + " contains '" + cityField.getText() + "'", e == null); } logger.log(Level.INFO, "after postalCodeField.getAttribute('value') = " + postalCodeField.getAttribute("value")); assertTrue( "cityField should contain 'Orlando' after auto populating from postalCode, but instead contains '" + cityField.getAttribute("value") + "'", cityField.getAttribute("value").contains("Orlando")); // If the (primefaces) selector is empty if ("".equals(provinceIdSelectorXpath)) { logger.log(Level.INFO, " provinceIdFieldXpath tagName = " + browser.findElement(By.xpath(provinceIdFieldXpath)).getTagName()); logger.log(Level.INFO, " provinceIdFieldXpath id = " + browser.findElement(By.xpath(provinceIdFieldXpath)).getAttribute("id")); logger.log(Level.INFO, " provinceIdField value = " + provinceIdField.getAttribute("value")); assertTrue( "provinceIdField should contain 3, but instead it contains '" + provinceIdField.getAttribute("value") + "'", provinceIdField.getAttribute("value").contains("3")); } // otherwise, use the (primefaces) selector else { logger.log(Level.INFO, " provinceIdSelectorXpath tagName = " + browser.findElement(By.xpath(provinceIdSelectorXpath)).getTagName()); logger.log(Level.INFO, " provinceIdSelectorXpath id = " + browser.findElement(By.xpath(provinceIdSelectorXpath)).getAttribute("id")); logger.log(Level.INFO, " provinceIdSelectorXpath value = " + browser.findElement(By.xpath(provinceIdSelectorXpath)).getAttribute("value")); assertTrue( "provinceIdSelector should contain 3, but instead it contains '" + provinceIdSelector.getAttribute("value") + "'", provinceIdSelector.getAttribute("value").contains("3")); } assertTrue("postalCodeField contains 32801", postalCodeField.getAttribute("value").contains("32801")); }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient// w w w. j a v a 2s. co m @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/*w w w . ja va 2 s. c om*/ @InSequence(8500) public void fileUpload() throws Exception { boolean uploaded = false; if (isThere(browser, fileUploadChooserXpath)) { logger.log(Level.INFO, "isThere(browser, fileUploadChooserXpath) = " + isThere(browser, fileUploadChooserXpath)); } else { // the ice1-portlet seems to render the input type="file" in a separate iframe ... why bother? // assuming that this is the jsf-jsp-applicant-portlet and waiting for its 'Add Attachment' button to appear logger.log(Level.INFO, "Waiting for the //input[@type='submit' and @value='Add Attachment'] to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("//input[@type='submit' and @value='Add Attachment']"))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "'Add Attachment' should be visible," + " but //input[@type='submit' and @value='Add Attachment'] is not visible.", false); } // As of the time of this comment, only the jsf-jsp-applicant-portlet did not render a fileUploadChooser on the // front view logger.log(Level.INFO, "clicking the Add Attachment button ..."); browser.findElement(By.xpath("//input[@type='submit' and @value='Add Attachment']")).click(); logger.log(Level.INFO, "Waiting for the fileUploadChooser to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(fileUploadChooserXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("fileUploadChooser should be visible," + " but " + fileUploadChooserXpath + " is not visible.", false); } } logger.log(Level.INFO, "fileUploadChooser.getCssValue(transform) = " + fileUploadChooser.getCssValue("transform")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(visibility) = " + fileUploadChooser.getCssValue("visibility")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(display) = " + fileUploadChooser.getCssValue("display")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(display) = " + fileUploadChooser.getCssValue("display")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(opacity) = " + fileUploadChooser.getCssValue("opacity")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(height) = " + fileUploadChooser.getCssValue("height")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(width) = " + fileUploadChooser.getCssValue("width")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(overflow) = " + fileUploadChooser.getCssValue("overflow")); logger.log(Level.INFO, "fileUploadChooser.getAttribute(type) = " + fileUploadChooser.getAttribute("type")); logger.log(Level.INFO, "entering in " + getPathToJerseyFile() + " for fileUploadChooser ..."); // This was the magic that fixed the primefaces4 fileupload component the transform needed to be set to 'none' ((JavascriptExecutor) browser).executeScript("arguments[0].style.transform = 'none';", fileUploadChooser); // when transform is NOT set to 'none' then we get: // fileUploadChooser.getCssValue(transform) = matrix(4, 0, 0, 4, -300, 0) logger.log(Level.INFO, "fileUploadChooser.getCssValue(transform) = " + fileUploadChooser.getCssValue("transform")); try { // Workaround https://github.com/ariya/phantomjs/issues/10993 // By removing the multiple attribute from <input type="file" /> if (BROWSER_NAME.equals("phantomjs")) { ((JavascriptExecutor) browser).executeScript( "var multipleFileUploadElements = document.querySelectorAll('input[type=\"file\"][multiple]');" + "for (var i = 0; i < multipleFileUploadElements.length; i++) {" + "multipleFileUploadElements[i].removeAttribute('multiple');" + "}"); } fileUploadChooser.sendKeys(getPathToJerseyFile()); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (e.getMessage().contains("Element is not currently visible")) { Dimension windowDimension = browser.manage().window().getSize(); logger.log(Level.INFO, "windowDimension.height = " + windowDimension.height); logger.log(Level.INFO, "windowDimension.width = " + windowDimension.width); logger.log(Level.INFO, "attempting to resize the browser window ... "); browser.manage().window().setSize(new Dimension(1260, 747)); windowDimension = browser.manage().window().getSize(); logger.log(Level.INFO, "windowDimension.height = " + windowDimension.height); logger.log(Level.INFO, "windowDimension.width = " + windowDimension.width); fileUploadChooser.sendKeys(getPathToJerseyFile()); } else { assertTrue( "No unexpected exceptions should occur when clearing the dateOfBirthField, but one did occur with the following message: " + e.getMessage(), false); } } // submitFileXpath logger.log(Level.INFO, " submitFileXpath tagName = " + browser.findElement(By.xpath(submitFileXpath)).getTagName()); logger.log(Level.INFO, " submitFileXpath type = " + browser.findElement(By.xpath(submitFileXpath)).getAttribute("type")); logger.log(Level.INFO, "Waiting for the submitFile button to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(submitFileXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("submitFile should be visible," + " but " + submitFileXpath + " is not visible.", false); } logger.log(Level.INFO, "submitting the uploaded file ..."); submitFile.click(); logger.log(Level.INFO, "Waiting for the uploadedFile to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(uploadedFileXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("uploadedFileX should be visible," + " but " + uploadedFileXpath + " is not visible.", false); } if (isThere(browser, uploadedFileXpath)) { logger.log(Level.INFO, "uploadedFile.getText() = " + uploadedFile.getText() + " is there."); uploaded = true; } if (uploaded) { assertTrue("uploadedFile.getText().contains('jersey') after 3 seconds", uploadedFile.getText().contains("jersey")); } else { assertTrue("file should have been uploaded, but was not ...", uploaded); } }
From source file:com.liferay.faces.test.AlloyApplicantPortletTest.java
License:Open Source License
@Test @RunAsClient/*from w w w. j a v a 2 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); } }
From source file:com.liferay.faces.test.Icefaces4PortletTest.java
License:Open Source License
@Test @RunAsClient/* w w w . j a va 2 s . c o m*/ @InSequence(8500) public void fileUpload() throws Exception { boolean uploaded = false; if (isThere(browser, fileUploadChooserXpath)) { logger.log(Level.INFO, "isThere(browser, fileUploadChooserXpath) = " + isThere(browser, fileUploadChooserXpath)); } else { // the ice1-portlet seems to render the input type="file" in a separate iframe ... why bother? // assuming that this is the jsf2-jsp-portlet and waiting for its 'Add Attachment' button to appear logger.log(Level.INFO, "Waiting for the //input[@type='submit' and @value='Add Attachment'] to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath("//input[@type='submit' and @value='Add Attachment']"))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "'Add Attachment' should be visible," + " but //input[@type='submit' and @value='Add Attachment'] is not visible.", false); } // As of the time of this comment, only the jsf2-jsp-portlet did not render a fileUploadChooser on the // front view logger.log(Level.INFO, "clicking the Add Attachment button ..."); browser.findElement(By.xpath("//input[@type='submit' and @value='Add Attachment']")).click(); logger.log(Level.INFO, "Waiting for the fileUploadChooser to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(fileUploadChooserXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("fileUploadChooser should be visible," + " but " + fileUploadChooserXpath + " is not visible.", false); } } logger.log(Level.INFO, "fileUploadChooser.getCssValue(transform) = " + fileUploadChooser.getCssValue("transform")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(visibility) = " + fileUploadChooser.getCssValue("visibility")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(display) = " + fileUploadChooser.getCssValue("display")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(display) = " + fileUploadChooser.getCssValue("display")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(opacity) = " + fileUploadChooser.getCssValue("opacity")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(height) = " + fileUploadChooser.getCssValue("height")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(width) = " + fileUploadChooser.getCssValue("width")); logger.log(Level.INFO, "fileUploadChooser.getCssValue(overflow) = " + fileUploadChooser.getCssValue("overflow")); logger.log(Level.INFO, "fileUploadChooser.getAttribute(type) = " + fileUploadChooser.getAttribute("type")); logger.log(Level.INFO, "entering in " + getPathToJerseyFile() + " for fileUploadChooser ..."); // This was the magic that fixed the primefaces4 fileupload component the transform needed to be set to 'none' ((JavascriptExecutor) browser).executeScript("arguments[0].style.transform = 'none';", fileUploadChooser); // when transform is NOT set to 'none' then we get: // fileUploadChooser.getCssValue(transform) = matrix(4, 0, 0, 4, -300, 0) logger.log(Level.INFO, "fileUploadChooser.getCssValue(transform) = " + fileUploadChooser.getCssValue("transform")); try { fileUploadChooser.sendKeys(getPathToJerseyFile()); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (e.getMessage().contains("Element is not currently visible")) { Dimension windowDimension = browser.manage().window().getSize(); logger.log(Level.INFO, "windowDimension.height = " + windowDimension.height); logger.log(Level.INFO, "windowDimension.width = " + windowDimension.width); logger.log(Level.INFO, "attempting to resize the browser window ... "); browser.manage().window().setSize(new Dimension(1260, 747)); windowDimension = browser.manage().window().getSize(); logger.log(Level.INFO, "windowDimension.height = " + windowDimension.height); logger.log(Level.INFO, "windowDimension.width = " + windowDimension.width); fileUploadChooser.sendKeys(getPathToJerseyFile()); } else { assertTrue( "No unexpected exceptions should occur when clearing the dateOfBirthField, but one did occur with the following message: " + e.getMessage(), false); } } // submitFileXpath logger.log(Level.INFO, " submitFileXpath tagName = " + browser.findElement(By.xpath(submitFileXpath)).getTagName()); logger.log(Level.INFO, " submitFileXpath type = " + browser.findElement(By.xpath(submitFileXpath)).getAttribute("type")); logger.log(Level.INFO, "Waiting for the submitFile button to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(submitFileXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("submitFile should be visible," + " but " + submitFileXpath + " is not visible.", false); } logger.log(Level.INFO, "submitting the uploaded file ..."); submitFile.click(); logger.log(Level.INFO, "Waiting for the uploadedFile to show on the page ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(uploadedFileXpath))); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("uploadedFileX should be visible," + " but " + uploadedFileXpath + " is not visible.", false); } if (isThere(browser, uploadedFileXpath)) { logger.log(Level.INFO, "uploadedFile.getText() = " + uploadedFile.getText() + " is there."); uploaded = true; } if (uploaded) { assertTrue("uploadedFile.getText().contains('jersey') after 3 seconds", uploadedFile.getText().contains("jersey")); } else { assertTrue("file should have been uploaded, but was not ...", uploaded); } }
From source file:com.liferay.faces.test.Icefaces4PortletTest.java
License:Open Source License
@Test @RunAsClient// w ww . ja v a 2s . co 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"))); 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); } }
From source file:com.liferay.faces.test.selenium.browser.internal.WaitingAsserterImpl.java
License:Open Source License
@Override public void assertElementPresent(String elementXpath) { assertTrue(ExpectedConditions.presenceOfElementLocated(By.xpath(elementXpath))); }
From source file:com.linagora.obm.ui.page.CalendarPage.java
License:Open Source License
public CreateCalendarPage createCalendarPage() { newEventCalendar.click();//from w ww. j av a 2s.c om new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("tf_title"))); return pageFactory.create(driver, CreateCalendarPage.class); }
From source file:com.linagora.obm.ui.page.ContactPage.java
License:Open Source License
public CreateContactPage openCreateContactPage() { addContact.click();/* ww w. j av a2s. c om*/ new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("firstname"))); return pageFactory.create(driver, CreateContactPage.class); }