Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

using System;
using CSF.Screenplay.Selenium.Elements;
using static CSF.Screenplay.Selenium.Tasks.ReadTheListItemsBuilder;
using static CSF.Screenplay.PerformanceStarter;
using static CSF.Screenplay.Selenium.PerformableBuilder;

Expand All @@ -22,8 +22,8 @@ public async Task SelectTheOptionFromShouldAddOneSelectedItem(IStage stage)

await Given(webster).WasAbleTo(OpenTheUrl(testPage));
await When(webster).AttemptsTo(SelectTheOption(0).From(selectElement));
var contents = await Then(webster).Should(ReadFromTheElement(displayText).TheText());
var contents = await Then(webster).Should(ReadTheListItemsIn(displayText));

Assert.That(contents, Is.EqualTo($"First{Environment.NewLine}Third"));
Assert.That(contents, Is.EqualTo(new [] { "First", "Third" }));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

using System;
using CSF.Screenplay.Selenium.Elements;
using static CSF.Screenplay.PerformanceStarter;
using static CSF.Screenplay.Selenium.PerformableBuilder;
using static CSF.Screenplay.Selenium.Tasks.ReadTheListItemsBuilder;

namespace CSF.Screenplay.Selenium.Actions;

Expand All @@ -22,8 +21,8 @@ public async Task SelectTheOptionFromShouldAddOneSelectedItem(IStage stage)

await Given(webster).WasAbleTo(OpenTheUrl(testPage));
await When(webster).AttemptsTo(SelectTheOption("Second").From(selectElement));
var contents = await Then(webster).Should(ReadFromTheElement(displayText).TheText());
var contents = await Then(webster).Should(ReadTheListItemsIn(displayText));

Assert.That(contents, Is.EqualTo($"Second{Environment.NewLine}Third"));
Assert.That(contents, Is.EqualTo(new [] { "Second", "Third" }));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

using System;
using CSF.Screenplay.Selenium.Elements;
using static CSF.Screenplay.PerformanceStarter;
using static CSF.Screenplay.Selenium.PerformableBuilder;
using static CSF.Screenplay.Selenium.Tasks.ReadTheListItemsBuilder;

namespace CSF.Screenplay.Selenium.Actions;

Expand All @@ -22,8 +22,8 @@ public async Task SelectTheOptionFromShouldAddOneSelectedItem(IStage stage)

await Given(webster).WasAbleTo(OpenTheUrl(testPage));
await When(webster).AttemptsTo(SelectTheOptionWithValue("Two").From(selectElement));
var contents = await Then(webster).Should(ReadFromTheElement(displayText).TheText());
var contents = await Then(webster).Should(ReadTheListItemsIn(displayText));

Assert.That(contents, Is.EqualTo($"Second{Environment.NewLine}Third"));
Assert.That(contents, Is.EqualTo(new [] { "Second", "Third" }));
}
}
32 changes: 32 additions & 0 deletions Tests/CSF.Screenplay.Selenium.Tests/Tasks/ReadTheListItems.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Collections.Generic;
using CSF.Screenplay.Selenium.Elements;
using static CSF.Screenplay.Selenium.PerformableBuilder;

namespace CSF.Screenplay.Selenium.Tasks;

public class ReadTheListItems : IPerformableWithResult<IReadOnlyList<string>>, ICanReport
{
static readonly Locator listItems = new CssSelector("li", "the list items");

readonly ITarget target;

public ReportFragment GetReportFragment(Actor actor, IFormatsReportFragment formatter)
=> formatter.Format("{Actor} reads the text from list items within {Target}", actor, target);

public async ValueTask<IReadOnlyList<string>> PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)
{
var items = await actor.PerformAsync(FindElementsWithin(target).WhichMatch(listItems), cancellationToken);
return await actor.PerformAsync(ReadFromTheCollectionOfElements(items).Text(), cancellationToken);
}

public ReadTheListItems(ITarget target)
{
this.target = target ?? throw new System.ArgumentNullException(nameof(target));
}
}

public static class ReadTheListItemsBuilder
{
public static IPerformableWithResult<IReadOnlyList<string>> ReadTheListItemsIn(ITarget target)
=> new ReadTheListItems(target);
}
Loading