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
Merge pull request #45 from MASTERS-Y2Q1-ISEP: Model visualisations
New feature for adding a graphical representation of the model to the Robot log file.
Co-authored-by: osingaatje <douwe@dosinga.nl>
Co-authored-by: JWillegers <148167.jw@gmail.com>
Co-authored-by: tychodub <t.b.dubbeling@student.utwente.nl>
Co-authored-by: Diogossilva03 <diogo.xuya@gmail.com>
Co-authored-by: JFoederer <github@famfoe.nl>
Copy file name to clipboardExpand all lines: README.md
+55-12Lines changed: 55 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ The recommended installation method is using [pip](http://pip-installer.org)
36
36
37
37
After installation include `robotmbt` as library in your robot file to get access to the new functionality. To run your test suite model-based, use the __Treat this test suite model-based__ keyword as suite setup. Check the _How to model_ section to learn how to make your scenarios suitable for running model-based.
38
38
39
-
```
39
+
```robotframework
40
40
*** Settings ***
41
41
Library robotmbt
42
42
Suite Setup Treat this test suite model-based
@@ -50,7 +50,8 @@ Modelling can be done directly from [Robot framework](https://robotframework.org
50
50
51
51
Consider these two scenarios:
52
52
53
-
```
53
+
```robotframework
54
+
*** Test Cases ***
54
55
Buying a postcard
55
56
When you buy a new postcard
56
57
then you have a blank postcard
@@ -63,7 +64,8 @@ Preparing for a birthday party
63
64
64
65
Mapping the dependencies between scenarios is done by annotating the steps with modelling info. Modelling info is added to the documentation of the step as shown below. Regular documentation can still be added, as long as `*model info*` starts on a new line and a white line is included after the last `:OUT:` expression.
65
66
66
-
```
67
+
```robotframework
68
+
*** Keywords ***
67
69
you buy a new postcard
68
70
[Documentation] *model info*
69
71
... :IN: None
@@ -117,7 +119,8 @@ All example scenarios naturally contain data. This information is embedded in th
117
119
118
120
#### Step argument modifiers
119
121
120
-
```
122
+
```robotframework
123
+
*** Test Cases ***
121
124
Personalising a birthday card
122
125
Given there is a birthday card
123
126
when Johan writes their name on the birthday card
@@ -126,7 +129,8 @@ Personalising a birthday card
126
129
127
130
The above scenario uses the name `Johan` to create a concrete example. But now suppose that from a testing perspective `Johan` and `Frederique` are part of the same equivalence class. Then the step `Frederique writes their name on the birthday card` would yield an equally valid scenario. This can be achieved by adding a modifier (`:MOD:`) to the model info of the step. The format of a modifier is a Robot argument to which you assign a list of options. The modifier updates the argument value to a randomly chosen value from the specified options.
128
131
129
-
```
132
+
```robotframework
133
+
*** Keywords ***
130
134
${person} writes their name on the birthday card
131
135
[Documentation] *model info*
132
136
... :MOD: ${person}= [Johan, Frederique]
@@ -138,7 +142,8 @@ ${person} writes their name on the birthday card
138
142
139
143
When constructing examples, they often express relations between multiple actors, where each actor can appear in multiple steps. This makes it important to know how modifiers behave when there are multiple modifiers in a scenario.
140
144
141
-
```
145
+
```robotframework
146
+
*** Test Cases ***
142
147
Addressing a birthday card
143
148
Given Tannaz is having their birthday
144
149
and Johan has a birthday card
@@ -148,7 +153,8 @@ Addressing a birthday card
148
153
149
154
Have a look at the when-step above. We will assume the model already contains a domain term with two properties: `birthday.celebrant = Tannaz` and `birthday.guests = [Johan, Frederique]`.
150
155
151
-
```
156
+
```robotframework
157
+
*** Keywords ***
152
158
${sender} writes the address of ${receiver} on the birthday card
153
159
[Documentation] *model info*
154
160
... :MOD: ${sender}= birthday.guests
@@ -175,10 +181,12 @@ It is not possible to add new options to an existing example value. Any constrai
175
181
176
182
It is possible for a step to keep the same options. The special `.*` notation lets you keep the available options as-is. Preceding steps must then supply the possible options. Some steps can, or must, deal with multiple independent sets of options that must not be mixed, because the expected results should differ. Suppose you have a set of valid and invalid passwords. You might be reluctant to include the superset of these as options to an authentication step. Instead, you can use `:MOD: ${password}= .*` as the modifier for that step. Like in the when-step for this scenario:
177
183
178
-
```
179
-
Given 'secret' is too weak a password
180
-
When user tries to update their password to 'secret'
181
-
then the password is rejected
184
+
```robotframework
185
+
*** Test Cases ***
186
+
Reject password
187
+
Given 'secret' is too weak a password
188
+
When user tries to update their password to 'secret'
189
+
then the password is rejected
182
190
```
183
191
184
192
In a then-step, modifiers behave slightly different. In then-steps no new option constraints are accepted for an argument. Its value must already have been determined during the given- and when-steps. In other words, regardless of the actual modifier, the expression behaves as if it were `.*`. The exception to this is when a then-step signals the first use of a new example value. In that case the argument value from the original scenario text is used.
@@ -193,12 +201,47 @@ For now, variable data considers strict equivalence classes only. This means tha
193
201
194
202
By default, trace generation is random. The random seed used for the trace is logged by _Treat this test suite model-based_. This seed can be used to rerun the same trace, if no external random factors influence the test run. To activate the seed, pass it as argument:
195
203
196
-
```
204
+
```robotframework
197
205
Treat this test suite model-based seed=eag-etou-cxi-leamv-jsi
198
206
```
199
207
200
208
Using `seed=new` will force generation of a new reusable seed and is identical to omitting the seed argument. To completely bypass seed generation and use the system's random source, use `seed=None`. This has even more variation but does not produce a reusable seed.
201
209
210
+
### Graphs
211
+
212
+
A graph can be included in the log file to visualise how scenarios are linked. This helps in understanding a test suite's structure and reveals alternative paths that did not make it into the final trace.
213
+
214
+
To enable graph generation, some extra dependencies must be installed: `pip install robotframework-mbt[visualisation]`
215
+
216
+
Generate the graph by setting the graph style for the model-based suite. The graph will be included in the Robot log file as part of the keyword's logging.
217
+
218
+
```robotframework
219
+
Treat this test suite Model-based graph=scenario
220
+
```
221
+
222
+
Available graph styles:
223
+
224
+
* scenario
225
+
* Compact view: Each scenario is shown as one node.
226
+
* scenario-delta-value
227
+
* Expanded view: Scenarios can become multiple nodes if they affect system state in different ways.
228
+
229
+
#### Exporting and importing graph data
230
+
231
+
Graph data can be stored by setting an output directory using argument `export_graph_data`. This createss a json file, named after the test suite, in the selected folder. Any accessable path can be used. For your convenience, Robot Framework offers an [automatic variable](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#automatic-variables)`${OUTPUT_DIR}` that points to this run's output directory. The `export_graph_data` argument can be used independent of the `graph` argument.
232
+
233
+
```robotframework
234
+
Treat this test suite Model-based export_graph_data=${OUTPUT_DIR}
235
+
```
236
+
237
+
To recreate a graph from previously exported graph data, use:
238
+
239
+
```robotframework
240
+
Show model graph from exported file json_file_path=<file_path> graph_style=scenario
241
+
```
242
+
243
+
This will draw a graph from the exported file, without the need to rerun the test suite. It is possible to select a different graph style than was used during the test run. If no graph style is selected, then the scenario graph style is used.
244
+
202
245
### Option management
203
246
204
247
If you want to set configuration options for use in multiple test suites without having to repeat them, the keywords __Set model-based options__ and __Update model-based options__ can be used to configure RobotMBT library options. _Set_ takes the provided options and discards any previously set options. _Update_ allows you to modify existing options or add new ones. Reset all options by calling _Set_ without arguments. Direct options provided to __Treat this test suite model-based__ take precedence over library options and affect only the current test suite.
0 commit comments