Skip to content

Commit 5946f57

Browse files
committed
Fixing HSL to RGB converter in Java
1 parent 515538a commit 5946f57

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

java/client/src/org/openqa/selenium/support/Color.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ protected Color createColor(Matcher matcher, double a) {
260260
b = hueToRgb(luminocity1, luminocity2, h - 1.0 / 3.0);
261261
}
262262

263-
return new Color((short) (r * 256),
264-
(short) (g * 256),
265-
(short) (b * 256),
263+
return new Color((short) Math.round(r * 255),
264+
(short) Math.round(g * 255),
265+
(short) Math.round(b * 255),
266266
a);
267267
}
268268

java/client/test/org/openqa/selenium/support/ColorTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ public void hslToRgba() {
106106
hsl = "hsl(100, 0%, 50%)";
107107
rgba = "rgba(128, 128, 128, 1)";
108108
assertEquals(rgba, Color.fromString(hsl).asRgba());
109+
hsl = "hsl(0, 100%, 50%)"; // red
110+
rgba = "rgba(255, 0, 0, 1)";
111+
assertEquals(rgba, Color.fromString(hsl).asRgba());
112+
hsl = "hsl(120, 100%, 50%)"; // green
113+
rgba = "rgba(0, 255, 0, 1)";
114+
assertEquals(rgba, Color.fromString(hsl).asRgba());
115+
hsl = "hsl(240, 100%, 50%)"; // blue
116+
rgba = "rgba(0, 0, 255, 1)";
117+
assertEquals(rgba, Color.fromString(hsl).asRgba());
118+
hsl = "hsl(0, 0%, 100%)"; // white
119+
rgba = "rgba(255, 255, 255, 1)";
120+
assertEquals(rgba, Color.fromString(hsl).asRgba());
109121
}
110122

111123
@Test

0 commit comments

Comments
 (0)