Extent Reports in Selenium CSharp (C#) - Blogs
X

clip_image001 Reports play a fundamental role when it comes to TESTING. Tester can now  know the real-time reports of test suit execution. Reports made ease to know the ratio of Pass? : Fail? post-test suit execution and it is the only documentation to know about test execution results.

Everyone wish to see the detailed description of the test results. Don’t you? here is the solution for it. And, let us see how these reports can be achieved? in Selenium C# - NUnit framework automation testing.

To achieve detailed test execution results as HTML reports we need to rely on third party tool called => Extent Reports. These reports provide decent narration of test execution results and are depicted in PIE chart.

 

 

How to Reference Extent Reports in MS Visual Studio 2015?

Extent Reports can be directly referenced via NuGet Gallery:

1: Reference => Manage NuGet Packages.

clip_image002

2: Install the Extent Reports from NuGet gallery.

clip_image003

3: Extent Reports reference is now added to your project.

clip_image004

How to Initialize Reports?

=> Instance of Extent Reports should be created to initialize the reports.

ExtentReports - Used to generate HTML reports.

ExtentTest – Used to create test log – pass, fail, skip etc…

NamesSpaces: RelevantCodes.ExtentReports;

 

=>clip_image005 Create a folder in the project path/current solution to store the HTML report (execution results).

 

Following is the complete class for extent reports:

 [TestFixture]

 class ExtentReports

 {

       //Instance of extents reports

       public static ExtentReports extent;

       public static ExtentTest test;

             

       [OneTimeSetUp]

       Public void StartReport()

       {

            //To obtain the current solution path/project path

            string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;

            string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));

            string projectPath = new Uri(actualPath).LocalPath;

 

            //Append the html report file to current project path

            string reportPath = projectPath + "Reports\\TestRunReport.html";

 

            //Boolean value for replacing exisisting report

            extent = new ExtentReports(reportPath, true);

 

            //Add QA system info to html report

            extent.AddSystemInfo("Host Name", "YourHostName")

                .AddSystemInfo("Environment", "YourQAEnvironment")

                .AddSystemInfo("Username", "YourUserName");

 

            //Adding config.xml file

extent.LoadConfig(projectPath + "Extent-Config.xml"); //Get the config.xml file from http://extentreports.com

        }

 [TearDown]

        public void AfterClass()

        {

            //StackTrace details for failed Testcases

            var status = TestContext.CurrentContext.Result.Outcome.Status;

            var stackTrace = "

" + TestContext.CurrentContext.Result.StackTrace + "
";

            var errorMessage = TestContext.CurrentContext.Result.Message;

                       

            if(status == TestStatus.Failed)

            {

                test.Log(LogStatus.Fail, status + errorMessage);

            }

            //End test report

            extent.EndTest(test);

            driver.Quit();           

        }

 

 [OneTimeTearDown]

        public void EndReport()

        {

            //End Report

            extent.Flush();

            extent.Close();

         }

 

Now, let’s see how to create a test method.

Note: The first statement in your test method should be extent reports to start reporting your test method.

Here, I have demonstrated simple Assert test method to create extent reports.

[Test]

public void SampleReporting(string browserName)

{

       //Start Report

       test = extent.StartTest("SampleReporting"); //”SampleReporting” TestMethod name

 

       //Log 'info'

       test.Log(LogStatus.Info, "Sample Reporting demo");

 

       //Pass scenario

       Assert.AreEqual(10,10);

       test.Log(LogStatus.Pass, "Test Passed");

                       

       //Fail scenario

       Assert.IsTrue(false);

           

       test.Log(LogStatus.Fail, "Test Failed");

}

Post running test method, the test execution report looks as shown below:

clip_image006

And, the PIE chart representation of test execution result looks as shown below:

clip_image007

Hope, everyone finds this blog useful for depicting “Text Execution Results”.

Please do subscribe to our blogs and keep yourself updated with the new posts.

 

For more information on extent reports, visit site: http://extentreports.com

 

Happy Reporting smiley

Happy Testing yes

 

canarys-logo

Related

What is Defect? Defect Life Cycle in Software Testing.

Defect is an unexpected behavior of the software application flow against the requirement specificat...

Read More >

What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Sending Test reports by Email using Office 365, Gmail

Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execut...

Read More >

Assertions in Coded UI

Let us discuss how to add assertions in coded UI. Assertions are checkpoints/benchmarks to UI c...

Read More >

Analysis of Load Test Results

Analysis of Performance DataAfter you capture and consolidate your results, analyze the captured dat...

Read More >

Parallel Execution using Selenium Webdriver and TestNG

While testing a web application it is very important to test the application on different browsers. ...

Read More >

Handling Radio buttons and Checkboxes using Selenium Webdriver

The main difference between Radio button and Checkbox is that, using radio button we will be able to...

Read More >

Page Object Model

Automation Testing with Selenium using Page Object ModelPage Object Model (POM)Writing selenium scri...

Read More >

Share

Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Tags
Monthly Archive
Subscribe
Name

Text/HTML
Contact Us
  • *
  • *