@Test public void styleIsChangedIfMarkingsAreActivated() { doReturn(Color.fromString("#aaaaaa")).when(configuration).getMarkingsColorReadBackground(); doReturn(Color.fromString("#bbbbbb")).when(configuration).getMarkingsColorReadOutline(); doReturn(true).when(configuration).isMarkingsEnabled(); cut.markAsRead(fragment); verify(styleChanger).changeStyleInformation(same(fragment), cssCaptor.capture()); Map<String, String> properties = cssCaptor.getValue(); assertThat(properties).containsEntry(CssProperties.OUTLINE_STYLE, "solid"); assertThat(properties).containsEntry(CssProperties.OUTLINE_WIDTH, "2px"); assertThat(properties).containsEntry(CssProperties.OUTLINE_COLOR, "#bbbbbb"); assertThat(properties).containsEntry(CssProperties.BACKGROUND_COLOR, "#aaaaaa"); }
@Test public void styleIsChangedIfMarkingsAreActivated() { doReturn(Color.fromString("#cccccc")).when(configuration).getMarkingsColorUsedBackground(); doReturn(Color.fromString("#dddddd")).when(configuration).getMarkingsColorUsedOutline(); doReturn(true).when(configuration).isMarkingsEnabled(); cut.markAsUsed(fragment); verify(styleChanger).changeStyleInformation(same(fragment), cssCaptor.capture()); Map<String, String> properties = cssCaptor.getValue(); assertThat(properties).containsEntry(CssProperties.OUTLINE_STYLE, "solid"); assertThat(properties).containsEntry(CssProperties.OUTLINE_WIDTH, "2px"); assertThat(properties).containsEntry(CssProperties.OUTLINE_COLOR, "#dddddd"); assertThat(properties).containsEntry(CssProperties.BACKGROUND_COLOR, "#cccccc"); }
private void markElement(PageFragment fragment, Color backgroundColor, Color outlineColor) { Map<String, String> cssStyleAttributes = new HashMap<>(); cssStyleAttributes.put(CssProperties.OUTLINE_STYLE, "solid"); cssStyleAttributes.put(CssProperties.OUTLINE_WIDTH, "2px"); cssStyleAttributes.put(CssProperties.OUTLINE_COLOR, outlineColor.asHex()); cssStyleAttributes.put(CssProperties.BACKGROUND_COLOR, backgroundColor.asHex()); styleChanger.changeStyleInformation(fragment, cssStyleAttributes); }
@Test void markingsColorUsedBackgroundCanBeChanged() { Color color = Colors.BLUEVIOLET.getColorValue(); Configuration configuration = cut.setMarkingsColorUsedBackground(color); assertThat(cut.getMarkingsColorUsedBackground()).isEqualTo(color); assertThat(configuration).isSameAs(cut); }
@Test void markingsColorUsedOutlineCanBeChanged() { Color color = Colors.ALICEBLUE.getColorValue(); Configuration configuration = cut.setMarkingsColorUsedOutline(color); assertThat(cut.getMarkingsColorUsedOutline()).isEqualTo(color); assertThat(configuration).isSameAs(cut); }
@Test void markingsColorReadBackgroundCanBeChanged() { Color color = Colors.ANTIQUEWHITE.getColorValue(); Configuration configuration = cut.setMarkingsColorReadBackground(color); assertThat(cut.getMarkingsColorReadBackground()).isEqualTo(color); assertThat(configuration).isSameAs(cut); }
@Test void markingsColorReadOutlineCanBeChanged() { Color color = Colors.AZURE.getColorValue(); Configuration configuration = cut.setMarkingsColorReadOutline(color); assertThat(cut.getMarkingsColorReadOutline()).isEqualTo(color); assertThat(configuration).isSameAs(cut); }
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; return Color.fromString(chart.findElement( By.cssSelector(".highcharts-series-group > g:nth-of-type(" + series + ") > rect:nth-of-type(" + barNumber + ")")) .getAttribute("fill")); }
/** * Marks the given {@link PageObject page object} as 'used' using the * configured colors from the page object's browser's {@link Configuration * configuration}. * * @param pageObject the page object to mark. * @since 0.9.6 */ public static void markAsUsed(PageObject pageObject) { Configuration configuration = pageObject.getBrowser().getConfiguration(); if (configuration.markingsAreActivated()) { Color backgroundColor = configuration.getMarkingsColorUsedBackground(); Color outlineColor = configuration.getMarkingsColorUsedOutline(); markElement(pageObject, backgroundColor, outlineColor); } }
/** * Marks the given {@link PageObject page object} as 'read' using the * configured colors from the page object's browser's {@link Configuration * configuration}. * * @param pageObject the page object to mark. * @since 1.2 */ public static void markAsRead(PageObject pageObject) { Configuration configuration = pageObject.getBrowser().getConfiguration(); if (configuration.markingsAreActivated()) { Color backgroundColor = configuration.getMarkingsColorReadBackground(); Color outlineColor = configuration.getMarkingsColorReadOutline(); markElement(pageObject, backgroundColor, outlineColor); } }
private static void markElement(PageObject pageObject, Color backgroundColor, Color outlineColor) { Map<CSSProperty, String> cssStyleAttributes = new HashMap<CSSProperty, String>(); cssStyleAttributes.put(CSSProperties.OUTLINE_STYLE, "solid"); cssStyleAttributes.put(CSSProperties.OUTLINE_WIDTH, "2px"); cssStyleAttributes.put(CSSProperties.OUTLINE_COLOR, outlineColor.asHex()); cssStyleAttributes.put(CSSProperties.BACKGROUND_COLOR, backgroundColor.asHex()); styleChanger.changeStyleInformation(pageObject, cssStyleAttributes); }
private String toString(Color color) { for (Colors namedColor : Colors.values()) { if (namedColor.getColorValue().equals(color)) return namedColor.toString().toLowerCase(); } return color.asHex().toLowerCase(); }
@Override protected boolean matchesSafely(WebElement item, Description mismatchDescription) { Color actualColor = Color.fromString(item.getCssValue(attributeName)); if (actualColor.equals(expectedColor)) return true; else { mismatchDescription.appendText(attributeName + " was " + toString(actualColor)); return false; } }
/** * Return the given attribute as a color or null if the attribute is not * specified. * * @param attributeName * @return */ public Color getAttributeAsColor(String attributeName) { try { return Color.fromString(element.getAttribute(attributeName)); } catch (Exception e) { return null; } }
@Override public Color getMarkingsColorUsedBackground() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_USED_BACKGROUND), "#ffd2a5")); }
@Override public BaseConfiguration setMarkingsColorUsedBackground(Color color) { return setProperty(key(NamedProperties.MARKINGS_USED_BACKGROUND), color.asHex()); }
@Override public Color getMarkingsColorUsedOutline() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_USED_OUTLINE), "#916f22")); }
@Override public BaseConfiguration setMarkingsColorUsedOutline(Color color) { return setProperty(key(NamedProperties.MARKINGS_USED_OUTLINE), color.asHex()); }
@Override public Color getMarkingsColorReadBackground() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_READ_BACKGROUND), "#90ee90")); }
@Override public Configuration setMarkingsColorReadBackground(Color color) { return setProperty(key(NamedProperties.MARKINGS_READ_BACKGROUND), color.asHex()); }
@Override public Color getMarkingsColorReadOutline() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_READ_OUTLINE), "#008000")); }
@Override public Configuration setMarkingsColorReadOutline(Color color) { return setProperty(key(NamedProperties.MARKINGS_READ_OUTLINE), color.asHex()); }
public Color getPrimarySeriesColourForXAxisLabel(String xAxisLabelValue) { return getSeriesColorAtXAxisPosition(2, xAxisLabelValue); }
public Color getSecondarySeriesColourForXAxisLabel(String xAxisLabelValue) { return getSeriesColorAtXAxisPosition(1, xAxisLabelValue); }
public Color getPrimarySeriesColourForXAxisLabel(String xAxisLabelValue) { return getSeriesColorAtXAxisPosition(1, xAxisLabelValue); }
public Color getSecondarySeriesColourForXAxisLabel(String xAxisLabelValue) { return getSeriesColorAtXAxisPosition(2, xAxisLabelValue); }
@Override public Color getMarkingsColorUsedBackground() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_COLOR_USED_BACKGROUND), "#ffd2a5")); }
@Override public BaseConfiguration setMarkingsColorUsedBackground(Color color) { return setProperty(key(NamedProperties.MARKINGS_COLOR_USED_BACKGROUND), color.toString()); }
@Override public Color getMarkingsColorUsedOutline() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_COLOR_USED_OUTLINE), "#916f22")); }
@Override public BaseConfiguration setMarkingsColorUsedOutline(Color color) { return setProperty(key(NamedProperties.MARKINGS_COLOR_USED_OUTLINE), color.toString()); }
@Override public Color getMarkingsColorReadBackground() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_COLOR_READ_BACKGROUND), "#90ee90")); }
@Override public BaseConfiguration setMarkingsColorReadBackground(Color color) { return setProperty(key(NamedProperties.MARKINGS_COLOR_READ_BACKGROUND), color.toString()); }
@Override public Color getMarkingsColorReadOutline() { return Color.fromString(getStringProperty(key(NamedProperties.MARKINGS_COLOR_READ_OUTLINE), "#008000")); }
@Override public BaseConfiguration setMarkingsColorReadOutline(Color color) { return setProperty(key(NamedProperties.MARKINGS_COLOR_READ_OUTLINE), color.toString()); }
protected ColorMatcher(String attributeName, Color expectedColor) { this.expectedColor = expectedColor; this.attributeName = attributeName; }
public static Matcher<WebElement> hasColor(String colorAsString) { return new ColorMatcher("color", Color.fromString(colorAsString)); }
public static Matcher<WebElement> hasBackgroundColor(String colorAsString) { return new ColorMatcher("background-color", Color.fromString(colorAsString)); }
@Override public boolean match(final String actualValue) { Color actualColor = Color.fromString(actualValue); Color expectedColor = Color.fromString(this.expectedColor); return actualColor.equals(expectedColor); }
protected ColorAssert assertThat(final Color color) { return new ColorAssert(color, ColorAssert.class); }
public Color fillColor() { return getAttributeAsColor("fill"); }