Class NamedUri
- Namespace
- CSF.Screenplay.Selenium
- Assembly
- CSF.Screenplay.Selenium.dll
Model containing a Uri with a corresponding human-readable name.
public sealed class NamedUri : IHasName
- Inheritance
-
NamedUri
- Implements
- Inherited Members
- Extension Methods
Remarks
This model allows for the association of human-readable names with URIs. This is most useful when making use of Screenplay reports, where the human-readable name can be used to describe the URI in a more user-friendly way. Named Uris are used with the OpenUrl and OpenUrlRespectingBase performables to facilitate direct web browser navigation.
Note the inclusion of implicit conversion operators which allow for seamless conversion from Uri and/or string instances to instances of this type. It is not recommended to use them, though, as neither supplies a name. This would mean that the naked Uri would appear in reports, instead of a human-readable name.
If you have a need to switch environments at runtime, consider specifying named Uris using relative Uri fragments. This may be combined with the UseABaseUri ability to rebase the relative Uri onto a base Uri at runtime. This could be useful in testing, for example, whereby the same test suite must be run against a number of environments:
- 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/
Constructors
NamedUri(string, string)
Initializes a new instance of the NamedUri class.
public NamedUri(string uri, string name = null)
Parameters
uristringThe URI to associate with this instance.
namestringThe human-readable name for the URI. If null, the URI string will be used as the name.
NamedUri(Uri, string)
Initializes a new instance of the NamedUri class.
public NamedUri(Uri uri, string name = null)
Parameters
uriUriThe URI to associate with this instance.
namestringThe human-readable name for the URI. If null, the URI string will be used as the name.
Properties
Name
Gets the human-readable name for this Uri.
public string Name { get; }
Property Value
Uri
Gets the Uri associated with this instance.
public Uri Uri { get; }
Property Value
Methods
RebaseTo(Uri)
Gets a copy of the current named URI, except 'rebased' using the specified base URI.
public NamedUri RebaseTo(Uri baseUri)
Parameters
baseUriUriA new base URI
Returns
- NamedUri
A URI which might have been rebased onto the new base URI
Remarks
If the current Uri is Absolute then this method has not effect and the named URI which is returned is the unmodified current instance.
If the current Uri is not absolute, then the specified base URI is prepended to the current URI, serving as a base. The new URI is then returned from this method. Note that this method will never result in the current instance being mutated, at most it will only return a copy of the current instance, which has the newly-rebased URI.
Operators
implicit operator NamedUri(string)
public static implicit operator NamedUri(string uri)
Parameters
uristringThe URI to convert.
Returns
implicit operator NamedUri(Uri)
public static implicit operator NamedUri(Uri uri)
Parameters
uriUriThe URI to convert.