Class UseABaseUri
- Namespace
- CSF.Screenplay.Selenium
- Assembly
- CSF.Screenplay.Selenium.dll
Screenplay ability which allows an Actor to use a base Uri, 'completing' relative Uris at runtime.
public class UseABaseUri : ICanReport
- Inheritance
-
UseABaseUri
- Implements
- Inherited Members
Remarks
This ability enables the use of a technique whereby the environment/location of a web application (which is being tested or manipulated by the Selenium Extension for Screenplay) may be set and changed at runtime, instead of hard-coded. This could be particularly useful if you are using this extension for testing and wish to be able to run the same suite of tests against multiple environments. For example:
- Locally, on a developer's computer, with a base Uri such as
https://localhost:8080/ - On a testing environment, with a base Uri such as
https://testing.example.com/ - On a staging environment, with a base Uri such as
https://staging.example.com/
If you wish to use this technique then when writing instances of NamedUri, specify these using relative Uris, such as
new NamedUri("user/shoppingCart", "the user's shopping cart"). Then, grant your actor this ability, using
IsAbleTo(object):
// The following would not realistically be expected to be seen together in one place.
// This is a 'compressed' example for brevity.
// In a realistic Screenplay, the Actor set-up would be in an IPersona implementation,
// the NamedUri would be declared in a library class and the Actor's performance would
// be within an IPerformable implementation.
using CSF.Screenplay.Selenium;
using static CSF.Screenplay.Selenium.PerformableBuilder;
var useABaseUri = new UseABaseUri(new Uri("https://testing.example.com/"));
myActor.IsAbleTo(useABaseUri);
// Details of getting a BrowseTheWeb ability instance are omitted for brevity.
myActor.IsAbleTo(GetBrowseTheWeb());
var shoppingCart = new NamedUri("user/shoppingCart", "the user's shopping cart");
await myActor.PerformAsync(OpenTheUrl(shoppingCart));
// Actually opens the URL https://testing.example.com/user/shoppingCart
The Uri to use as the base Uri does not need to be hard-coded, it could come from configuration or an environment variable etc. When the actor makes use of the BrowseTheWeb ability and opens a Url using the performable returned from OpenTheUrl(NamedUri), the specified named Uri will be rebased to the base Uri specified by this ability.
Constructors
UseABaseUri(Uri)
Initializes a new instance of the UseABaseUri class.
public UseABaseUri(Uri baseUri)
Parameters
baseUriUriThe base URI.
Remarks
When specifying a base URI via this ability, remember to include a trailing slash where applicable. The manner in which relative URIs will be resolved into absolute ones, when this ability is present, is via the two-parameter overload of the Uri constructor, taking a Uri and a string. As stated in the documentation for this constructor:
If the baseUri has relative parts (like /api), then the relative part must be terminated with a slash, (like
/api/), if the relative part of baseUri is to be preserved in the constructed Uri.
The Uri held within this ability will be used as that base URI, as described above.
Properties
BaseUri
Gets the base URI which is associated with the current ability instance.
public Uri BaseUri { get; }
Property Value
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
actorActorAn actor for whom to write the report fragment
formatterIFormatsReportFragmentA 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.