Skip to content
Craig Fowler edited this page Mar 20, 2019 · 5 revisions

Screenplay is all about Actors executing performable steps: tasks, actions & questions. During a test, Screenplay automatically records the steps performed by each actor, along with their outcomes. These records may be saved to file as reports.

Test developers should use the Screenplay integration configuration to set up writing report files. Here is a minimal example of the configuration to write a report file.

// "builder" is an instance of IIntegrationConfigBuilder
builder.UseReporting(r => r.WithReportJsonFile("Screenplay report.json"))

Converting & reading reports

Because of restrictions imposed by test frameworks and runners, reports are written to JSON files. A conversion utility, part of Screenplay, may be used to convert the JSON reports into human-readable formats, such as:

  • Plain text files
  • Rich HTML files (with folding/filtering)

Here is an example of a fictitious report, presented in the converted plain text format.

Feature: Adding random numbers together
Scenario: When Jane adds two dice rolls together, the result should be less than 13
*** Success ***
Given Jane can roll dice
Given Jane can add numbers together
 When Jane rolls two dice
          Jane rolls a die
          Result:4
          Jane rolls a die
          Result:1
 When Jane adds the numbers 4 and 1
 Then Jane reads the result
      Result:5

Getting the most from reports

There are two recommended practices which can improve the usefulness of Screenplay reports.

Override GetReport in your tasks

Tasks should override the GetReport method to provide human-readable strings which will appear in the generated report. If you do not then Screenplay will record your task using the following standard/generated format in reports.

{Actor name} performs {Task type name}`

Use object formatters for complex result types

Screenplay records the results/return values of any questions/tasks in the generated reports. By default these result values are serialised to the report using Object.ToString(). That might not be very useful for complex object types though.

Screenplay offers an extension-point - Object Formatters - which specify how a given result object type should be formatted within a report. This allows for a more useful human-readable representation in the reports. Object formatters are registered with the reporter in the integration configuration.