Skip to content

Commit 23f65fe

Browse files
committed
Provisionally resolve #242 - more useful type names
This means that people reading reports will see more useful human readable names of types which are involved in Performances.
1 parent ad2d2c6 commit 23f65fe

12 files changed

Lines changed: 40 additions & 6 deletions

CSF.Screenplay.Selenium/Actions/SingleElementPerformableAdapter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace CSF.Screenplay.Selenium.Actions
1818
/// to fetch it using the WebDriver more than once. As such, instances of this adapter (like all performables) should not be re-used.
1919
/// </para>
2020
/// </remarks>
21-
public class SingleElementPerformableAdapter : IPerformable, ICanReport
21+
public class SingleElementPerformableAdapter : IPerformable, ICanReport, IHasCustomTypeName
2222
{
2323
readonly ISingleElementPerformable performable;
2424
readonly ITarget target;
@@ -38,6 +38,10 @@ public ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellatio
3838
return performable.PerformAsAsync(actor, actor.GetAbility<BrowseTheWeb>().WebDriver, lazyElement, cancellationToken);
3939
}
4040

41+
/// <inheritdoc/>
42+
public string GetHumanReadableTypeName()
43+
=> $"{performable.GetType().FullName}, via {nameof(SingleElementPerformableAdapter)}";
44+
4145
/// <summary>
4246
/// Initializes a new instance of the <see cref="SingleElementPerformableAdapter"/> class with the specified performable and target.
4347
/// </summary>

