Skip to content

Commit b01e965

Browse files
committed
Expand Screenplay tests to use Color
This might resolve the issues I'm having with FF/Safari tests which fail, because they use different representations of color.
1 parent aca9d0f commit b01e965

4 files changed

Lines changed: 56 additions & 4 deletions

File tree

CSF.Screenplay.Selenium/Color.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,30 @@ public static Color Parse(string webColorValue)
337337
/// <param name="sysColor">The <see cref="System.Drawing.Color"/></param>
338338
/// <returns><see langword="false"/> if the two different colors represent the same sRGB color; <see langword="true"/> if not.</returns>
339339
public static bool operator !=(Color color, SysColor sysColor) => !(color == sysColor);
340+
341+
/// <summary>
342+
/// Gets a value indicating whether the specified <see cref="Color"/> and <see cref="System.Drawing.Color"/>
343+
/// are equal.
344+
/// </summary>
345+
/// <remarks>
346+
/// <para>Despite the type differences, two colors are equal if they represent the same sRGB color.</para>
347+
/// </remarks>
348+
/// <param name="color">The <see cref="Color"/></param>
349+
/// <param name="sysColor">The <see cref="System.Drawing.Color"/></param>
350+
/// <returns><see langword="true"/> if the two different colors represent the same sRGB color; <see langword="false"/> if not.</returns>
351+
public static bool operator ==(SysColor sysColor, Color color) => color.Equals(sysColor);
352+
353+
/// <summary>
354+
/// Gets a value indicating whether the specified <see cref="Color"/> and <see cref="System.Drawing.Color"/>
355+
/// are not equal.
356+
/// </summary>
357+
/// <remarks>
358+
/// <para>Despite the type differences, two colors are equal if they represent the same sRGB color.</para>
359+
/// </remarks>
360+
/// <param name="color">The <see cref="Color"/></param>
361+
/// <param name="sysColor">The <see cref="System.Drawing.Color"/></param>
362+
/// <returns><see langword="false"/> if the two different colors represent the same sRGB color; <see langword="true"/> if not.</returns>
363+
public static bool operator !=(SysColor sysColor, Color color) => !(color == sysColor);
340364

341365
/// <summary>
342366
/// Gets a value indicating whether the specified <see cref="Color"/> and <see cref="string"/> representation of a color
@@ -366,6 +390,34 @@ public static Color Parse(string webColorValue)
366390
/// <returns><see langword="false"/> if the current color and the string color representation indicate the same sRGB color; <see langword="true"/> if not.</returns>
367391
public static bool operator !=(Color color, string stringColor) => !(color == stringColor);
368392

393+
/// <summary>
394+
/// Gets a value indicating whether the specified <see cref="Color"/> and <see cref="string"/> representation of a color
395+
/// are equal.
396+
/// </summary>
397+
/// <remarks>
398+
/// <para>A color is equal to a string if the result of <see cref="TryParse(string, out Color)"/> is <see langword="true"/>
399+
/// and if the resulting parsed <see cref="Color"/> instance is equal to the current color.
400+
/// Note that this means that a color is never equal to a string which is not a valid color representation, or which is <see langword="null"/>.</para>
401+
/// </remarks>
402+
/// <param name="color">The <see cref="Color"/></param>
403+
/// <param name="stringColor">The string which represents a color</param>
404+
/// <returns><see langword="true"/> if the current color and the string color representation indicate the same sRGB color; <see langword="false"/> if not.</returns>
405+
public static bool operator ==(string stringColor, Color color) => color.Equals(stringColor);
406+
407+
/// <summary>
408+
/// Gets a value indicating whether the specified <see cref="Color"/> and <see cref="string"/> representation of a color
409+
/// are not equal.
410+
/// </summary>
411+
/// <remarks>
412+
/// <para>A color is equal to a string if the result of <see cref="TryParse(string, out Color)"/> is <see langword="true"/>
413+
/// and if the resulting parsed <see cref="Color"/> instance is equal to the current color.
414+
/// Note that this means that a color is never equal to a string which is not a valid color representation, or which is <see langword="null"/>.</para>
415+
/// </remarks>
416+
/// <param name="color">The <see cref="Color"/></param>
417+
/// <param name="stringColor">The string which represents a color</param>
418+
/// <returns><see langword="false"/> if the current color and the string color representation indicate the same sRGB color; <see langword="true"/> if not.</returns>
419+
public static bool operator !=(string stringColor, Color color) => !(color == stringColor);
420+
369421
#if !RECORD_STRUCT_SUPPORT
370422
/// <summary>
371423
/// Gets a value indicating whether the two specified <see cref="Color"/> instances are equal.

Tests/CSF.Screenplay.Selenium.Tests/Actions/ExecuteJavaScriptTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ public async Task ExecuteJavaScriptShouldBeAbleToExecuteAScriptWithParameters(IS
2424
await When(webster).AttemptsTo(ExecuteCustomScript(scriptBody).WithTheName("a script that changes the BG colour of an element").WithTheArguments("textContent", "#F00"));
2525
var backgroundColor = await Then(webster).Should(ReadFromTheElement(textContent).TheCssProperty("background-color"));
2626

27-
Assert.That(backgroundColor, Is.EqualTo("rgba(255, 0, 0, 1)"));
27+
Assert.That(backgroundColor, Is.EqualTo(Colors.RED));
2828
}
2929
}

Tests/CSF.Screenplay.Selenium.Tests/Builders/QueryPredicatePrototypeBuilderTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public void CssPropertyShouldCreateASpecificationThatUsesGetCssValue(QueryPredic
175175
.Setup(e => e.GetCssValue("color"))
176176
.Returns("rgba(0, 0, 255, 1)");
177177

178-
var sut = builder.CssProperty("color", v => v == "rgba(255, 0, 0, 1)").GetElementSpecification();
178+
var sut = builder.CssProperty("color", v => v == Colors.RED).GetElementSpecification();
179179

180180
Assert.Multiple(() =>
181181
{
@@ -196,7 +196,7 @@ public void CssPropertyWithValueShouldCreateASpecificationThatUsesGetCssValue(Qu
196196
.Setup(e => e.GetCssValue("color"))
197197
.Returns("rgba(0, 0, 255, 1)");
198198

199-
var sut = builder.CssProperty("color", "rgba(255, 0, 0, 1)").GetElementSpecification();
199+
var sut = builder.CssProperty("color", Colors.RED.ToRgbaString()).GetElementSpecification();
200200

201201
Assert.Multiple(() =>
202202
{

Tests/CSF.Screenplay.Selenium.Tests/Queries/QueriesTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task ReadingTheCssPropertyFromAnElementShouldReturnTheCorrectResult
4949
await Given(webster).WasAbleTo(OpenTheUrl(testPage));
5050
var result = await When(webster).AttemptsTo(ReadFromTheElement(backgroundDiv).TheCssProperty("background-color"));
5151

52-
Assert.That(result, Is.EqualTo("rgba(170, 170, 255, 1)"));
52+
Assert.That(result, Is.EqualTo(Selenium.Color.Parse("rgba(170, 170, 255, 1)")));
5353
}
5454

5555
[Test, Screenplay]

0 commit comments

Comments
 (0)