下面列出了怎么用org.openqa.selenium.support.Color的API类实例代码及写法,或者点击链接到github查看源代码。
@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);
}
public static ExpectedCondition<QAFExtendedWebElement, Boolean> elementCssColorPropertyValueEq(final String propertyName,
final Object val) {
return new ExpectedCondition<QAFExtendedWebElement, Boolean>() {
@Override
public Boolean apply(QAFExtendedWebElement element) {
return Color.fromString(element.getCssValue(propertyName)).asRgba().equals(Color.fromString(String.valueOf(val)).asRgba());
}
};
}
public static ExpectedCondition<QAFExtendedWebElement, Boolean> elementCssColorPropertyValueNotEq(
final String propertyName, final Object val) {
return new ExpectedCondition<QAFExtendedWebElement, Boolean>() {
@Override
public Boolean apply(QAFExtendedWebElement element) {
return !Color.fromString(element.getCssValue(propertyName)).asRgba().equals(Color.fromString(String.valueOf(val)).asRgba());
}
};
}
/**
* 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);
}
@Test
@Ignore(value = MARIONETTE, issue = "https://github.com/mozilla/geckodriver/issues/789")
@NotYetImplemented(HTMLUNIT)
@NotYetImplemented(SAFARI)
@NotYetImplemented(EDGE)
public void testCanMoveOverAndOutOfAnElement() {
driver.get(pages.mouseOverPage);
WebElement greenbox = driver.findElement(By.id("greenbox"));
WebElement redbox = driver.findElement(By.id("redbox"));
Dimension greenSize = greenbox.getSize();
Dimension redSize = redbox.getSize();
new Actions(driver).moveToElement(greenbox, 1 - greenSize.getWidth() / 2, 1 - greenSize.getHeight() / 2).perform();
assertThat(Color.fromString(redbox.getCssValue("background-color")))
.isEqualTo(GREEN.getColorValue());
new Actions(driver).moveToElement(redbox).perform();
assertThat(Color.fromString(redbox.getCssValue("background-color")))
.isEqualTo(RED.getColorValue());
// IE8 (and *only* IE8) requires a move of 2 pixels. All other browsers
// would be happy with 1.
new Actions(driver).moveToElement(redbox, redSize.getWidth() / 2 + 2, redSize.getHeight() / 2 + 2)
.perform();
wait.until(attributeToBe(redbox, "background-color", Colors.GREEN.getColorValue().asRgba()));
}
@Test
public void testShouldPickUpStyleOfAnElement() {
driver.get(pages.javascriptPage);
WebElement element = driver.findElement(By.id("green-parent"));
Color backgroundColour = Color.fromString(element.getCssValue("background-color"));
assertThat(backgroundColour).isEqualTo(new Color(0, 128, 0, 1));
element = driver.findElement(By.id("red-item"));
backgroundColour = Color.fromString(element.getCssValue("background-color"));
assertThat(backgroundColour).isEqualTo(new Color(255, 0, 0, 1));
}
@Test
public void testGetCssValueShouldReturnStandardizedColour() {
driver.get(pages.colorPage);
WebElement element = driver.findElement(By.id("namedColor"));
Color backgroundColour = Color.fromString(element.getCssValue("background-color"));
assertThat(backgroundColour).isEqualTo(new Color(0, 128, 0, 1));
element = driver.findElement(By.id("rgb"));
backgroundColour = Color.fromString(element.getCssValue("background-color"));
assertThat(backgroundColour).isEqualTo(new Color(0, 128, 0, 1));
}
@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());
}
@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"));
}