Example usage for org.openqa.selenium WebElement getCssValue

List of usage examples for org.openqa.selenium WebElement getCssValue

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getCssValue.

Prototype

String getCssValue(String propertyName);

Source Link

Document

Get the value of a given CSS property.

Usage

From source file:org.aludratest.service.gui.web.selenium.selenium2.condition.ZIndexSupport.java

License:Apache License

/** To get the z-index (defined in the attribute "style") for the operated element. There are 3 possibilities for retrieving
 * z-index: <br/>/*from  w w w.  ja  va2 s .co  m*/
 * <ol>
 * <li>If a z-index is defined for this element or its ancestor, then return this value</li>
 * <li>If no z-index is defined for this element and its ancestor, then use the base z-index for this page</li>
 * <li>For an element of the type "LabelLocator", the base z-index will be returned</li>
 * </ol>
 * @param element The element to check.
 * @return current z-Index */
private int getCurrentZIndex(WebElement element) {
    String zIndex = null;
    try {
        do {
            zIndex = element.getCssValue("z-index");
            element = locatorSupport.getParent(element);
        } while ("auto".equals(zIndex) && element != null);
    } catch (InvalidSelectorException e) {
        // this occurs when having reached the root element
    } catch (WebDriverException e) {
        // for PhantomJS, such an exception is thrown instead
        if (e.getMessage() == null || !e.getMessage().contains(" should be an element")) {
            throw e;
        }
        // otherwise OK
    }
    int value = parseZIndex(zIndex);
    LOGGER.trace("WebElement {} has z index {}", element, value);
    return value;
}

From source file:org.aludratest.service.gui.web.selenium.selenium2.ZIndexSupport.java

License:Apache License

/** To get the z-index (defined in the attribute "style") for the operated element. There are 3 possibilities for retrieving
 * z-index: <br/>/* w w w.j  a v  a2 s . c  om*/
 * 1) If a z-index is defined for this element or its ancestor, then return this value <br/>
 * 2) If no z-index is defined for this element and its ancestor, then use the base z-index for this page <br/>
 * 3) For an element of the type "LabelLocator", the base z-index will be returned
 * @param element The element to check.
 * @return current z-Index */
public int getCurrentZIndex(WebElement element) {
    String zIndex = null;
    try {
        do {
            zIndex = element.getCssValue("z-index");
            element = element.findElement(By.xpath(".."));
        } while ("auto".equals(zIndex) && element != null);
    } catch (InvalidSelectorException e) {
        // this occurs when having reached the root element
    }
    int value = parseZIndex(zIndex);
    LOGGER.debug("WebElement {} has z index {}", element, value);
    return value;
}

From source file:org.apache.flex.html.textButton.TextButton.java

License:Apache License

public static void main(String[] args) {
    WebDriver driver = new FirefoxDriver();

    Map<String, String> argsMap = new HashMap<String, String>();
    for (String arg : args) {
        String[] keyValuePair = arg.split("=");
        argsMap.put(keyValuePair[0], keyValuePair[1]);
    }/*from w  w w  . j  av  a2  s. c  om*/

    final String url = argsMap.get("url");

    driver.get(url);

    WebElement element = driver.findElement(By.tagName("button"));

    try {
        // there is a button in the DOM
        if (element != null) {
            // the button x position is 100
            if (element.getCssValue("left").equals("100px"))
                System.out.println(SUCCESS);
            else
                System.out.println(FAILED);
        } else {
            System.out.println(FAILED);
        }
    } catch (Exception e) {
        System.out.println(e.getMessage());
    } finally {
        driver.quit();
    }
}

From source file:org.auraframework.impl.clientlibrary.ClientLibraryTagUITest.java

License:Apache License

/**
 * Verify that Javascript and Style resources marked as combinable are available at the client.
 * clientLibraryTest:clientLibraryTest Moment, Walltime, js://clientLibraryTest.clientLibraryTest are marked as
 * combinable JS resources. css://clientLibraryTest.clientLibraryTest is marked as combinable CSS resource
 * //from   w w w .  j a v a 2  s .  c o m
 * @throws Exception
 */
