Search code examples
c#extentreportsselenium-extent-report

How to combine reporting from multiple class files into 1 extent reporting test


I am looking for a way to combine the reporting I am generating in multiple classes into 1 test within a report. Note: I am not looking to combine reports, this is a separate issue.

I am running web service automation tests from a Test class which contains my individual test cases. From here the test methods (tasks to be more specific) are reaching out to "callers" which actually call the web service and then return a response to the test case. From there the test case validates the response. I wrote it this way so I can have many tests utilize one caller when needed instead of duplicating code.

However, the problem I now have is my reporting - I'd like to create a test in extent reports from my test method, but I'd also like my caller class to log things such as my full request and response into that same test so I have all of my information in one place.


Solution

  • I was ultimately able to figure out my solution:

    Previously i had all of my extent reporting done directly within the class i was working in. I changed my approach and created another class specifically for my reporting. Within this class I broke up the various extent reporting functions i needed into individual methods. Then, from any class my test is running through, I initialize my reporting class and call the methods i need to create a clean report. for ex:

    1. Test Class:
      • Report.Create report
      • Reaches out to Caller class
    2. Caller class:
      • Report.log something
    3. Test Class
      • Report.end report

    at the end i get one report for the test with everything i want from both classes logged inside the report.