Skip to content

Trgan Report Csharp Tutorial

This guide walks through all the core features TrganReport provides for generating modular, branded HTML reports in C#.

Create and Generate Report

To get started, install TrganReport via Visual Studio’s NuGet package manager or by adding the following to your .csproj file:

1
2
3
<ItemGroup>
    <PackageReference Include="TrganReport" Version="1.0.0" />
</ItemGroup>
Then import the package:

1
using TrganReport;

Initialize a report by creating a TrganHtmlReport object and specifying the output path and filename:

2
TrganHtmlReport report = new ("reports/TrganReport.html");

Organize with Containers and Tests

You can create TrganContainer or TrganTest objects concurrently. For module-based reports, use containers to group related tests:

3
TrganContainer container = report.CreateContainer(name:"Login Page Module",categories:["login"]);

Both TrganContainer and TrganTest accept an optional string[] categories parameter, which helps visualize tags in the Execution Status Table under the Category column.

Create tests within a container:

4
5
6
TrganTest test1 = container.CreateTest(name:"Login in with valid credentials");
TrganTest test2 = container.CreateTest(name:"Login in with invalid credentials");
TrganTest test3 = container.CreateTest(name:"Login in with valid username");

Update test status using:

test.Pass();
test.Fail();
test.Skip();
test.Log(status);
The status argument must be a value from the Status enum.

Add Steps and BDD Keywords

You can add steps to a test to mark checkpoints or trace actions:

7
8
9
test1.AddStep(Status.PASS,"Navigate to app");
test1.AddStep(Status.PASS, "Enter valid credentials");
test1.AddStep(Status.PASS, "Land on main page");

For BDD-style reports, use Gherkin keywords:

7
8
9
test.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");
test.AddStep(Status.PASS, GherkinKeyword.When, "Enter valid credentials");
test.AddStep(Status.PASS, GherkinKeyword.Then,"Land on main page");
The AddStep method also accepts an optional Screenshot

View Example-3: Normal Test and BDD Test

Create and Update Steps Separately

You can split step creation and status updates:

10
11
12
13
14
15
16
17
18
19
20
TrganStep step = test1.CreateStep("Navigate to app");
// doing operations
step1.Pass();

TrganStep step = test1.CreateStep("Enter valid credentials");
// doing operations
step2.Pass();

TrganStep step = test1.CreateStep("Land on main page");
// doing operations
step3.Pass();

After all steps are completed, generate the report:

19
report.Generate();

View Example-1: container based report

View Example-2: test based report

Adding trace logs to a step

Trace logs act as sub-checkpoints within a step. Use Write() to log messages:

1
2
3
step.Write("entered username");
step.Write("entered password");
step.Write("clicked login");

View Example-4: trace logs in step

Each log includes a timestamp by default. The Write()method accepts:

  • A string message

  • An optional Screenshot

  • A bool timeStamp flag to disable timestamp

Valid Combinations

step.Write("entered username");
step.Write(screenshot);
step.Write("entered username",timeStamp:false);
step.Write(screenshot,timeStamp:false);
step.Write("entered username",screenshot);
step.Write("entered username",screenshot,timeStamp:false);

Upcomings

  • Screenshot attachments
  • TrganTable