public void testCombinableResources() throws Exception {
    open("/clientLibraryTest/clientLibraryTest.app");
    waitForAuraFrameworkReady();
    Object minuteThruMoment = auraUITestingUtil.getEval("return moment(new Date()).minutes()");
    assertNotNull(minuteThruMoment);
    assertEquals(Calendar.getInstance().get(Calendar.MINUTE), ((Long) minuteThruMoment).intValue());

    Boolean walltime = (Boolean) auraUITestingUtil.getEval("return !!WallTime");
    assertTrue(walltime);

    assertEquals("awesome", auraUITestingUtil.getEval("return clientLibraryTest.cool;"));

    WebElement div = findDomElement(By.cssSelector("div[class~='identifier']"));
    String divCss = div.getCssValue("background-color");
    assertEquals("CSS not loaded from combinable resource", "rgba(255, 0, 0, 1)", divCss);

}

From source file:org.auraframework.impl.ClientOutOfSyncUITest.java

License:Apache License

@ThreadHostileTest("NamespaceDef modification affects namespace")
public void testPostAfterStyleChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = Aura.getDefinitionService().getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-style:italic;}", className));
    addSourceAutoCleanup(Aura.getDefinitionService().getDefDescriptor(
            String.format("%s://%s", DefDescriptor.MARKUP_PREFIX, styleDesc.getNamespace()),
            NamespaceDef.class), "<aura:namespace/>");
    open(cmpDesc);//w  w w.  j  a v  a2  s  .  c om
    assertEquals("italic",
            auraUITestingUtil.findDomElement(By.cssSelector("." + className)).getCssValue("font-style"));
    updateStringSource(styleDesc, String.format(".%s {font-style:normal;}", className));
    triggerServerAction();
    auraUITestingUtil.waitForElementFunction(By.cssSelector("." + className),
            new Function<WebElement, Boolean>() {
                @Override
                public Boolean apply(WebElement element) {
                    return "normal".equals(element.getCssValue("font-style"));
                }
            });
}

From source file:org.auraframework.impl.ClientOutOfSyncUITest.java

License:Apache License

/**
 * A routine to do _many_ iterations of a client out of sync test.
 * //from   w  w  w  . ja va 2  s  .c  o m
 * This test really shouldn't be run unless one of the tests is flapping. It lets you iterate a number of times to
 * force a failure.... No guarantees, but without the _waitingForReload check in the trigger function, this will
 * cause a failure in very few iterations.
 */
@ThreadHostileTest("NamespaceDef modification affects namespace")
public void _testPostManyAfterStyleChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = Aura.getDefinitionService().getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-style:italic;}", className));
    addSourceAutoCleanup(Aura.getDefinitionService().getDefDescriptor(
            String.format("%s://%s", DefDescriptor.MARKUP_PREFIX, styleDesc.getNamespace()),
            NamespaceDef.class), "<aura:namespace/>");
    open(cmpDesc);
    assertEquals("italic",
            auraUITestingUtil.findDomElement(By.cssSelector("." + className)).getCssValue("font-style"));
    for (int i = 0; i < 1000; i++) {
        updateStringSource(styleDesc, String.format(".%s {font-style:normal;}", className));
        triggerServerAction();
        auraUITestingUtil.waitForElementFunction(By.cssSelector("." + className),
                new Function<WebElement, Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return "normal".equals(element.getCssValue("font-style"));
                    }
                });
        updateStringSource(styleDesc, String.format(".%s {font-style:italic;}", className));
        triggerServerAction();
        auraUITestingUtil.waitForElementFunction(By.cssSelector("." + className),
                new Function<WebElement, Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return "italic".equals(element.getCssValue("font-style"));
                    }
                });
    }
}

From source file:org.auraframework.impl.ClientOutOfSyncUITest.java

License:Apache License

@ThreadHostileTest("NamespaceDef modification affects namespace")
public void testPostAfterThemeChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = Aura.getDefinitionService().getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-size:t(fsize);}", className));
    DefDescriptor<?> themeDesc = Aura.getDefinitionService().getDefDescriptor(String.format("%s://%s:%sTheme",
            DefDescriptor.MARKUP_PREFIX, cmpDesc.getNamespace(), cmpDesc.getNamespace()), ThemeDef.class);
    addSourceAutoCleanup(themeDesc, "<aura:theme><aura:var name='fsize' value='8px'/></aura:theme>");
    open(cmpDesc);/*from  w w w  .j  a  v a2 s .c  o m*/
    assertEquals("8px",
            auraUITestingUtil.findDomElement(By.cssSelector("." + className)).getCssValue("font-size"));
    updateStringSource(themeDesc, "<aura:theme><aura:var name='fsize' value='66px'/></aura:theme>");
    triggerServerAction();
    auraUITestingUtil.waitForElementFunction(By.cssSelector("." + className),
            new Function<WebElement, Boolean>() {
                @Override
                public Boolean apply(WebElement element) {
                    return "66px".equals(element.getCssValue("font-size"));
                }
            });
}

