List of usage examples for org.openqa.selenium WebElement getCssValue
String getCssValue(String propertyName);
From source file:org.richfaces.tests.metamer.ftest.richPopupPanel.TestPopupPanel.java
License:Open Source License
private void checkCssValueOf(String cssValue, double value, WebElement element) { int tolerance = 5; assertEquals(Double.valueOf(element.getCssValue(cssValue).replace("px", "")), value, tolerance, cssValue + " of the panel"); }
From source file:org.richfaces.tests.metamer.ftest.richPopupPanel.TestPopupPanel.java
License:Open Source License
private void checkCssValueOf(String cssValue, double value, double tolerance, WebElement element) { assertEquals(Double.valueOf(element.getCssValue(cssValue).replace("px", "")), value, tolerance, cssValue + " of the panel"); }
From source file:org.richfaces.tests.metamer.ftest.richPopupPanel.TestPopupPanel.java
License:Open Source License
@Test(groups = "smoke") public void testInit() { assertPresent(openButton, "Button for opening popup should be on the page."); assertNotVisible(panel.advanced().getRootElement(), "Popup panel is visible."); openPopupPanel();/*from w w w. ja va 2s .co m*/ assertVisible(panel.advanced().getRootElement(), "Popup panel should be visible."); assertVisible(panel.advanced().getHeaderContentElement(), "Popup panel's header content should be visible."); assertVisible(panel.advanced().getHeaderControlsElement(), "Popup panel's header contols should be visible."); assertVisible(panel.advanced().getHeaderElement(), "Popup panel's header should be visible."); assertVisible(panel.advanced().getContentScrollerElement(), "Popup panel's scroller should be visible."); assertVisible(panel.advanced().getShadowElement(), "Popup panel's shadow should be visible."); WebElement resizerElement; for (ResizerLocation l : ResizerLocation.values()) { resizerElement = panel.advanced().getResizerElement(l); assertVisible(resizerElement, "Resizer" + l + " should be visible."); assertEquals(resizerElement.getCssValue("cursor"), l.toString().toLowerCase(Locale.ENGLISH) + "-resize"); } assertNotPresent(shade, "Mask should not be visible."); assertEquals(panel.advanced().getHeaderContentElement().getText(), "popup panel header", "Header's text"); assertTrue(panel.getBodyContent().getContentString().startsWith("Lorem ipsum"), "Panel's content should start with 'Lorem ipsum'."); assertTrue(panel.getBodyContent().getContentString().endsWith("hide this panel"), "Panel's content should end with 'hide this panel'."); }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
License:Open Source License
/** * Get css values of the object/*w w w .j ava2 s .c om*/ * @param element - WebElement * @return - return map as key and value pair */ public static Map<String, String> getCssValues(WebElement element) { String[] styleattr = { "color", "display", "float", "font-family", "font-size", "font-weight", "height", "white-space", "width", "background-color", "background-repeat", "visibility" }; Map<String, String> map = new HashMap<String, String>(); String val = null; for (int i = 0; i < styleattr.length; i++) { try { val = element.getCssValue(styleattr[i]); map.put(styleattr[i], val); } catch (Throwable t) { } } return map; }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
License:Open Source License
/** * get the value of a property. The property can be an attribute, a css-attribute, a true property field, or certain property methods. * @param element WebElement, from which to retrieve the property * @param property String, the property name * @return String, the value of the property * @throws SeleniumPlusException if the attribute or property is not found. * @see #getProperties(WebElement)// w w w . j a v a 2 s . c om */ public static String getProperty(WebElement element, String property) throws SeleniumPlusException { String value = null; String dbg = "WDLibrary.getProperty() "; try { try { value = element.getAttribute(property); } catch (Throwable x) { IndependantLog.debug(dbg + "getAttribute('" + property + "') threw " + x.getClass().getName() + ", " + x.getMessage()); } if (value == null) { IndependantLog.debug(dbg + "getAttribute('" + property + "') returned null. Trying getCssValue."); try { value = element.getCssValue(property); } catch (Throwable x) { IndependantLog.debug(dbg + "getCssValue('" + property + "') threw " + x.getClass().getName() + ", " + x.getMessage()); } //for a non-exist css-property, SeleniumWebDriver will return "" instead of null if (value != null && value.isEmpty()) { IndependantLog.debug( dbg + "getCssValue('" + property + "') returned empty value. Resetting to null."); value = null; } } if (value == null) { IndependantLog.debug(dbg + "trying wide getProperties() net."); Map<String, Object> props = getProperties(element); if (props.containsKey(property)) { value = props.get(property).toString(); } else { IndependantLog.debug(dbg + "getProperties() reports no property named '" + property + "'."); String keys = ""; for (String key : props.keySet()) keys += key + " "; IndependantLog.debug(dbg + "propertyNames: " + keys); } } if (value == null) { IndependantLog.debug(dbg + "trying *NATIVE JS function* to get property '" + property + "'"); StringBuffer script = new StringBuffer(); script.append(JavaScriptFunctions.SAP.sap_getProperty(true, property)); script.append("return sap_getProperty(arguments[0], arguments[1]);"); Object result = null; try { result = WDLibrary.executeJavaScriptOnWebElement(script.toString(), element, property); if (result != null) { IndependantLog.debug(dbg + " got '" + result + "' by *NATIVE JS function*."); value = result.toString(); if (!(result instanceof String)) { IndependantLog.warn(dbg + " the result is not String, it is " + result.getClass().getName() + ", may need more treatment."); } } } catch (SeleniumPlusException se) { IndependantLog.error(dbg + StringUtils.debugmsg(se)); } } if (value == null) { IndependantLog.error( dbg + "got nothing but (null) for all getProperty attempts using '" + property + "'"); throw new SeleniumPlusException(property + " not found."); } return value; } catch (Exception e) { IndependantLog.error(dbg + "caught " + e.getClass().getName() + ": " + e.getMessage()); throw new SeleniumPlusException(property + " not found.", SeleniumPlusException.CODE_PropertyNotFoundException); } }
From source file:org.slc.sli.selenium.controller.LoginSeleniumITest.java
License:Apache License
@Test public void testLoginPage() { driver.get(loginUrl);//from w w w . j a v a 2 s . co m /* * Test for invalid username */ WebElement username = driver.findElement(By.name("username")); username.sendKeys(testBadUser); // Before submission - error message should not be displayed WebElement errorMessage = driver.findElement(By.name("errorMessage")); assertTrue(errorMessage.getCssValue("display").equalsIgnoreCase("none")); WebElement loginForm = driver.findElement(By.name("loginForm")); loginForm.submit(); // After submission - error message should be displayed errorMessage = driver.findElement(By.name("errorMessage")); assertTrue(errorMessage.getCssValue("display").equalsIgnoreCase("block")); /* * Test for a valid username */ username = driver.findElement(By.name("username")); username.sendKeys(testUser); loginForm = driver.findElement(By.name("loginForm")); loginForm.submit(); WebElement body = driver.findElement(By.tagName("body")); String bodyText = body.getText(); assertTrue(bodyText.contains("Select an application")); driver.close(); }
From source file:org.uiautomation.ios.selenium.RenderedWebElementTest.java
License:Apache License
@Test public void testShouldPickUpStyleOfAnElement() { driver.get(pages.javascriptPage);/*w w w . j av a 2 s .co m*/ WebElement element = driver.findElement(By.id("green-parent")); String backgroundColour = element.getCssValue("background-color"); assertEquals("rgba(0, 128, 0, 1)", backgroundColour); element = driver.findElement(By.id("red-item")); backgroundColour = element.getCssValue("background-color"); assertEquals("rgba(255, 0, 0, 1)", backgroundColour); }
From source file:org.uiautomation.ios.selenium.RenderedWebElementTest.java
License:Apache License
@Test public void testGetCssValueShouldReturnStandardizedColour() { driver.get(pages.colorPage);/*from w w w .ja va 2 s.co m*/ WebElement element = driver.findElement(By.id("namedColor")); String backgroundColour = element.getCssValue("background-color"); assertEquals("rgba(0, 128, 0, 1)", backgroundColour); element = driver.findElement(By.id("rgb")); backgroundColour = element.getCssValue("background-color"); assertEquals("rgba(0, 128, 0, 1)", backgroundColour); }
From source file:org.uiautomation.ios.selenium.RenderedWebElementTest.java
License:Apache License
@Test public void testShouldAllowInheritedStylesToBeUsed() { driver.get(pages.javascriptPage);//from www .j a v a2s . com WebElement element = driver.findElement(By.id("green-item")); String backgroundColour = element.getCssValue("background-color"); assertEquals(backgroundColour, "rgba(0, 0, 0, 0)"); }
From source file:org.uiautomation.ios.selenium.RenderedWebElementTest.java
License:Apache License
@Test public void testShouldGetHeightCss() { driver.get(pages.javascriptPage);/*from ww w . j av a 2 s . co m*/ WebElement element = driver.findElement(By.id("green-item")); String height = element.getCssValue("height"); assertEquals("30px", height); }