List of usage examples for org.openqa.selenium WebElement getLocation
Point getLocation();
From source file:org.auraframework.components.ui.infiniteListRow.infiniteListRowUITest.java
License:Apache License
/** * Set x-coordinate of the container and x-coordinate for swipeBody to some variables for future reference * Helpful to check if element is within the viewport after swipe gestures */// w ww. j a v a 2 s . c o m private void setViewPortVariable() { WebElement container = findDomElement(By.cssSelector(DIV_CONTAINER)); container_x_coordinate = container.getLocation().getX(); WebElement row1 = getListRowElement(1); WebElement row1SwipeBody = getListRowSwipeBody(row1); swipeBody_x_coordinate = row1SwipeBody.getLocation().getX(); }
From source file:org.auraframework.components.ui.infiniteListRow.infiniteListRowUITest.java
License:Apache License
/** * Swipe and then verify if the element is within or outside of the viewport depending * on the swipe gesture performed//from w ww . j a va2 s .c om * @param elem * @param swipeOption * @throws InterruptedException */ private void swipeOnElementAndVerify(WebElement elem, swipeDirection swipeOption) throws InterruptedException { WebElement swipBody = getListRowSwipeBody(elem); WebElement eleBody = getListRowBody(elem); switch (swipeOption) { case SWIPE_LEFT: performFlick(elem, -10000, 0); waitForElementPresent( String.format("Swipe body for %s should be visible on the page after horizontal swipe", swipBody.getText()), swipBody); int swipeBody_xPos_SL = swipBody.getLocation().getX(); int eleBody_xPos_SL = eleBody.getLocation().getX(); boolean viewPortConditionForSwipeBody_SL = container_x_coordinate <= swipeBody_xPos_SL && swipeBody_xPos_SL <= swipeBody_x_coordinate; assertTrue(String.format("%s should be within the view port after horizontal Left swipe", swipBody.getText()), viewPortConditionForSwipeBody_SL); boolean viewPortConditionForListBody_SL = eleBody_xPos_SL < container_x_coordinate; assertTrue(String.format("%s should not be within the view port after horizontal Left swipe", eleBody.getText()), viewPortConditionForListBody_SL); break; case SWIPE_RIGHT: performFlick(swipBody, 10000, 0); waitForElementPresent(String.format("%s should be visible on the page", eleBody.getText()), elem); int swipeBody_xPos_SR = swipBody.getLocation().getX(); int eleBody_xPos_SR = eleBody.getLocation().getX(); boolean viewPortConditionForListBody_SR = container_x_coordinate <= eleBody_xPos_SR && eleBody_xPos_SR <= swipeBody_x_coordinate; assertTrue(String.format("%s should be within the view port after horizontal Right swipe", eleBody.getText()), viewPortConditionForListBody_SR); boolean viewPortConditionForSwipeBody_SR = swipeBody_xPos_SR >= swipeBody_x_coordinate; assertTrue(String.format("%s should be outside of the view port after horizontal Right swipe", swipBody.getText()), viewPortConditionForSwipeBody_SR); break; case SWIPE_VERTICAL_DOWN: int totalElementBeforeFlick = getAllListRows().size(); performFlick(elem, 0, -200); WebElement lastElement = getListRowElement(totalElementBeforeFlick); waitForElementPresent(String.format("Last Element %s should be visible on the page", getListRowBody(lastElement).getText()), lastElement); break; case SWIPE_VERTICAL_UP: performFlick(elem, 0, 200); break; } }
From source file:org.auraframework.components.ui.popup.PopupUITest.java
License:Apache License
/** * Sets a popup to open at a manual position (move left by 5px) * and verifies the popup opens at the specified location. * /*from w w w .j a v a 2s.com*/ * @throws Exception */ public void testPopupManualPosition() throws Exception { WebDriver driver = this.getDriver(); String triggerText = "Trigger" + randString(4); String popupText = "Target" + randString(4); String triggerLocator = "a[class='triggerExtendedTarget']"; int popupWidth = 100; int popupHeight = 220; int xCoord = 5; String cmpMarkup = "<aura:application>" + "<ui:popup>" + "<ui:popupTrigger class='triggerExtendedTarget' aura:id='triggerExtendedTarget' label='" + triggerText + "'/>" + "<ui:popupTarget aura:id='targetExtendedTarget' attachToBody='true' manualPosition='true' autoPosition='false'>" + "<div style='position: absolute; left: " + xCoord + "px;width: " + popupWidth + "px;height: " + popupHeight + "px'>" + popupText + "</div>" + "</ui:popupTarget>" + "</ui:popup>" + "</aura:application>"; DefDescriptor<ApplicationDef> appDef = addSourceAutoCleanup(ApplicationDef.class, cmpMarkup); String appUrl = String.format("/%s/%s.app", appDef.getNamespace(), appDef.getName()); // Open app and verify the trigger loads open(appUrl); // Click the trigger and verify popup launches WebElement trigger = driver.findElement(By.cssSelector(triggerLocator)); trigger.click(); waitForElementPresent("Popup did not launch", driver.findElement(By.cssSelector(POPUP_CONTAINER_TARGET))); WebElement containerTgt = driver.findElement(By.cssSelector(POPUP_CONTAINER_TARGET)); assertTrue("Popup does not contain specified text", containerTgt.getText().contains(popupText)); // Verify the popup location is as specified WebElement popupElem = driver.findElement(By.cssSelector(POPUP_CONTAINER_TARGET)); assertEquals("Popup position incorrect", xCoord, popupElem.getLocation().getX()); }
From source file:org.auraframework.integration.test.components.ui.infiniteListRow.infiniteListRowUITest.java
License:Apache License
/** * Swipe and then verify if the element is within or outside of the viewport depending * on the swipe gesture performed//from w w w .j ava 2s . c o m * @param elem * @param swipeOption * @throws InterruptedException */ private void swipeOnElementAndVerify(int elmRow, SwipeDirection swipeOption) throws InterruptedException { WebElement elm = getListRowElement(elmRow); WebElement swipBody; WebElement eleBody; switch (swipeOption) { case SWIPE_LEFT: performFlick(elm, -10000, 0); elm = getListRowElement(elmRow); swipBody = getListRowSwipeBody(elm); eleBody = getListRowBody(elm); getAuraUITestingUtil().waitUntil((driver) -> { return swipBody.isDisplayed(); }, String.format("Swipe body for %s should be visible on the page after horizontal swipe", swipBody.getText())); int swipeBody_xPos_SL = swipBody.getLocation().getX(); int eleBody_xPos_SL = eleBody.getLocation().getX(); boolean viewPortConditionForSwipeBody_SL = container_x_coordinate <= swipeBody_xPos_SL && swipeBody_xPos_SL <= swipeBody_x_coordinate; assertTrue(String.format("%s should be within the view port after horizontal Left swipe", swipBody.getText()), viewPortConditionForSwipeBody_SL); boolean viewPortConditionForListBody_SL = eleBody_xPos_SL < container_x_coordinate; assertTrue(String.format("%s should not be within the view port after horizontal Left swipe", eleBody.getText()), viewPortConditionForListBody_SL); break; case SWIPE_RIGHT: swipBody = getListRowSwipeBody(elm); performFlick(swipBody, 10000, 0); elm = getListRowElement(elmRow); eleBody = getListRowBody(elm); WebElement rowElement = elm; getAuraUITestingUtil().waitUntil((driver) -> { return rowElement.isDisplayed(); }, String.format("%s should be visible on the page", eleBody.getText())); int swipeBody_xPos_SR = swipBody.getLocation().getX(); int eleBody_xPos_SR = eleBody.getLocation().getX(); boolean viewPortConditionForListBody_SR = container_x_coordinate <= eleBody_xPos_SR && eleBody_xPos_SR <= swipeBody_x_coordinate; assertTrue(String.format("%s should be within the view port after horizontal Right swipe", eleBody.getText()), viewPortConditionForListBody_SR); boolean viewPortConditionForSwipeBody_SR = swipeBody_xPos_SR >= swipeBody_x_coordinate; assertTrue(String.format("%s should be outside of the view port after horizontal Right swipe", swipBody.getText()), viewPortConditionForSwipeBody_SR); break; case SWIPE_VERTICAL_DOWN: int totalElementBeforeFlick = getAllListRows().size(); performFlick(elm, 0, -200); WebElement lastElement = getListRowElement(totalElementBeforeFlick); getAuraUITestingUtil().waitUntil((driver) -> { return lastElement.isDisplayed(); }, String.format("Last Element %s should be visible on the page", getListRowBody(lastElement).getText())); break; case SWIPE_VERTICAL_UP: performFlick(elm, 0, 200); break; } }
From source file:org.auraframework.integration.test.components.ui.popup.PopupUITest.java
License:Apache License
/** * Sets a popup to open at a manual position (move left by 5px) * and verifies the popup opens at the specified location. * * @throws Exception/*from w w w . j a v a 2 s. c om*/ */ @Test public void testPopupManualPosition() throws Exception { WebDriver driver = this.getDriver(); String triggerText = "Trigger" + randString(4); String popupText = "Target" + randString(4); String triggerLocator = "a[class='triggerExtendedTarget']"; int popupWidth = 100; int popupHeight = 220; int xCoord = 5; String cmpMarkup = "<aura:application>" + "<ui:popup>" + "<ui:popupTrigger class='triggerExtendedTarget' aura:id='triggerExtendedTarget' label='" + triggerText + "'/>" + "<ui:popupTarget aura:id='targetExtendedTarget' attachToBody='true' manualPosition='true' autoPosition='false'>" + "<div style='position: relative; left: " + xCoord + "px;width: " + popupWidth + "px;height: " + popupHeight + "px'>" + popupText + "</div>" + "</ui:popupTarget>" + "</ui:popup>" + "</aura:application>"; DefDescriptor<ApplicationDef> appDef = addSourceAutoCleanup(ApplicationDef.class, cmpMarkup); String appUrl = String.format("/%s/%s.app", appDef.getNamespace(), appDef.getName()); // Open app and verify the trigger loads open(appUrl); // Click the trigger and verify popup launches WebElement trigger = driver.findElement(By.cssSelector(triggerLocator)); trigger.click(); getAuraUITestingUtil().waitForElementDisplayed(By.cssSelector(POPUP_CONTAINER_TARGET), "Popup did not launch"); WebElement containerTgt = driver.findElement(By.cssSelector(POPUP_CONTAINER_TARGET)); assertTrue("Popup does not contain specified text", containerTgt.getText().contains(popupText)); // Verify the popup location is as specified WebElement popupElem = driver.findElement(By.cssSelector(POPUP_CONTAINER_TARGET)); assertEquals("Popup position incorrect", xCoord, popupElem.getLocation().getX()); }
From source file:org.callimachusproject.webdriver.helpers.WebBrowserDriver.java
License:Apache License
public int getPositionBottom(By locator) { WebElement element = driver.findElement(locator); return element.getLocation().getY() + element.getSize().getHeight(); }
From source file:org.cybercat.automation.core.Browser.java
License:Apache License
/** * highlight active element with red color *//* www . j a v a 2 s . c om*/ public void highlightElement(WebElement element) { String bg = element.getCssValue("backgroundColor"); try { this.executeScript("arguments[0].style.backgroundColor = '" + "red" + "'", element); Point point = element.getLocation(); Dimension demention = new Dimension(point.x, point.y);// .getSize(); eventManager.notify(new TakeScreenshotEvent(this, EffectType.RESIZ_BY_WIDTH, point.getX() + demention.getWidth(), point.getY() + demention.getHeight())); } catch (Exception e) { e.printStackTrace(); } this.executeScript("arguments[0].style.backgroundColor = '" + bg + "'", element); }
From source file:org.finra.jtaf.ewd.utils.ScreenshotUtils.java
License:Apache License
/*** * You can use this method to take your control pictures. Note that the file should be a png. * /* ww w . j a v a2 s . c o m*/ * @param element * @param toSaveAs * @throws IOException * @throws WidgetException * @throws WidgetTimeoutException * @throws Exception */ public static void takeScreenshotOfElement(IElement element, File toSaveAs) throws IOException, WidgetException { for (int i = 0; i < 10; i++) { //Loop up to 10x to ensure a clean screenshot was taken log.info("Taking screen shot of locator " + element.getLocator() + " ... attempt #" + (i + 1)); //Scroll to element element.scrollTo(); //Take picture of the page WebDriver wd = SessionManager.getInstance().getCurrentSession().getWrappedDriver(); File screenshot; boolean isRemote = false; if (!(wd instanceof RemoteWebDriver)) { screenshot = ((TakesScreenshot) wd).getScreenshotAs(OutputType.FILE); } else { Augmenter augmenter = new Augmenter(); screenshot = ((TakesScreenshot) augmenter.augment(wd)).getScreenshotAs(OutputType.FILE); isRemote = true; } BufferedImage fullImage = ImageIO.read(screenshot); WebElement ele = element.getWebElement(); //Parse out the picture of the element Point point = ele.getLocation(); int eleWidth = ele.getSize().getWidth(); int eleHeight = ele.getSize().getHeight(); int x; int y; if (isRemote) { x = ((Locatable) ele).getCoordinates().inViewPort().getX(); y = ((Locatable) ele).getCoordinates().inViewPort().getY(); } else { x = point.getX(); y = point.getY(); } log.debug("Screenshot coordinates x: " + x + ", y: " + y); BufferedImage eleScreenshot = fullImage.getSubimage(x, y, eleWidth, eleHeight); ImageIO.write(eleScreenshot, "png", screenshot); //Ensure clean snapshot (sometimes WebDriver takes bad pictures and they turn out all black) if (!isBlack(ImageIO.read(screenshot))) { FileUtils.copyFile(screenshot, toSaveAs); break; } } }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
public int getHorizontalPosition(String locator) { WebElement element = finder.find(locator); Point point = element.getLocation(); LOG.createAppender().appendBold("Get Horizontal Position:").appendCss(locator) .appendProperty("X", point.getX()).log(); return point.getX(); }
From source file:org.jspringbot.keyword.selenium.SeleniumHelper.java
License:Open Source License
public int getVerticalPosition(String locator) { WebElement element = finder.find(locator); Point point = element.getLocation(); LOG.createAppender().appendBold("Get Vertical Position:").appendCss(locator) .appendProperty("Y", point.getY()).log(); return point.getY(); }