List of usage examples for org.openqa.selenium WebElement getAttribute
String getAttribute(String name);
From source file:com.liferay.faces.test.showcase.buttonlink.ButtonLinkTester.java
License:Open Source License
private void clickButtonLink(BrowserDriver browserDriver, String xpath) { WebElement webElement = browserDriver.findElementByXpath(xpath); String tagName = webElement.getTagName(); String onclick = webElement.getAttribute("onclick"); browserDriver.clickElement(xpath);/*www . ja v a 2 s . c o m*/ // If the clicking the button/link will cause the page to reload. if (!"button".equals(tagName) || ((onclick != null) && !"".equals(onclick))) { browserDriver.waitFor(ExpectedConditions.stalenessOf(webElement)); waitForShowcasePageReady(browserDriver); } }
From source file:com.liferay.faces.test.showcase.portlet.NamespaceGeneralTester.java
License:Open Source License
@Test public void runPortletNamespaceGeneralTest() { BrowserDriver browserDriver = getBrowserDriver(); navigateToUseCase(browserDriver, "portlet", "namespace", "general"); // Test that the portlet namespace is rendered for both examples on the page. WaitingAsserter waitingAsserter = getWaitingAsserter(); WebElement liferayFacesBridgeBody = browserDriver .findElementByXpath("//div[contains(@class,'liferay-faces-bridge-body')]"); String portletNamespace = liferayFacesBridgeBody.getAttribute("id"); testPortletNamespaceRendered(browserDriver, waitingAsserter, portletNamespace, "//label[contains(.,'Example')][contains(.,'Introducing a var into the EL')]/ancestor::div[@class='showcase-example']//pre"); testPortletNamespaceRendered(browserDriver, waitingAsserter, portletNamespace, "//label[contains(.,'Example')][contains(.,'Output directly to the response')]/ancestor::div[@class='showcase-example']//pre"); }
From source file:com.liferay.faces.test.showcase.TesterBase.java
License:Open Source License
protected void assertImageRendered(BrowserDriver browserDriver, WaitingAsserter waitingAsserter, String imageXpath) {/*from w w w . java 2s . c o m*/ waitingAsserter.assertElementDisplayed(imageXpath); WebElement image = browserDriver.findElementByXpath(imageXpath); String imageSrc = image.getAttribute("src"); Assert.assertTrue("Image src " + imageSrc + " is not a valid JSF resource URL.", // Context-relative path: imageSrc.matches(".*/resources/images/[a-z-]+[.]png.*") || // JSF Resource URL: (imageSrc.matches(".*javax.faces.resource\\p{Punct}[a-z-]+[.]png.*") && imageSrc.matches(".*ln\\p{Punct}images.*"))); Boolean imageRendered = (Boolean) browserDriver.executeScriptInCurrentWindow( "return arguments[0].complete && typeof arguments[0].naturalWidth != 'undefined' && arguments[0].naturalWidth > 0", image); Assert.assertTrue("Image " + imageXpath + " (src=\"" + imageSrc + "\") is not rendered in the DOM.", imageRendered); }
From source file:com.liferay.faces.test.showcase.TesterBase.java
License:Open Source License
/** * Click the link and assert that it opens a new window/tab with the correct domain name. *///from w w w .j a va2 s . c o m protected void testLink(BrowserDriver browserDriver, WaitingAsserter waitingAsserter, String exampleLinkXpath, String domainNameRegex) { waitingAsserter.assertElementDisplayed(exampleLinkXpath); String newTabURL = null; String originalWindowHandle = null; Set<String> originalWindowIds = browserDriver.getWindowIds(); int initialNumberOfWindows = originalWindowIds.size(); WebElement linkElement = browserDriver.findElementByXpath(exampleLinkXpath); linkElement.click(); waitingAsserter.assertTrue(new WindowOpened(initialNumberOfWindows)); browserDriver.setPageLoadTimeout(5); try { Set<String> windowIds = new HashSet<String>(browserDriver.getWindowIds()); originalWindowHandle = browserDriver.getCurrentWindowId(); // Obtain the URL of the newly opened tab. windowIds.removeAll(originalWindowIds); browserDriver.switchToWindow(windowIds.iterator().next()); newTabURL = browserDriver.getCurrentWindowUrl(); } catch (TimeoutException e) { // The browser likely could not connect to the website. } // Reset to page load timeout to inifinity (the default). browserDriver.setPageLoadTimeout(-1); // If the url is null or "about:blank", the browser likely could not connect to the website, so fall back // to testing the link on the original page. if ((newTabURL == null) || "about:blank".equals(newTabURL)) { if (originalWindowHandle != null) { if (!isHeadlessChrome(browserDriver)) { browserDriver.closeCurrentWindow(); } browserDriver.switchToWindow(originalWindowHandle); } linkElement = browserDriver.findElementByXpath(exampleLinkXpath); newTabURL = linkElement.getAttribute("href"); } Pattern pattern = Pattern.compile(domainNameRegex); Assert.assertTrue("The url does not contain text matching the pattern " + domainNameRegex + ". The full URL is " + newTabURL + ".", pattern.matcher(newTabURL).find()); if ((originalWindowHandle != null) && !browserDriver.getCurrentWindowId().equals(originalWindowHandle)) { if (!isHeadlessChrome(browserDriver)) { browserDriver.closeCurrentWindow(); } browserDriver.switchToWindow(originalWindowHandle); } }
From source file:com.linagora.obm.ui.page.CalendarPage.java
License:Open Source License
private List<WebElement> messagesByClass(String clazz) { Builder<WebElement> builder = ImmutableList.builder(); for (WebElement message : messages) { if (clazz.equals(message.getAttribute("class"))) { builder.add(message);/*from w w w . j ava2s . c o m*/ } } return builder.build(); }
From source file:com.linagora.obm.ui.page.CreateUserPage.java
License:Open Source License
private void doCreateUser(UIUser userToCreate) { if (userToCreate.hasKindDefined()) { userKind.sendKeys(userToCreate.getKind().getUiFrenchText()); }//from w w w.j ava 2 s .c om userLogin.sendKeys(userToCreate.getLogin()); userFirstname.sendKeys(userToCreate.getFirstName()); userLastname.sendKeys(userToCreate.getLastName()); userCommonname.sendKeys(userToCreate.getCommonName()); passwd.sendKeys(userToCreate.getPassword()); userTitle.sendKeys(userToCreate.getTitle()); clickCheckbox(cba_hidden, userToCreate.isMailboxHidden()); clickCheckbox(cba_archive, userToCreate.isMailboxArchive()); delegationTargetField.sendKeys(userToCreate.getDelegation()); clickCheckbox(noexperie, !userToCreate.isNoExpire()); userPhone.sendKeys(userToCreate.getPhone()); userPhone2.sendKeys(userToCreate.getPhone2()); userMobile.sendKeys(userToCreate.getPhoneMobile()); userFax.sendKeys(userToCreate.getPhoneFax()); userFax2.sendKeys(userToCreate.getPhoneFax2()); userCompany.sendKeys(userToCreate.getCompany()); userDirection.sendKeys(userToCreate.getDirection()); userService.sendKeys(userToCreate.getService()); userAd1.sendKeys(userToCreate.getAddress1()); userAd2.sendKeys(userToCreate.getAddress2()); userAd3.sendKeys(userToCreate.getAddress3()); userZip.sendKeys(userToCreate.getAddressZip()); userTown.sendKeys(userToCreate.getAddressTown()); userCdx.sendKeys(userToCreate.getAddressCedex()); userDesc.sendKeys(userToCreate.getDescription()); if (clickCheckbox(userMailActive, userToCreate.isEmailInternalEnabled())) { WebElement firstInternalEmail = Iterables.getLast(internalEmailFields); firstInternalEmail.sendKeys(userToCreate.getEmailAddress()); } else { externalEmailField.sendKeys(userToCreate.getEmailAddress()); } SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); if (userToCreate.getDateBegin() != null) { userDatebegin.sendKeys(sdf.format(userToCreate.getDateBegin())); } if (userToCreate.getDateExpire() != null) { userDateexp.sendKeys(sdf.format(userToCreate.getDateExpire())); } for (WebElement domainOption : sel_profile.findElements(By.tagName("option"))) { if (domainOption.getAttribute("value").equals(String.valueOf(userToCreate.getProfile().getUiValue()))) { domainOption.click(); } } createUserSubmit.click(); }
From source file:com.linagora.obm.ui.page.widget.CalendarCalRangeWidget.java
License:Open Source License
private WebElement retrieveMonthlyElement() { if (monthlyElement != null) { return monthlyElement; }//from www .j av a 2 s . c o m List<WebElement> buttonElements = calendarCalRangeElement.findElements(new ByCssSelector("a")); for (WebElement webElement : buttonElements) { if (webElement.getAttribute("href").contains("month")) { return monthlyElement = webElement; } } throw new NoSuchElementException("monthlyElement"); }
From source file:com.linagora.obm.ui.page.widget.CalendarNavBarWidget.java
License:Open Source License
private WebElement navigateToNextPageOnCalendarView() { List<WebElement> buttonElements = calendarNavBarElement.findElements(new ByCssSelector("a")); for (WebElement webElement : buttonElements) { if (webElement.getAttribute("onclick").contains("showNext")) { return nextPageElement = webElement; }/* w w w . j a va 2 s. c om*/ } throw new NoSuchElementException("nextPageElementOnCalendarView"); }
From source file:com.linagora.obm.ui.page.widget.CalendarNavBarWidget.java
License:Open Source License
private WebElement navigateToNextPageOnOtherViews() { List<WebElement> buttonElements = calendarNavBarElement.findElements(new ByCssSelector("img")); for (WebElement webElement : buttonElements) { if (webElement.getAttribute("src").contains("next.png")) { return nextPageElement = webElement; }//from w w w .j av a2 s . com } throw new NoSuchElementException("nextPageElementOnOtherViews"); }
From source file:com.linagora.obm.ui.page.widget.CalendarViewWidget.java
License:Open Source License
public boolean isInAgendaView() { WebElement currentViewElement = calendarViewElement .findElement(new ByCssSelector("img[title='Vue calendrier, cette vue est ditable']")); return currentViewElement.getAttribute("src").contains("current.gif"); }