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

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

Introduction

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

Prototype

public static Color fromString(String value) 

Source Link

Usage

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

License:Apache License

/**
 * {@inheritDoc}// www.j  a  v a2s. 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:com.uttesh.selenium.testng.highcharts.HighCharts.java

protected Color getSeriesColorAtXAxisPosition(int series, String xAxisLabelValue) {
    //The series can vary depending on the structure of the chart, by default it is fine but if this doesn't work you may need to tweak the series
    int barNumber = getXAxisLabelsText().indexOf(xAxisLabelValue);
    //The below varies depending on the structure of the chart, by default we need to multiply by 4
    barNumber = barNumber * 4;//from  w  w  w  . ja v a 2 s  .  c o  m
    return Color.fromString(chart.findElement(By.cssSelector(
            ".highcharts-series-group > g:nth-of-type(" + series + ") > rect:nth-of-type(" + barNumber + ")"))
            .getAttribute("fill"));
}

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

License:Apache License

@Override
protected boolean matchesSafely(WebElement item, Description mismatchDescription) {
    Color actualColor = Color.fromString(item.getCssValue(attributeName));
    if (actualColor.equals(expectedColor))
        return true;
    else {//from www.  j a v a2 s.c  om
        mismatchDescription.appendText(attributeName + " was " + toString(actualColor));
        return false;
    }
}

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

License:Apache License

public static Matcher<WebElement> hasColor(String colorAsString) {
    return new ColorMatcher("color", Color.fromString(colorAsString));
}

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

License:Apache License

public static Matcher<WebElement> hasBackgroundColor(String colorAsString) {
    return new ColorMatcher("background-color", Color.fromString(colorAsString));
}