Interface IGetsScreenplay
- Namespace
- CSF.Screenplay
- Assembly
- CSF.Screenplay.dll
An object which can fully configure and get a Screenplay instance.
public interface IGetsScreenplay
Examples
The smallest example of a valid implementation of this class, which just gets a default Screenplay with no customizations is:
public class ScreenplayFactory : IGetsScreenplay
{
public Screenplay GetScreenplay() => Screenplay.Create();
}
Feel free to customize this example to add a parameter to the Create
method, which adds other services to the DI service
collection which will be used with the Screenplay. Such services could be those
Remarks
This interface is particularly important when using Screenplay as a testing tool. Some test integrations do not have any inherent extension points for the placement of 'configuration' or startup logic which affects the entire test run. In those cases, a developer will need to implement this interface with a class of their own, in order to configure and get the Screenplay instance.
Types which implement this interface need only implement the GetScreenplay() method, which should build and return a Screenplay instance. Developers are advised to use Create(Action<IServiceCollection>, Action<ScreenplayOptions>) to create and return the Screenplay.
Note that implementations of this type must have a public parameterless constructor, because they will be instantiated via CreateInstance(Type) and not resolved from dependency injection.
Methods
GetScreenplay()
Gets the configured Screenplay instance provided by the current type.
Screenplay GetScreenplay()
Returns
- Screenplay
A Screenplay instance
Remarks
Implementors should create and return a new Screenplay instance from this method; they are strongly urged
to consider the use of Create(Action<IServiceCollection>, Action<ScreenplayOptions>)
for this purpose.
As well as the creation of the Screenplay instance itself, they should also add to the service collection any
services which relate to abilities which could be used in the Screenplay.
It is recommended to use the parameter to the Create
method (above) to configure such services into the DI
container.