List of usage examples for org.openqa.selenium Keys TAB
Keys TAB
To view the source code for org.openqa.selenium Keys TAB.
Click Source Link
From source file:com.liferay.faces.test.FACES1439PortletTest.java
License:Open Source License
@Test @RunAsClient//from www . java 2s . c om @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.FACES1439PortletTest.java
License:Open Source License
@Test @RunAsClient//from w ww. j av a 2 s . c o m @InSequence(1300) public void inputThree() throws Exception { inputThree.sendKeys("Hello world 3"); logger.log(Level.INFO, "comments3Output.getText() = " + comments3Output.getText()); assertFalse("Model bean should not be updated yet since we have not tabbed-out of the field", comments3Output.getText().contains("Hello world 3")); inputThree.sendKeys(Keys.TAB); logger.log(Level.INFO, "comments3Output.getText() = " + comments3Output.getText()); assertTrue("Model bean needs to have been updated via ajax after tabbing-out of field", comments3Output.getText().contains("Hello world 3")); }
From source file:com.liferay.faces.test.Icefaces4PortletTest.java
License:Open Source License
@Test @RunAsClient//from w w w . j av a 2s.co 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.Icefaces4PortletTest.java
License:Open Source License
@Test @RunAsClient//w w w .j av a2 s .c om @InSequence(2000) public void validateEmail() throws Exception { String foo = ""; // checks an invalid email address logger.log(Level.INFO, "Entering an invalid email address 'test' ..."); emailAddressField.sendKeys("test"); phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain 'Invalid e-mail address' ..."); try { WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementLocated(By.xpath(emailAddressFieldErrorXpath), "Invalid e-mail address")); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("emailAddressField should be visible after tabbing out with no value," + " but " + emailAddressFieldErrorXpath + " is not visible.", false); } logger.log(Level.INFO, "emailAddressField.getAttribute('value') = " + emailAddressField.getAttribute("value")); assertTrue("Invalid e-mail address validation message displayed", emailAddressFieldError.getText().contains("Invalid e-mail address")); logger.log(Level.INFO, "emailAddressFieldError.isDisplayed() = " + emailAddressFieldError.isDisplayed()); logger.log(Level.INFO, "emailAddressFieldError.getText() = " + emailAddressFieldError.getText()); // checks a valid email address logger.log(Level.INFO, "Waiting for the emailAddressFieldError to contain '' ..."); try { emailAddressField.clear(); WebDriverWait wait = new WebDriverWait(browser, 10); wait.until(ExpectedConditions.textToBePresentInElementValue(By.xpath(emailAddressFieldXpath), "")); logger.log(Level.INFO, "emailAddressField.getText() = '" + emailAddressField.getText() + "'"); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); if (isThere(browser, emailAddressFieldXpath)) { foo = emailAddressField.getText(); } assertTrue("emailAddressField should be clear," + " but " + emailAddressFieldXpath + " contains '" + foo + "'", false); } logger.log(Level.INFO, "Entering a valid email address 'test@liferay.com' ..."); emailAddressField.click(); emailAddressField.sendKeys("test@liferay.com"); emailAddressField.sendKeys(Keys.TAB); phoneNumberField.click(); logger.log(Level.INFO, "Waiting for the emailAddressFieldError 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.invisibilityOfElementLocated(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.Jsf2FlowsPortletTest.java
License:Open Source License
@Test @RunAsClient// w w w . j av a 2 s . c om @InSequence(1000) public void flowsPortlet() throws Exception { signIn(browser); logger.log(Level.INFO, "browser.navigate().to(" + url + ")"); browser.navigate().to(url); logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle()); logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); getPortletDisplayName(); logger.log(Level.INFO, "displayName.getText() = " + displayName.getText()); if (isThere(browser, weldServletVersionXpath)) { logger.log(Level.INFO, "weldServletVersion.isDisplayed() = " + weldServletVersion.isDisplayed()); logger.log(Level.INFO, "weldServletVersion.getText() = " + weldServletVersion.getText()); } assertTrue("portletDisplayName displayName.isDisplayed()", displayName.isDisplayed()); if (isThere(browser, enterBookingFlowButtonXpath)) { enterBookingFlowButton.click(); try { waitForElement(browser, bookingTypeSelectXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("bookingTypeSelect should be visible, but " + bookingTypeSelectXpath + " is not there.", e == null); } exitBookingFlowButton.click(); try { waitForElement(browser, enterBookingFlowButtonXpath); logger.log(Level.INFO, "We exited the flow."); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("enterBookingFlowButton should be visible, but " + enterBookingFlowButtonXpath + " is not there.", e == null); } enterBookingFlowButton.click(); try { waitForElement(browser, bookingTypeSelectXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("bookingTypeSelect should be visible, but " + bookingTypeSelectXpath + " is not there.", e == null); } if (isThere(browser, bookingTypeSelectFlightXpath)) { bookingTypeSelectFlight.click(); waitForElement(browser, departureLaxXpath); departureLax.click(); waitForElement(browser, arrivalSdfXpath); arrivalSdf.click(); waitForElement(browser, departureDateXpath); departureDate.sendKeys("2015-08-12T00:00:01Z"); if (isThere(browser, searchFlightsButtonXpath)) { searchFlightsButton.click(); try { waitForElement(browser, addToCartButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "addToCartButton should be visible, but " + addToCartButtonXpath + " is not there.", e == null); } addToCartButton.click(); try { waitForElement(browser, bookAdditionalTravelButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("bookAdditionalTravelButton should be visible, but " + bookAdditionalTravelButtonXpath + " is not there.", e == null); } bookAdditionalTravelButton.click(); waitForElement(browser, bookingTypeSelectXpath); assertTrue("The selector for the booking type should be showing now, but it is not visible.", isThere(browser, bookingTypeSelectXpath)); if (isThere(browser, bookingTypeSelectFlightXpath)) { bookingTypeSelectCruise.click(); try { waitForElement(browser, onlyFlightBookingXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("onlyFlightBooking message should be visible, but " + onlyFlightBookingXpath + " is not there.", e == null); } bookingTypeSelectFlight.click(); waitForElement(browser, departureSdfXpath); departureSdf.click(); waitForElement(browser, arrivalMcoXpath); arrivalMco.click(); waitForElement(browser, departureDateXpath); departureDate.sendKeys("2015-08-12T00:00:01Z"); if (isThere(browser, searchFlightsButtonXpath)) { searchFlightsButton.click(); try { waitForElement(browser, addToCartButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("addToCartButton should be visible, but " + addToCartButtonXpath + " is not there.", e == null); } addToCartButton.click(); waitForElement(browser, checkoutButtonXpath); checkoutButton.click(); try { waitForElement(browser, purchaseButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("purchaseButton should be visible, but " + purchaseButtonXpath + " is not there.", e == null); } assertTrue("The firstName field should be vissible, but it is not.", isThere(browser, firstNameXpath)); if (isThere(browser, firstNameXpath)) { firstName.sendKeys("Gilbert"); firstName.sendKeys(Keys.TAB); } purchaseButton.click(); try { waitForElement(browser, thankYouFormPurchaseXpath); logger.log(Level.INFO, "We booked a flight."); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("thankYouForm for the purchase should be visible, but " + thankYouFormPurchaseXpath + " is not there.", e == null); } if (isThere(browser, callSurveyFlowButtonXpath)) { callSurveyFlowButton.click(); try { waitForElement(browser, finishButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("finishButton should be visible, but " + finishButtonXpath + " is not there.", e == null); } question1.sendKeys("Liferay"); question2.sendKeys("cockpit"); finishButton.click(); try { waitForElement(browser, returnFromSurveyFlowButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "returnFromSurveyFlowButton should be visible, but " + returnFromSurveyFlowButtonXpath + " is not there.", e == null); } returnFromSurveyFlowButton.click(); try { waitForElement(browser, enterBookingFlowButtonXpath); logger.log(Level.INFO, "We completed the survey flow. Yay!"); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("enterBookingFlowButton should be visible, but " + enterBookingFlowButtonXpath + " is not there.", e == null); } } } } } } } }
From source file:com.liferay.faces.test.JsfFlowsPortletTest.java
License:Open Source License
@Test @RunAsClient/*from w ww. j av a 2 s . c om*/ @InSequence(1000) public void flowsPortlet() throws Exception { signIn(browser); logger.log(Level.INFO, "browser.navigate().to(" + url + ")"); browser.navigate().to(url); logger.log(Level.INFO, "browser.getTitle() = " + browser.getTitle()); logger.log(Level.INFO, "browser.getCurrentUrl() = " + browser.getCurrentUrl()); if (isThere(browser, weldServletVersionXpath)) { logger.log(Level.INFO, "weldServletVersion.isDisplayed() = " + weldServletVersion.isDisplayed()); logger.log(Level.INFO, "weldServletVersion.getText() = " + weldServletVersion.getText()); } if (isThere(browser, enterBookingFlowButtonXpath)) { enterBookingFlowButton.click(); try { waitForElement(browser, bookingTypeSelectXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("bookingTypeSelect should be visible, but " + bookingTypeSelectXpath + " is not there.", e == null); } exitBookingFlowButton.click(); try { waitForElement(browser, enterBookingFlowButtonXpath); logger.log(Level.INFO, "We exited the flow."); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("enterBookingFlowButton should be visible, but " + enterBookingFlowButtonXpath + " is not there.", e == null); } enterBookingFlowButton.click(); try { waitForElement(browser, bookingTypeSelectXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("bookingTypeSelect should be visible, but " + bookingTypeSelectXpath + " is not there.", e == null); } if (isThere(browser, bookingTypeSelectFlightXpath)) { bookingTypeSelectFlight.click(); waitForElement(browser, departureLaxXpath); departureLax.click(); waitForElement(browser, arrivalSdfXpath); arrivalSdf.click(); waitForElement(browser, departureDateXpath); departureDate.sendKeys("2015-08-12T00:00:01Z"); if (isThere(browser, searchFlightsButtonXpath)) { searchFlightsButton.click(); try { waitForElement(browser, addToCartButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "addToCartButton should be visible, but " + addToCartButtonXpath + " is not there.", e == null); } addToCartButton.click(); try { waitForElement(browser, bookAdditionalTravelButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("bookAdditionalTravelButton should be visible, but " + bookAdditionalTravelButtonXpath + " is not there.", e == null); } bookAdditionalTravelButton.click(); waitForElement(browser, bookingTypeSelectXpath); assertTrue("The selector for the booking type should be showing now, but it is not visible.", isThere(browser, bookingTypeSelectXpath)); if (isThere(browser, bookingTypeSelectFlightXpath)) { bookingTypeSelectCruise.click(); try { waitForElement(browser, onlyFlightBookingXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("onlyFlightBooking message should be visible, but " + onlyFlightBookingXpath + " is not there.", e == null); } bookingTypeSelectFlight.click(); waitForElement(browser, departureSdfXpath); departureSdf.click(); waitForElement(browser, arrivalMcoXpath); arrivalMco.click(); waitForElement(browser, departureDateXpath); departureDate.sendKeys("2015-08-12T00:00:01Z"); if (isThere(browser, searchFlightsButtonXpath)) { searchFlightsButton.click(); try { waitForElement(browser, addToCartButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("addToCartButton should be visible, but " + addToCartButtonXpath + " is not there.", e == null); } addToCartButton.click(); waitForElement(browser, checkoutButtonXpath); checkoutButton.click(); try { waitForElement(browser, purchaseButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("purchaseButton should be visible, but " + purchaseButtonXpath + " is not there.", e == null); } assertTrue("The firstName field should be vissible, but it is not.", isThere(browser, firstNameXpath)); if (isThere(browser, firstNameXpath)) { firstName.sendKeys("Gilbert"); firstName.sendKeys(Keys.TAB); } purchaseButton.click(); try { waitForElement(browser, thankYouFormPurchaseXpath); logger.log(Level.INFO, "We booked a flight."); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("thankYouForm for the purchase should be visible, but " + thankYouFormPurchaseXpath + " is not there.", e == null); } if (isThere(browser, callSurveyFlowButtonXpath)) { callSurveyFlowButton.click(); try { waitForElement(browser, finishButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("finishButton should be visible, but " + finishButtonXpath + " is not there.", e == null); } question1.sendKeys("Liferay"); question2.sendKeys("cockpit"); finishButton.click(); try { waitForElement(browser, returnFromSurveyFlowButtonXpath); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue( "returnFromSurveyFlowButton should be visible, but " + returnFromSurveyFlowButtonXpath + " is not there.", e == null); } returnFromSurveyFlowButton.click(); try { waitForElement(browser, enterBookingFlowButtonXpath); logger.log(Level.INFO, "We completed the survey flow. Yay!"); } catch (Exception e) { logger.log(Level.INFO, "Exception e.getMessage() = " + e.getMessage()); assertTrue("enterBookingFlowButton should be visible, but " + enterBookingFlowButtonXpath + " is not there.", e == null); } } } } } } } }
From source file:com.liferay.faces.test.PlutoTest.java
License:Open Source License
@Test @RunAsClient//w w w .java 2s. c om @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//from ww w. j a v a 2s. c om @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); } }
From source file:com.mycompany.webcrawler.GmailAutomation.java
public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); DesiredCapabilities dcaps = new DesiredCapabilities(); dcaps.setCapability("takeScreenshot", true); //WebDriver driver = new PhantomJSDriver(dcaps); //Comment for PhantomJS ChromeDriver driver = new ChromeDriver(); //Comment for PhantomJS //driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); driver.get(/* w w w . java2 s. co m*/ "https://accounts.google.com/ServiceLogin?sacu=1&scc=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&osid=1&service=mail&ss=1<mpl=default&rm=false#identifier"); try { Thread.sleep(2000); driver.findElement(By.id("Email")).sendKeys("Your gmail goes here"); Thread.sleep(2000); driver.findElement(By.id("next")).click(); Thread.sleep(2000); driver.findElement(By.id("Passwd")).sendKeys("Your password goes here"); Thread.sleep(2000); driver.findElement(By.id("signIn")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji T-I-KE L3']")).click(); Thread.sleep(2000); driver.findElement(By.className("vO")).sendKeys("Who you want to send the email to"); Thread.sleep(2000); driver.findElement(By.className("aoT")).sendKeys("The subject"); Thread.sleep(2000); driver.switchTo().activeElement().sendKeys(Keys.TAB); driver.switchTo().activeElement().sendKeys("The body"); //Comment for PhantomJS //driver.findElement(By.xpath("//div[@class='Am Al editable LW-avf']")).sendKeys("Test Email"); Thread.sleep(2000); File file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(file, new File("screenshot.jpg")); Thread.sleep(2000); driver.findElement(By.xpath("//div[@class='T-I J-J5-Ji aoO T-I-atl L3']")).click(); //Comment for PhantomJS //Thread.sleep(2000); //driver.get("https://mail.google.com/mail/u/0/#sent"); } catch (IOException | InterruptedException | WebDriverException e) { System.out.println(e.getMessage()); } }
From source file:com.opera.core.systems.DriverKeysTest.java
License:Apache License
@Test public void testTab() { new Actions(driver).sendKeys("ab" + Keys.TAB + "c").build().perform(); assertEquals("ab", fieldOne.getAttribute("value")); assertEquals("c", fieldTwo.getAttribute("value")); }