Skip to content

Csharp Examples

Example-1: Container Based Report

1 container with 3 tests

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// creating report obj
TrganHtmlReport report = new ("reports/ContainerBasedReport.html");

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

// creating Test 1
TrganTest test1 = container.CreateTest(name: "Login in with valid credentials");
DoingOperations();
test1.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");
DoingOperations();
test1.AddStep(Status.PASS, GherkinKeyword.When, "Enter valid credentials");
DoingOperations();
test1.AddStep(Status.PASS, GherkinKeyword.Then, "Land on main page");

// creating Test 2
TrganTest test2 = container.CreateTest(name: "Login in with invalid credentials");
DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");
DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.When, "Enter invalid credentials");
DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.Then, "Fail to land on main page");

// creating Test 3
TrganTest test3 = container.CreateTest(name: "Login in with valid username");
DoingOperations();
test3.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");
DoingOperations();
test3.AddStep(Status.PASS, GherkinKeyword.When, "Enter valid username and invalid password");
DoingOperations();
test3.AddStep(Status.PASS, GherkinKeyword.Then, "Fail to land on main page");

// generating report
report.Generate();

Example-2: Test Based Report

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// creating report obj
TrganHtmlReport report = new("reports/TestBasedReport.html");

// creating Test 1
TrganTest test1 = report.CreateTest(testName: "Login in with valid credentials", categories: ["Login"]);
DoingOperations();
test1.AddStep(Status.PASS, "Navigate to app");
DoingOperations();
test1.AddStep(Status.PASS, GherkinKeyword.When, "Enter valid credentials");
DoingOperations();
test1.AddStep(Status.PASS, GherkinKeyword.Then, "Land on main page");

// creating Test 2
TrganTest test2 = report.CreateTest(testName: "Login in with invalid credentials", categories: ["Login"]);
DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");
DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.When, "Enter invalid credentials");
DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.Then, "Failed to land on main page");

// creating Test 3
TrganTest test3 = report.CreateTest(testName: "Login in with valid username", categories: ["Login"]);
DoingOperations();
test3.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");
DoingOperations();
test3.AddStep(Status.PASS, GherkinKeyword.When, "Enter valid username and invalid password");
DoingOperations();
test3.AddStep(Status.PASS, GherkinKeyword.Then, "Failed to land on main page");

// generating report
report.Generate();

Example-3: Normal and Gherkin Test

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
TrganHtmlReport report = new("reports/NormalAndGherkinTests.html");

// creating a normal test
TrganTest test1 = report.CreateTest(testName: "Normal Test", categories: ["TDD"]);

DoingOperations();
test1.AddStep(Status.PASS, "Navigate to app");

DoingOperations();
test1.AddStep(Status.PASS, "Enter valid credentials");

DoingOperations();
test1.AddStep(Status.PASS, "Land on main page");

// creating a bdd styled test
TrganTest test2 = report.CreateTest(testName: "Gherkin Test", categories: ["BDD"]);

DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.Given, "Navigate to app");

DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.When, "Enter invalid credentials");

DoingOperations();
test2.AddStep(Status.PASS, GherkinKeyword.Then, "Failed to land on main page");

report.Generate();

Example-4: Trace Logs in step

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
TrganHtmlReport report = new("reports/Container_Tracelog_DescAndStamp.html");
TrganContainer container = report.CreateContainer("Login Module", categories: ["Regression"]);
TrganTest test = container.CreateTest(name: "Gherkin Test");

TrganStep step1 = test.CreateStep(GherkinKeyword.Given, "Navigate to app");

LaunchApp();
step1.Write("navigated to application");
ViewLoginPage();
step1.Write("able to see login page");
step1.Pass();

TrganStep step2 = test.CreateStep(GherkinKeyword.When, "Enter invalid credentials");

EnterUserName();
step2.Write("entered username");
EnterPassword();
step2.Write("entered password");
ClickLogin();
step2.Write("clicked login");
step2.Pass();

TrganStep step3 = test.CreateStep(GherkinKeyword.Then, "Failed to land on main page");

ViewInvalidWarning();
step3.Write("invalid credentials warning appeared");
CheckCurrentPage();
step3.Write("main page not visible");
step3.Pass();

report.Generate();

Example-5: Report with screenshot