Actor class extensibility - Galad/tranquire GitHub Wiki

WithReporting

You can add reporting to all actions by using the WithReporting extension method on the actor. You need to provide an implementation of IObserver<ActionNotification> that is called on each notification. You can also provide a IObserver<string> that uses a default renderering of a ReportingInfo object to a string notification message.

Using a IObserver<string>

The following example reports all the notifications to a ConsoleObserver, which writes its standard output (see System.Console) :

var actor = new Actor("John").WithReporting(new ConsoleObserver());

Tranquire provides the following observers of string:

  • ConsoleObserver (only for .NET framework projects)
  • TraceObserver (only for .NET framework projects)
  • DebugObserver You can create your own just by implementing IObserver<string>.

Using a IObserver<ActionNotification>

You can pipe the result of a ReportingInfo to one of the IObserver<string> implementation. You might want to do that if you want to provide a custom notification message format.

var actor = new Actor("John").WithReporting(
                              new RenderedReportingObserver(
                                   observer,
                                   notification => GetNotificationMessage(notification)
                                   )
                              );

By default, tranquire uses the RenderedReportingObserver.DefaultRenderer function to create the messages.

Using XmlDocumentObserver

In addition to the text format, you can create a report in an XML format. This report contains the different actions and questions that were executed.

To enable the xml report, you can just pass an instance of XmlDocumentObserver to the WithReporting method, and use this instance to generate the XML report at the end of the test. Finally, call the GetXmlDocument method to generate a XDocument object containing the report in XML format.

var xmlDocumentReporting = new XmlDocumentObserver();
var actor = new Actor("John").WithReporting(xmlDocumentReporting);
// run the test
xmlDocumentReporting.GetXmlDocument().Save("actorReport.xml");

XML format

Here is an example of an XML document:

<root start-date="06/02/2018 21:48:42 +00:00" end-date="06/02/2018 21:48:53 +00:00" duration="11208" name="Test" has-error="false">
  <given start-date="06/02/2018 21:48:42 +00:00" end-date="06/02/2018 21:48:44 +00:00" duration="1472" name="Given Navigate to http://localhost:57897/ToDo/index.html" has-error="false">
    <action start-date="06/02/2018 21:48:42 +00:00" end-date="06/02/2018 21:48:44 +00:00" duration="1468" name="Navigate to http://localhost:57897/ToDo/index.html" has-error="false">
      <attachments>
        <attachment filepath="Add an item_01.jpg" description="" />
      </attachments>
    </action>
  </given>
  <when start-date="06/02/2018 21:48:44 +00:00" end-date="06/02/2018 21:48:48 +00:00" duration="4603" name="When Add item 'buy some milk'" has-error="false">
    <action start-date="06/02/2018 21:48:44 +00:00" end-date="06/02/2018 21:48:48 +00:00" duration="4602" name="Add item 'buy some milk'" has-error="false">
      <action start-date="06/02/2018 21:48:44 +00:00" end-date="06/02/2018 21:48:46 +00:00" duration="2302" name="Enter the value 'buy some milk' into 'New todo item input'" has-error="false">
        <attachments>
          <attachment filepath="Add an item_02.jpg" description="" />
        </attachments>
      </action>
      <action start-date="06/02/2018 21:48:46 +00:00" end-date="06/02/2018 21:48:48 +00:00" duration="2295" name="Enter the value '' into 'New todo item input'" has-error="false">
        <attachments>
          <attachment filepath="Add an item_03.jpg" description="" />
        </attachments>
      </action>
    </action>
  </when>
  <then start-date="06/02/2018 21:48:48 +00:00" end-date="06/02/2018 21:48:53 +00:00" duration="4830" name="Then verifies the answer of Displayed items" has-error="false" outcome="pass">
    <question start-date="06/02/2018 21:48:48 +00:00" end-date="06/02/2018 21:48:53 +00:00" duration="4811" name="Displayed items" has-error="false">
      <question start-date="06/02/2018 21:48:48 +00:00" end-date="06/02/2018 21:48:53 +00:00" duration="4585" name="What are the state of the elements identified by To do item (By.CssSelector: ul.todo-list li) ?" has-error="false">
        <question start-date="06/02/2018 21:48:49 +00:00" end-date="06/02/2018 21:48:52 +00:00" duration="2286" name="What is the state of the element identified by To do item name (By.CssSelector: div label) ?" has-error="false">
          <attachments>
            <attachment filepath="Add an item_04.jpg" description="" />
          </attachments>
        </question>
        <attachments>
          <attachment filepath="Add an item_05.jpg" description="" />
        </attachments>
      </question>
      <attachments>
        <attachment filepath="Add an item_06.jpg" description="" />
      </attachments>
    </question>
  </then>
</root>

HTML report (.NET Framework)

You can also generate an HTML report from the XmlDocumentObserver instance:

var xmlDocumentReporting = new XmlDocumentObserver();
var actor = new Actor("John").WithReporting(xmlDocumentReporting);
// run the test
var htmlReport = xmlDocumentReporting.GetHtmlDocument();
File.WriteAllText("actorReport.html", htmlReport);
⚠️ **GitHub.com Fallback** ⚠️