When an assertion fails, its message may not have room for all the useful context—or the context may not be text at all. The supplementary attachment pattern adds that context to the test result so a failure is easier to diagnose. section 19.7
For a scenario that fails:
- Save useful context, such as an application log or screenshot. section 19.2
- Register the saved file with the scenario automation tool or underlying test framework; saving it to the output directory alone usually does not attach it to the result. section 19.2
Application log
A failing UI scenario can attach the application log to help investigate unexpected popups or timing issues. A report can then show both the assertion message and the log attachment. section 19.2
Listing 19.4 Save and register supplementary attachment
*** Support/Hooks.cs ***
[Binding]
public class Hooks(
IScenarioContext scenarioContext, #A
IReqnrollOutputHelper outputHelper, #B
AppLogContext appLogContext) #C
{
[AfterScenario(Order = 0)] #D
public void SaveAppLogOnError()
{
if (scenarioContext.ScenarioExecutionStatus ==
ScenarioExecutionStatus.TestError) #E
{
string outputPath = Path.GetFullPath(
$"app-log-{Guid.NewGuid():N}.txt"); #F
appLogContext.SaveToFile(outputPath); #G
outputHelper.AddAttachment(outputPath); #H
}
}
}See a Reqnroll hook that checks for a scenario error, saves the application log to a uniquely named file, and registers it as an attachment. section 19.2
