You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Screenplay design pattern is fundamentally compatible with and based upon [dependency injection], aka DI.
8
-
You may add Screenplay to an existing [container] if you wish, via the [`AddScreenplay`] extension method.
9
-
Alternatively you may create an instance of [`Screenplay`] which uses its own self-contained DI container with the static [`Screenplay.Create`] helper method.
8
+
9
+
* You may add Screenplay to an existing [container] via the [`AddScreenplay`] extension method
10
+
* You may create a self-contained instance of [`Screenplay`] via the static [`Screenplay.Create`] helper method
11
+
* Use this is you wish to integrate with an app or library which does not use DI itself
12
+
*[Test integrations] have their own ways to integrate with DI
The example below shows a minimal template for a factory; replace the commment with DI service registrations for anything that you would like to be available to Screenplay.
34
+
There's no need to use `.AddScreenplay()` here, _the integration does that already_.
35
+
For example, to add [the Screenplay/Selenium extension], add `services.AddSelenium()` here.
33
36
34
-
There is one other thing you must do, and that is to write a screenplay factory class, which configures how the `Screenplay` should be created for your tests.
35
-
A screenplay factory is a class which must implement [`IGetsScreenplay`].
36
-
Consider the example below as a starting point for writing your own.
37
+
> [!IMPORTANT]
38
+
> The Screenplay Factory class _must have a parameterless constructor_.
37
39
38
40
```csharp
39
41
usingCSF.Screenplay;
@@ -50,12 +52,27 @@ public class MyScreenplayFactory : IGetsScreenplay
> When using NUnit with Screenplay, every Screenplay-using test within a test assembly (thus, within a .NET project) must share the same instance of `Screenplay`.
55
74
> This is not expected to be problematic, as all the `Screenplay` object does is set-up the Screenplay architecture and dependency injection for the tests.
56
75
57
-
[`Screenplay`]: xref:CSF.Screenplay.Screenplay
58
-
59
76
## Writing test methods
60
77
61
78
When writing test methods, the test methods must be decorated with [`ScreenplayAttribute`], which activates Screenplay for that particular test method.
Copy file name to clipboardExpand all lines: CSF.Screenplay.Docs/docs/gettingStarted/reqnroll/index.md
+35-9Lines changed: 35 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,32 +2,58 @@
2
2
3
3
> [!TIP]
4
4
> Are you using the legacy **SpecFlow**?
5
-
> **Reqnroll** is the maintained fork of SpecFlow, so it's recommended you upgrade your projects ASAP.
6
-
>
7
-
> For now, CSF.Screenplay continues to support SpecFlow.
8
-
> Use the [CSF.Screenplay.SpecFlow] package and SpecFlow v3.4.3 or higher instead.
9
-
> The remainder of the instructions below work for either Reqnroll or SpecFlow.
5
+
> [Reqnroll is the maintained fork of SpecFlow], so it's recommended you upgrade your projects ASAP.
6
+
> See [the documentation on using CSF.Screenplay with SpecFlow] for more information.
10
7
11
8
Begin writing Reqnroll tests using Screenplay by following these steps.
12
9
Further detail is provided below.
13
10
14
11
1. Ensure that your test project uses [Reqnroll version 2.0.0] or higher
15
12
1. Install the NuGet package **[CSF.Screenplay.Reqnroll]** to the project which will contain your `.feature` files
16
-
1._Optional:_ Add services to dependency injection which will be required by the [Abilities]you intend to use. If required, [use Reqnroll context injection & hooks] to add these to the DI container.
13
+
1.Configure dependency injection with any services you intend to use in your tests
17
14
1. Write step binding classes which dependency-inject and use Screenplay's architecture
18
15
16
+
[Reqnroll is the maintained fork of SpecFlow]: https://reqnroll.net/news/2025/01/specflow-end-of-life-has-been-announced/
17
+
[the documentation on using CSF.Screenplay with SpecFlow]: Specflow.md
19
18
[Reqnroll version 2.0.0]: https://www.nuget.org/packages/Reqnroll/2.0.0
// Add your own dependency injection service descriptors to the service collection here
41
+
// For example, services which will be used by Screenplay Abilities.
42
+
;
43
+
}
44
+
}
45
+
```
26
46
27
47
> [!IMPORTANT]
28
48
> When using Reqnroll with Screenplay, every Screenplay-using test within a test assembly (thus, within a .NET project) must share the same instance of `Screenplay`.
29
49
> This is not expected to be problematic, as all the [`Screenplay`] object does is set-up the Screenplay architecture and dependency injection for the tests.
Copy file name to clipboardExpand all lines: CSF.Screenplay.Docs/docs/introduction/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,8 @@ It is particularly useful when many of those steps have a lot in common, making
5
5
This has seen Screenplay become popular for writing the logic of [Behavior-driven development tests](https://en.wikipedia.org/wiki/Behavior-driven_development).
6
6
Despite this, _Screenplay is not limited to just testing logic_.
7
7
8
+
In its early days _Screenplay was better-known as the "Journey" pattern_.
9
+
8
10
## How Screenplay fits into an architecture
9
11
10
12
This diagram provides a very high-level look at where Screenplay lies within the architecture of your software.
Copy file name to clipboardExpand all lines: CSF.Screenplay.NUnit/ScreenplayAssemblyAttribute.cs
+18-6Lines changed: 18 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -11,21 +11,33 @@ namespace CSF.Screenplay
11
11
/// <para>
12
12
/// This attribute is the core of the NUnit3 <xref href="IntegrationGlossaryItem?text=test+framework+integration"/> with Screenplay.
13
13
/// In order to run tests with Screenplay, the assembly must be decorated with this attribute.
14
+
/// Its purpose is to signpost the Screenplay Factory (see below) to the NUnit/Screenplay integration.
14
15
/// </para>
15
16
/// <para>
16
-
/// This attribute has one mandatory parameter; that is the <see cref="Type"/> of a concrete implementation of
17
-
/// <see cref="IGetsScreenplay"/>. That type will be instantiated by the NUnit3 integration and will be used to
17
+
/// This attribute has one mandatory parameter; that is the <see cref="Type"/> of the Screenplay Factory which should be used in this test project.
18
+
/// A Screenplay Factory is a class which provides a concrete implementation of <see cref="IGetsScreenplay"/>.
19
+
/// An instance of the factory will be instantiated by the NUnit3 integration and will be used to
18
20
/// build and retrieve the <see cref="Screenplay"/> instance for running the Screenplay-based tests within the decorated
19
-
/// assembly. Each test method must additionally be decorated with the <see cref="ScreenplayAttribute"/> in order to make
20
-
/// it a Screenplay-based test.
21
+
/// assembly.
22
+
/// </para>
23
+
/// <para>
24
+
/// Each test method in the project must additionally be decorated with the
25
+
/// <see cref="ScreenplayAttribute"/> in order to activate the Screenplay architecture for that test.
26
+
/// It is possible to mix & match Screenplay-based and non-Screenplay-based tests within a single test project.
27
+
/// </para>
28
+
/// <para>
29
+
/// All Screenplay-based tests within a test project/assembly will use the Screenplay Factory which is identified by this attribute.
21
30
/// </para>
22
31
/// </remarks>
23
32
/// <example>
24
33
/// <para>
25
-
/// Decorate your assembly with this attribute using the syntax <c>[assembly: CSF.Screenplay.ScreenplayAssembly]</c>. You may place this
34
+
/// Decorate your assembly with this attribute using the syntax <c>[assembly: CSF.Screenplay.ScreenplayAssembly(typeof(MyScreenplayFactory))]</c>. You may place this
26
35
/// into any source file, outside of any type declaration. By convention it would be put into a dedicated source file
27
36
/// within the <c>Properties</c> project directory.
28
37
/// </para>
38
+
/// <para>
39
+
/// There is a further example available in the <xref href="NUnit3GettingStartedArticle?text=getting+started+guide+for+Screenplay+and+NUnit3"/>.
@@ -68,7 +80,7 @@ public Screenplay GetScreenplay()
68
80
/// The <paramref name="factoryType"/> specified in this constructor must meet all of the following criteria:
69
81
/// </para>
70
82
/// <list type="bullet">
71
-
/// <item><description>It must be a non-<see langword="null" /> <see cref="Type"/> which derives from <see cref="IGetsScreenplay"/></description></item>
83
+
/// <item><description>It must be a non-<see langword="null" />, non-<see langword="abstract"/> <see cref="Type"/> which derives from <see cref="IGetsScreenplay"/></description></item>
72
84
/// <item><description>It must have a public parameterless constructor</description></item>
73
85
/// <item><description>It must return a non-<see langword="null" /> instance of <see cref="Screenplay"/> from its <see cref="IGetsScreenplay.GetScreenplay"/> method</description></item>
0 commit comments