Skip to content

Test Steps

Test steps are created using the TrganStep class within a TrganTest context. Each step represents a distinct action or checkpoint in the test flow and serves as a structured unit for logging execution status. The TrganStep object exposes intuitive methods—Pass(), Fail(), Skip(), and Log()—to record outcomes and annotate progress. This approach ensures consistent reporting, improves traceability, and enhances readability across test suites.

Creating a Trgan Step

You can create a step using the CreateStep method from TrganTest obj, which initializes the step instance and allows you to update its details later. Alternatively, use AddStep to create and log the step with all required data in a single call.

1
2
3
4
5
6
7
8
GherkinKeyword gherkin = GherkinKeyword.Given;
string description = "User clicks login";

// Create a generic step
var step = trganTest.CreateStep(description);

// Create a BDD-style step
var step = trganTest.CreateStep(gherkin, description); 
After executing the test logic, you can log the result of the step using one of the following methods:
1
2
3
4
step.Pass(description);
step.Fail(description);
step.Skip(description);
step.Log(status, description); 
All four methods accept an optional Screenshot parameter, which embeds the image directly into the HTML report. See the Screenshot section for details.

AddStep() provides a streamlined way to create and log a TrganStep in a single call, eliminating the need for separate instantiation and status assignment. This method is particularly effective for concise test flows and supports both generic and BDD-style steps, allowing you to pass a GherkinKeyword for semantic clarity.

1
2
3
4
5
6
7
8
9
GherkinKeyword gherkin = GherkinKeyword.Given;
string description = "User clicks login";
Status status = Status.PASS;

// Create a generic step
var step = AddStep(status, description);

// Create a BDD step
var step = AddStep(status, gherkin, description);
The timespan of the step when created using AddStep is calculated as follows,

  • if it is the first step under a TrganTest, the duration spans from the test’s creation time to the current step’s end time.
  • otherwise, it spans from the previous step’s end time to the current one.

Info

If a TrganTest contains multiple steps with varying statuses, its overall status will reflect the highest severity among them.