/ docs / screenplay-pattern.c4
screenplay-pattern.c4
  1  // https://serenity-js.org/handbook/design/screenplay-pattern/
  2  model {
  3      context screenplay-pattern {
  4          title: "Screenplay Pattern"
  5          icon: https://avatars.githubusercontent.com/u/25189746?s=200&v=4
  6          link : https://serenity-js.org/handbook/design/screenplay-pattern/
  7          description: "The Screenplay Pattern uses the system metaphor of a stage performance, helping you model each test scenario like a little screenplay describing how the actors should go about performing their activities while interacting with the system under test.
  8  
  9  Following the Screenplay Pattern helps you capture:
 10  
 11  Who the actors interacting with your system are
 12  Why they interact with your system
 13  What they need to do to accomplish their goals
 14  How exactly they would go about that"
 15  
 16          style {
 17              color: yellow-100
 18              opacity: 15%
 19          }
 20  
 21          container actors {
 22              title: "Actors"
 23              icon: tech:playwrite
 24              description: "People and external systems interacting with system under test"
 25              link : https://serenity-js.org/handbook/design/screenplay-pattern/#actors
 26              style {
 27                  color: amber
 28                  shape: person
 29              }
 30          }
 31  
 32          container tasks {
 33              title: "Tasks"
 34              icon: https://www.svgrepo.com/show/498465/task.svg
 35              description: "Used to model sequences of activities as meaningful steps of a business workflow in your domain"
 36              link : https://serenity-js.org/handbook/design/screenplay-pattern/#tasks
 37              style {
 38                  color: blue-800
 39                  shape: queue
 40              }
 41          }
 42  
 43          container abilities {
 44              title: "Abilities"
 45              icon: https://www.svgrepo.com/show/189274/running-run.svg
 46              description: "Thin wrappers around any integration libraries required to interact with the system under test"
 47              link : https://serenity-js.org/handbook/design/screenplay-pattern/#abilities
 48              style {
 49                  color: green
 50                  shape: queue
 51              }
 52          }
 53  
 54          container interactions {
 55              title: "Interactions"
 56              icon: https://www.svgrepo.com/show/216713/click.svg
 57              description: "The low-level activities an actor can perform using a given interface"
 58              link : https://serenity-js.org/handbook/design/screenplay-pattern/#interactions
 59              style {
 60                  color: indigo
 61                  shape: queue
 62              }
 63          }
 64  
 65          container questions {
 66              title: "Questions"
 67              icon: https://www.svgrepo.com/show/407321/red-question-mark.svg
 68              description: "Used to retrieve information from the system under test and the test execution environment"
 69              link : https://serenity-js.org/handbook/design/screenplay-pattern/#questions
 70              style {
 71                  color: cyan-800
 72                  shape: storage
 73              }
 74          }
 75  
 76          container system-under-test {
 77              title: "System under test"
 78              description: "Collection of one or more apps"
 79              icon: https://www.svgrepo.com/show/189269/dumbbell-gym.svg
 80              style {
 81                  color: yellow-700
 82                  shape: mobile
 83              }
 84          }
 85  
 86          actors -> tasks {
 87              title: "perform"
 88              style {
 89                  color: yellow-100
 90              }
 91          }
 92  
 93          actors -> interactions {
 94              title: "perform"
 95              style {
 96                  color: yellow-100
 97              }
 98          }
 99  
100          actors -> abilities {
101              title: "have"
102              description: "Actors have abilities that enable them to interact with the various interfaces of the system under test and the test execution environment.
103  
104  From the technical perspective, abilities act as wrappers around any integration libraries required to communicate with the external interfaces of system under test, such as web browser drivers or an HTTP client, or hold state to allow actors to remember retrieved information. Abilities also enable portability of your test code across various lower-level integration libraries as they expose a standardised API."
105              style {
106                  line: solid
107                  color: orange-800
108                  head: none
109                  tail: diamond
110              }
111          }
112  
113          actors -> questions {
114              title: "answer"
115              description: "Apart from enabling interactions, abilities also enable actors to answer questions about the state of the system under test and the test execution environment. More specifically, questions instruct actors how to use their abilities to retrieve information when the activity is performed and provide a way to parameterise activities."
116              style {
117                  line: dotted
118                  color: pink-800
119              }
120          }
121  
122          tasks -> interactions {
123              title: "made up of"
124              description: "The idea that underpins the Screenplay Pattern is to capture your domain language and use your acceptance tests as an opportunity to demonstrate how actors interacting with your system accomplish their goals.
125  
126  Conceptually similar to standard JavaScript functions, tasks offer an easy way to associate business meaning with sequences of activities and turn them into reusable building blocks from which your team can assemble test scenarios."
127              style {
128                  line: solid
129                  color: blue
130                  head: none
131                  tail: diamond
132              }
133          }
134  
135          abilities -> interactions {
136              title: "enable"
137              description: "Abilities enable actors to perform interactions with the system under test. Interactions are command objects that instruct an actor how to use their abilities to perform the given activity. Most interactions you will need are already provided by Serenity/JS modules, and you can easily create new ones if you'd like to.
138  To instruct an actor to attempt to perform a sequence of interactions, use the Actor.attemptsTo method. Note that this method returns a Promise that resolves when the actor has completed the interactions, or rejects if any of the interactions fail, so you can use it with await in an async function."
139              style {
140                  color: green
141              }
142          }
143  
144          interactions -> system-under-test {
145              title: "with"
146              style {
147                  line: dotted
148                  color: indigo
149              }
150          }
151  
152          abilities -> system-under-test {
153              title: "invoke"
154              style {
155                  line: dotted
156                  color: violet-800
157              }
158          }
159  
160          abilities -> questions {
161              title: "enable"
162              description: "Abilities enable actors to perform interactions with the system under test. Interactions are command objects that instruct an actor how to use their abilities to perform the given activity. Most interactions you will need are already provided by Serenity/JS modules, and you can easily create new ones if you'd like to.
163  To instruct an actor to attempt to perform a sequence of interactions, use the `Actor.attemptsTo` method. Note that this method returns a Promise that resolves when the actor has completed the interactions, or rejects if any of the interactions fail, so you can use it with await in an async function."
164              style {
165                  color: green
166              }
167          }
168  
169          questions -> system-under-test {
170              title: "about the state of"
171              style {
172                  color: cyan-800
173                  line: dotted
174              }
175          }
176      }
177  }