Skip to content

Commit 6c7c992

Browse files
committed
Further test coverage
1 parent f8e9fc2 commit 6c7c992

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

CSF.Screenplay.Selenium/Actions/OpenUrl.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ public class OpenUrl : IPerformable, ICanReport
1515
public ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)
1616
{
1717
var ability = actor.GetAbility<BrowseTheWeb>();
18-
ability.WebDriver.Url = uri.Uri.AbsoluteUri;
18+
ability.WebDriver.Url = uri.Uri.ToString();
1919
return default;
2020
}
2121

2222
/// <inheritdoc/>
2323
public ReportFragment GetReportFragment(Actor actor, IFormatsReportFragment formatter)
24-
=> formatter.Format("{Actor} opens their browser at {UriName}: {Uri}", actor.Name, uri.Name, uri.Uri.AbsoluteUri);
24+
=> formatter.Format("{Actor} opens their browser at {UriName}: {Uri}", actor.Name, uri.Name, uri.Uri.ToString());
2525

2626
/// <summary>
2727
/// Initializes a new instance of the <see cref="OpenUrl"/> class with the specified URL.

Tests/CSF.Screenplay.Selenium.Tests/NamedUriTests.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using System;
2+
using CSF.Screenplay.Selenium;
3+
14
namespace CSF.Screenplay.Selenium;
25

36
[TestFixture, Parallelizable]
@@ -26,4 +29,32 @@ public void RebaseToShouldReturnAUriWithTheSameName()
2629
var rebased = sut.RebaseTo("https://example.com");
2730
Assert.That(rebased.Name, Is.EqualTo("name"));
2831
}
32+
33+
[Test]
34+
public void RebaseToShouldThrowIfUriIsNull()
35+
{
36+
var sut = new NamedUri("test.html", "name");
37+
Assert.That(() => sut.RebaseTo(null), Throws.ArgumentNullException);
38+
}
39+
40+
[Test]
41+
public void RebaseToShouldThrowIfUriIsNullString()
42+
{
43+
var sut = new NamedUri("test.html", "name");
44+
Assert.That(() => sut.RebaseTo((string?) null), Throws.ArgumentNullException);
45+
}
46+
47+
[Test]
48+
public void ImplicitCastFromUriShouldCreateANamedUri()
49+
{
50+
NamedUri uri = new Uri("https://example.com/foo.html");
51+
Assert.That(uri.Uri.ToString(), Is.EqualTo("https://example.com/foo.html"));
52+
}
53+
54+
[Test]
55+
public void ImplicitCastFromStringShouldCreateANamedUri()
56+
{
57+
NamedUri uri = "https://example.com/foo.html";
58+
Assert.That(uri.Uri.ToString(), Is.EqualTo("https://example.com/foo.html"));
59+
}
2960
}

Tests/CSF.Screenplay.Selenium.Tests/Tasks/OpenUrlRespectingBaseTests.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,39 @@ public async Task TheActionCreatedByThisTaskShouldContainTheCorrectReport(IWebDr
4949
actor.EndPerformable -= OnPerform;
5050
}
5151
}
52+
53+
[Test, AutoMoqData]
54+
public async Task TheActionCreatedByThisTaskShouldContainTheCorrectReportWhenTheActorDoesNotHaveABaseUrl(IWebDriver driver, DriverOptions options)
55+
{
56+
var actor = new Actor("Anthony", Guid.NewGuid());
57+
IPerformable? performable = null;
58+
59+
void OnPerform(object? sender, PerformableEventArgs ev) => performable = (IPerformable)ev.Performable;
60+
61+
var namedUri = new NamedUri("test.html", "the test page");
62+
actor.IsAbleTo(new BrowseTheWeb(Mock.Of<IGetsWebDriver>(x => x.GetDefaultWebDriver(It.IsAny<Action<DriverOptions>>()) == new WebDriverAndOptions(driver, options))));
63+
var sut = new OpenUrlRespectingBase(namedUri);
64+
var valueFormatterProvider = new ValueFormatterProvider(new ServiceCollection().AddTransient<ToStringFormatter>().BuildServiceProvider(),
65+
new ValueFormatterRegistry { typeof(ToStringFormatter) });
66+
67+
var formatter = new ReportFragmentFormatter(new ReportFormatCreator(), valueFormatterProvider);
68+
69+
actor.EndPerformable += OnPerform;
70+
try
71+
{
72+
await sut.PerformAsAsync(actor);
73+
74+
Assert.Multiple(() =>
75+
{
76+
Assert.That(performable, Is.InstanceOf<OpenUrl>(), "Performable is correct type");
77+
Assert.That(((OpenUrl) performable!).GetReportFragment(actor, formatter).ToString(),
78+
Is.EqualTo("Anthony opens their browser at the test page: test.html"),
79+
"The report is correct");
80+
});
81+
}
82+
finally
83+
{
84+
actor.EndPerformable -= OnPerform;
85+
}
86+
}
5287
}

0 commit comments

Comments
 (0)