CSF.Screenplay.Selenium/Questions/ElementCollectionPerformableWithResultAdapter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace CSF.Screenplay.Selenium.Questions
1919
/// to fetch it using the WebDriver more than once. As such, instances of this adapter (like all performables) should not be re-used.
2020
/// </para>
2121
/// </remarks>
22-
public class ElementCollectionPerformableWithResultAdapter<TResult> : IPerformableWithResult<IReadOnlyList<TResult>>, ICanReport
22+
public class ElementCollectionPerformableWithResultAdapter<TResult> : IPerformableWithResult<IReadOnlyList<TResult>>, ICanReport, IHasCustomTypeName
2323
{
2424
readonly IElementCollectionPerformableWithResult<TResult> performable;
2525
readonly ITarget target;
@@ -39,6 +39,10 @@ public ValueTask<IReadOnlyList<TResult>> PerformAsAsync(ICanPerform actor, Cance
3939
return performable.PerformAsAsync(actor, actor.GetAbility<BrowseTheWeb>().WebDriver, lazyElements, cancellationToken);
4040
}
4141

42+
/// <inheritdoc/>
43+
public string GetHumanReadableTypeName()
44+
=> $"{performable.GetHumanReadableTypeName()}, via {nameof(ElementCollectionPerformableWithResultAdapter)}";
45+
4246
/// <summary>
4347
/// Initializes a new instance of the <see cref="ElementCollectionPerformableWithResultAdapter{TResult}"/> class with the specified performable and target.
4448
/// </summary>

CSF.Screenplay.Selenium/Questions/ElementCollectionQuery.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ public ReportFragment GetReportFragment(Actor actor, Lazy<SeleniumElementCollect
5757
public ValueTask<IReadOnlyList<TResult>> PerformAsAsync(ICanPerform actor, IWebDriver webDriver, Lazy<SeleniumElementCollection> elements, CancellationToken cancellationToken = default)
5858
=> new ValueTask<IReadOnlyList<TResult>>(elements.Value.Select(query.GetValue).ToList());
5959

60+
/// <inheritdoc/>
61+
public string GetHumanReadableTypeName()
62+
=> $"{query.GetType().FullName}, via {nameof(ElementCollectionQuery)}";
63+
6064
/// <summary>
6165
/// Initializes a new instance of the <see cref="ElementCollectionQuery{TResult}"/> class with the specified query.
6266
/// </summary>

CSF.Screenplay.Selenium/Questions/FindElement.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public ValueTask<SeleniumElement> PerformAsAsync(ICanPerform actor, IWebDriver w
7070

7171
string GetElementsName(SeleniumElement element) => elementsName ?? $"{locatorBasedMatcher?.Name} within {element.Name}";
7272

73+
/// <inheritdoc/>
74+
public string GetHumanReadableTypeName() => GetType().FullName;
75+
7376
/// <summary>
7477
/// Initializes a new instance of the <see cref="FindElement"/> class.
7578
/// </summary>

CSF.Screenplay.Selenium/Questions/FindElements.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public ValueTask<SeleniumElementCollection> PerformAsAsync(ICanPerform actor, IW
6969

7070
string GetElementsName(SeleniumElement element) => elementsName ?? $"{locatorBasedMatcher?.Name} within {element.Name}";
7171

72+
/// <inheritdoc/>
73+
public string GetHumanReadableTypeName() => GetType().FullName;
74+
7275
/// <summary>
7376
/// Initializes a new instance of the <see cref="FindElements"/> class.
7477
/// </summary>

CSF.Screenplay.Selenium/Questions/GetShadowRootNatively.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public class GetShadowRootNatively : ISingleElementPerformableWithResult<Seleniu
3434
public ReportFragment GetReportFragment(Actor actor, Lazy<SeleniumElement> element, IFormatsReportFragment formatter)
3535
=> formatter.Format("{Actor} gets the Shadow Root node from {Element} using the native Selenium technique", actor, element.Value);
3636

37+
/// <inheritdoc/>
38+
public string GetHumanReadableTypeName() => GetType().FullName;
39+
3740
/// <inheritdoc/>
3841
public ValueTask<SeleniumElement> PerformAsAsync(ICanPerform actor, IWebDriver webDriver, Lazy<SeleniumElement> element, CancellationToken cancellationToken = default)
3942
{

CSF.Screenplay.Selenium/Questions/GetShadowRootWithJavaScript.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public class GetShadowRootWithJavaScript : ISingleElementPerformableWithResult<S
3535
public ReportFragment GetReportFragment(Actor actor, Lazy<SeleniumElement> element, IFormatsReportFragment formatter)
3636
=> formatter.Format("{Actor} gets the Shadow Root node from {Element} using JavaScript", actor, element.Value);
3737

38+
/// <inheritdoc/>
39+
public string GetHumanReadableTypeName() => GetType().FullName;
40+
3841
/// <inheritdoc/>
3942
public async ValueTask<SeleniumElement> PerformAsAsync(ICanPerform actor, IWebDriver webDriver, Lazy<SeleniumElement> element, CancellationToken cancellationToken = default)
4043
{

CSF.Screenplay.Selenium/Questions/IElementCollectionPerformableWithResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace CSF.Screenplay.Selenium.Questions
2121
/// <see cref="SingleElementPerformableWithResultAdapter{TResult}"/>.
2222
/// </para>
2323
/// </remarks>
24-
public interface IElementCollectionPerformableWithResult<TResult> : ICanReportForElements
24+
public interface IElementCollectionPerformableWithResult<TResult> : ICanReportForElements, IHasCustomTypeName
2525
{
2626
/// <summary>
2727
/// Counterpart to <see cref="IPerformableWithResult{TResult}.PerformAsAsync(ICanPerform, CancellationToken)"/> except that this method also offers

CSF.Screenplay.Selenium/Questions/ISingleElementPerformableWithResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace CSF.Screenplay.Selenium.Questions
2020
/// <see cref="SingleElementPerformableWithResultAdapter{TResult}"/>.
2121
/// </para>
2222
/// </remarks>
23-
public interface ISingleElementPerformableWithResult<TResult> : ICanReportForElement
23+
public interface ISingleElementPerformableWithResult<TResult> : ICanReportForElement, IHasCustomTypeName
2424
{
2525
/// <summary>
2626
/// Counterpart to <see cref="IPerformableWithResult{TResult}.PerformAsAsync(ICanPerform, CancellationToken)"/> except that this method also offers

CSF.Screenplay.Selenium/Questions/SingleElementPerformableWithResultAdapter.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace CSF.Screenplay.Selenium.Questions
1818
/// to fetch it using the WebDriver more than once. As such, instances of this adapter (like all performables) should not be re-used.
1919
/// </para>
2020
/// </remarks>
21-
public class SingleElementPerformableWithResultAdapter<TResult> : IPerformableWithResult<TResult>, ICanReport
21+
public class SingleElementPerformableWithResultAdapter<TResult> : IPerformableWithResult<TResult>, ICanReport, IHasCustomTypeName
2222
{
2323
readonly ISingleElementPerformableWithResult<TResult> performable;
2424
readonly ITarget target;
@@ -46,6 +46,10 @@ public ValueTask<TResult> PerformAsAsync(ICanPerform actor, CancellationToken ca
4646
}
4747
}
4848

49+
/// <inheritdoc/>
50+
public string GetHumanReadableTypeName()
51+
=> $"{performable.GetHumanReadableTypeName()}, via {nameof(SingleElementPerformableWithResultAdapter)}";
52+
4953
/// <summary>
5054
/// Initializes a new instance of the <see cref="SingleElementPerformableWithResultAdapter{TResult}"/> class with the specified performable and target.
5155
/// </summary>

0 commit comments

Comments
 (0)