From source file:org.auraframework.integration.test.ClientOutOfSyncUITest.java

License:Apache License

@ThreadHostileTest("NamespaceDef modification affects namespace")
@Test//w w  w  .  j ava2 s .c  o m
public void testPostAfterStyleChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = definitionService.getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-style:italic;}", className));
    open(cmpDesc);
    assertEquals("italic",
            getAuraUITestingUtil().findDomElement(By.cssSelector("." + className)).getCssValue("font-style"));
    updateStringSource(styleDesc, String.format(".%s {font-style:normal;}", className));
    triggerServerAction();
    getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
            new Function<WebElement, Boolean>() {
                @Override
                public Boolean apply(WebElement element) {
                    return "normal".equals(element.getCssValue("font-style"));
                }
            });
}

From source file:org.auraframework.integration.test.ClientOutOfSyncUITest.java

License:Apache License

/**
 * A routine to do _many_ iterations of a client out of sync test.
 *
 * This test really shouldn't be run unless one of the tests is flapping. It lets you iterate a number of times to
 * force a failure.... No guarantees, but without the _waitingForReload check in the trigger function, this will
 * cause a failure in very few iterations.
 *//*from  ww  w. j a va2  s .c o m*/
@ThreadHostileTest("NamespaceDef modification affects namespace")
@Test
@Ignore
public void testPostManyAfterStyleChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = definitionService.getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-style:italic;}", className));
    open(cmpDesc);
    assertEquals("italic",
            getAuraUITestingUtil().findDomElement(By.cssSelector("." + className)).getCssValue("font-style"));
    for (int i = 0; i < 1000; i++) {
        updateStringSource(styleDesc, String.format(".%s {font-style:normal;}", className));
        triggerServerAction();
        getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
                new Function<WebElement, Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return "normal".equals(element.getCssValue("font-style"));
                    }
                });
        updateStringSource(styleDesc, String.format(".%s {font-style:italic;}", className));
        triggerServerAction();
        getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
                new Function<WebElement, Boolean>() {
                    @Override
                    public Boolean apply(WebElement element) {
                        return "italic".equals(element.getCssValue("font-style"));
                    }
                });
    }
}

From source file:org.auraframework.integration.test.ClientOutOfSyncUITest.java

License:Apache License

@ThreadHostileTest("NamespaceDef modification affects namespace")
@Test/* w  w  w.  j  a v a2  s. c  om*/
public void testPostAfterTokensChange() throws Exception {
    DefDescriptor<ComponentDef> cmpDesc = setupTriggerComponent("", "<div id='out'>hi</div>");
    String className = cmpDesc.getNamespace() + StringUtils.capitalize(cmpDesc.getName());
    DefDescriptor<?> styleDesc = definitionService.getDefDescriptor(cmpDesc, DefDescriptor.CSS_PREFIX,
            StyleDef.class);
    addSourceAutoCleanup(styleDesc, String.format(".%s {font-size:t(fsize);}", className));
    DefDescriptor<?> tokensDesc = definitionService.getDefDescriptor(String.format("%s://%s:%sNamespace",
            DefDescriptor.MARKUP_PREFIX, cmpDesc.getNamespace(), cmpDesc.getNamespace()), TokensDef.class);
    addSourceAutoCleanup(tokensDesc, "<aura:tokens><aura:token name='fsize' value='8px'/></aura:tokens>");
    open(cmpDesc);
    assertEquals("8px",
            getAuraUITestingUtil().findDomElement(By.cssSelector("." + className)).getCssValue("font-size"));
    updateStringSource(tokensDesc, "<aura:tokens><aura:token name='fsize' value='66px'/></aura:tokens>");
    triggerServerAction();
    getAuraUITestingUtil().waitForElementFunction(By.cssSelector("." + className),
            new Function<WebElement, Boolean>() {
                @Override
                public Boolean apply(WebElement element) {
                    return "66px".equals(element.getCssValue("font-size"));
                }
            });
}