Table of Contents

Class EnterTheDate

Namespace
CSF.Screenplay.Selenium.Tasks
Assembly
CSF.Screenplay.Selenium.dll

A Screenplay task for entering a value into an <input type="date"> element.

public class EnterTheDate : IPerformable, ICanReport
Inheritance
EnterTheDate
Implements
Inherited Members

Examples

A British English browser en-GB expects dates to be entered in the format ddMMyyyy. However, a US English browser en-US expects dates to be entered in the format MMddyyyy.

The code sample below shows how to enter the date 5th April 2025 into a date input element with the id due_date, using the British English format.

using CSF.Screenplay.Selenium.Elements;
using static CSF.Screenplay.Selenium.PerformableBuilder;

readonly ITarget dueDate = new ElementId("due_date", "the due date");

// Within the logic of a custom task, deriving from IPerformable
public async ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)
{
    // ... other performance logic
    await actor.PerformAsync(EnterTheDate(new DateTime(2025, 4, 5)).Into(dueDate).ForTheCultureNamed("en-GB"), cancellationToken);
    // ... other performance logic
}

Remarks

Use this task with the builder method EnterTheDate(DateTime?). This builder will guide you through picking the element into which the date should be entered.

The rationale for this task is that web browsers or WebDriver implementations are inconsistent in the manner in which they support interacting with Date input elements. Browsers which require a JavaScript workaround are marked with the browser quirk CannotSetInputTypeDateWithSendKeys. See the documentation for that quirk for more information. This task provides date-setting capabilities in a cross-browser manner.

For browsers which are affected by the quirk, the date is set via a separate task: SetTheElementValue, with the 'simulate setting the value interactively' behaviour enabled. For browsers which are not affected by the quirk, the date is first cleared via the action ClearTheContents, and then keypresses are sent to the web browser to enter the date in a locale-specific format via SendKeys.

Note that because entering a date interactively (by sending keys) requires a locale-specific format, that makes this task culture-sensitive. It is important to ensure that the date value entered into the browser is entered using the same culture as which the browser is currently operating. If the culture does not match then this could lead to mistakes in the value; consider muddling up US English and UK English dates. In US English 04/05/2010 means the 5th April 2010. In UK English that same date string means 4th May 2010, because the days and months are transposed in that format. If no culture information is specified in the constructor then this task defaults to the current culture: CurrentCulture. That is often sufficient, particularly if the WebDriver is running locally on the same computer as is executing the Screenplay Performance. It could be problematic, though, if a Remote WebDriver is in use. A Remote WebDriver could be hosted in another nation and thus be operating under a different culture to the Screenplay Performance. In this case, be sure to specify the correct culture in the constructor of this task.

If the date specified to this task is null then this task will clear the date from the target.

Constructors

EnterTheDate(DateTime?, ITarget, CultureInfo)

Initializes a new instance of the EnterTheDate class with the specified date.

public EnterTheDate(DateTime? date, ITarget target, CultureInfo culture = null)

Parameters

date DateTime?

The date to enter into the element.

target ITarget

The element into which to enter the data

culture CultureInfo

The culture for which to enter the date

Methods

GetReportFragment(Actor, IFormatsReportFragment)

Gets a fragment of a Screenplay report, specific to the execution (performables) or gaining (abilities) of the current instance, for the specified actor.

public ReportFragment GetReportFragment(Actor actor, IFormatsReportFragment formatter)

Parameters

actor Actor

An actor for whom to write the report fragment

formatter IFormatsReportFragment

A report-formatting service

Returns

ReportFragment

A human-readable report fragment.

Examples

For a performable which clicks a button (where the button itself has been constructor-injected into the performable instance), then a suitable return value might be a formatted string such as {Actor name} clicks {Button}, where the two placeholders indicated by braces: {} are substituted with the actor's Name and a string representation of the button.

For a performable which reads the temperature from a thermometer, a suitable return value might be a string in the format {Actor name} reads the temperature.

For an ability which allows the actor to wash dishes then a suitable return value might be a string in the format {Actor name} is able to wash the dishes.

Remarks

Implementers should return a string which indicates that the named actor is performing (present tense) the performable, for types which also implement a performable interface. For types which represent abilities, the implementer should return a string which indicates that the named actor is able to do something. In particular for abilities, to make them easily recognisable in reports, it helps to stick to the convention {Actor name} is able to {Ability summary}.

For performables which return a value (Questions, or Tasks which behave like Questions), there is no need to include the returned value within the report fragment. The framework will include the return value in the report and will format it via a different mechanism.

Good report fragments are concise. Be aware that report fragments for Tasks (which are composed from other performables) do not need to go into detail about what they do. Users reading Screenplay reports are able to drill-down into Tasks to see what they are composed from, so if the user is curious as to what the task does, it is easy to discover. It is also strongly recommended to avoid periods (full stops) at the end of a report fragment. Whilst report fragments tend to be complete sentences, punctuation like this is distracting and reports are seldom presented as paragraphs of prose.

PerformAsAsync(ICanPerform, CancellationToken)

Performs the action(s) are represented by the current instance.

public ValueTask PerformAsAsync(ICanPerform actor, CancellationToken cancellationToken = default)

Parameters

actor ICanPerform

The actor that is performing.

cancellationToken CancellationToken

An optional cancellation token by which to abort the performable.

Returns

ValueTask

A task which completes when the performable represented by the current instance is complete.

See Also