Example usage for org.openqa.selenium.support Color asHex

List of usage examples for org.openqa.selenium.support Color asHex

Introduction

In this page you can find the example usage for org.openqa.selenium.support Color asHex.

Prototype

public String asHex() 

Source Link

Usage

From source file:com.atanas.kanchev.testframework.selenium.handlers.Probe.java

License:Apache License

/**
 * {@inheritDoc}/*from   w  ww.  j av  a 2 s  .c o m*/
 */
@Override
public boolean hasColour(CommonPageDefinitions.CSS css, String expectedColorHexCode) {

    Color expColor;

    try {
        expColor = Color.fromString(expectedColorHexCode);
        logger.debug("Expected color: " + expColor.asHex());
    } catch (IllegalArgumentException e) {
        logger.error("Error processing color : " + expectedColorHexCode
                + " : color should have format : #[6 Hexadecimal Characters]");
        throw new IllegalArgumentException();
    }

    switch (css) {
    case CSS_BACKGROUND_COLOUR:
        Color backgroundColor = Color
                .fromString(((SeleniumContext) context().getCurrentContext()).getCurrentElement()
                        .getCssValue(CommonPageDefinitions.CSS.CSS_BACKGROUND_COLOUR.getDefinition()));
        logger.debug("Actual color: " + backgroundColor.asHex());
        return expColor.asHex().equals(backgroundColor.asHex());
    case CSS_TEXT_COLOUR:
        Color textColor = Color.fromString(((SeleniumContext) context().getCurrentContext()).getCurrentElement()
                .getCssValue(CommonPageDefinitions.CSS.CSS_TEXT_COLOUR.getDefinition()));
        logger.debug("Actual color: " + textColor.asHex());
        return expColor.asHex().equals(textColor.asHex());
    }

    return false;
}

From source file:jhc.redsniff.webdriver.matchers.ColorMatcher.java

License:Apache License

private String toString(Color color) {
    for (Colors namedColor : Colors.values()) {
        if (namedColor.getColorValue().equals(color))
            return namedColor.toString().toLowerCase();
    }//from w w w  .j  a  va 2 s  . c  o m
    return color.asHex().toLowerCase();
}