Skip to content

Commit c181d39

Browse files
asashourlukeis
authored andcommitted
Fix HtmlUnitWebElement.getCssValue
Return correct value for colors. Signed-off-by: Luke Inman-Semerau <[email protected]>
1 parent c8bc2ad commit c181d39

File tree

4 files changed

+37
-15
lines changed

4 files changed

+37
-15
lines changed

Diff for: java/client/src/org/openqa/selenium/htmlunit/HtmlUnitAlert.java

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public void authenticateUsing(Credentials credentials) {
7878
public void setCredentials(Credentials credentials) {
7979
}
8080

81-
8281
@Override
8382
public void handleAlert(Page page, String message) {
8483
Queue<String> queue = queues.get(page);

Diff for: java/client/src/org/openqa/selenium/htmlunit/HtmlUnitWebElement.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
import java.util.List;
2525
import java.util.concurrent.Callable;
2626

27+
import net.sourceforge.htmlunit.corejs.javascript.Undefined;
28+
2729
import org.openqa.selenium.By;
2830
import org.openqa.selenium.Dimension;
2931
import org.openqa.selenium.ElementNotVisibleException;
@@ -45,6 +47,8 @@
4547
import org.openqa.selenium.internal.Locatable;
4648
import org.openqa.selenium.internal.WrapsDriver;
4749
import org.openqa.selenium.internal.WrapsElement;
50+
import org.openqa.selenium.support.Color;
51+
import org.openqa.selenium.support.Colors;
4852
import org.w3c.dom.Attr;
4953
import org.w3c.dom.NamedNodeMap;
5054

@@ -69,8 +73,6 @@
6973
import com.google.common.base.Strings;
7074
import com.google.common.base.Throwables;
7175

72-
import net.sourceforge.htmlunit.corejs.javascript.Undefined;
73-
7476

7577
public class HtmlUnitWebElement implements WrapsDriver,
7678
FindsById, FindsByLinkText, FindsByXPath, FindsByTagName,
@@ -156,7 +158,6 @@ public void click() {
156158
new HtmlUnitWebElement(parent, referencedElement).click();
157159
}
158160
}
159-
160161
}
161162

162163
@Override
@@ -864,7 +865,33 @@ protected void assertElementNotStale() {
864865
public String getCssValue(String propertyName) {
865866
assertElementNotStale();
866867

867-
return getEffectiveStyle((HtmlElement) element, propertyName);
868+
String style = getEffectiveStyle((HtmlElement) element, propertyName);
869+
return getColor(style);
870+
}
871+
872+
private static String getColor(String name) {
873+
if ("null".equals(name)) {
874+
return "transparent";
875+
}
876+
if (name.startsWith("rgb(")) {
877+
return Color.fromString(name).asRgba();
878+
}
879+
880+
Colors colors = getColorsOf(name);
881+
if (colors != null) {
882+
return colors.getColorValue().asRgba();
883+
}
884+
return name;
885+
}
886+
887+
private static Colors getColorsOf(String name) {
888+
name = name.toUpperCase();
889+
for (Colors colors : Colors.values()) {
890+
if (colors.name().equals(name)) {
891+
return colors;
892+
}
893+
}
894+
return null;
868895
}
869896

870897
private String getEffectiveStyle(HtmlElement htmlElement, String propertyName) {

Diff for: java/client/src/org/openqa/selenium/htmlunit/build.desc

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ java_library(name = "htmlunit",
55
"//java/client/src/org/openqa/selenium:webdriver-api",
66
"//java/client/src/org/openqa/selenium/interactions",
77
"//java/client/src/org/openqa/selenium/remote:common",
8+
"//java/client/src/org/openqa/selenium/support:support",
89
"//third_party/java/htmlunit",
910
])

Diff for: java/client/test/org/openqa/selenium/CssValueTest.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,21 @@
1717

1818
package org.openqa.selenium;
1919

20-
import org.junit.Test;
21-
import org.openqa.selenium.testing.Ignore;
22-
import org.openqa.selenium.testing.JUnit4TestBase;
23-
import org.openqa.selenium.testing.JavascriptEnabled;
24-
import org.openqa.selenium.testing.NotYetImplemented;
25-
2620
import static org.hamcrest.Matchers.anyOf;
2721
import static org.hamcrest.Matchers.equalTo;
2822
import static org.junit.Assert.assertEquals;
2923
import static org.junit.Assert.assertThat;
30-
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
3124
import static org.openqa.selenium.testing.Ignore.Driver.MARIONETTE;
3225

26+
import org.junit.Test;
27+
import org.openqa.selenium.testing.Ignore;
28+
import org.openqa.selenium.testing.JUnit4TestBase;
29+
import org.openqa.selenium.testing.JavascriptEnabled;
30+
3331
public class CssValueTest extends JUnit4TestBase {
3432

3533
@JavascriptEnabled
3634
@Ignore(MARIONETTE)
37-
@NotYetImplemented(HTMLUNIT)
3835
@Test
3936
public void testShouldPickUpStyleOfAnElement() {
4037
driver.get(pages.javascriptPage);
@@ -52,7 +49,6 @@ public void testShouldPickUpStyleOfAnElement() {
5249

5350
@JavascriptEnabled
5451
@Ignore(MARIONETTE)
55-
@NotYetImplemented(HTMLUNIT)
5652
@Test
5753
public void testGetCssValueShouldReturnStandardizedColour() {
5854
driver.get(pages.colorPage);
@@ -68,7 +64,6 @@ public void testGetCssValueShouldReturnStandardizedColour() {
6864
}
6965

7066
@JavascriptEnabled
71-
@NotYetImplemented(HTMLUNIT)
7267
@Test
7368
public void testShouldAllowInheritedStylesToBeUsed() {
7469
driver.get(pages.javascriptPage);

0 commit comments

Comments
 (0)