Forum Discussion

ashsharma22's avatar
ashsharma22
Occasional Contributor
4 years ago
Solved

ExtenrtReport for ReadyAPI v3.x

Please help me to integrate extentreport with ReadyAPI v3.x. 

  • sonya_m's avatar
    sonya_m
    4 years ago

    Thank you Himanshu🙂

     

    ashsharma22 Did you manage to complete this task?

3 Replies

    • sonya_m's avatar
      sonya_m
      SmartBear Alumni (Retired)

      Thank you Himanshu🙂

       

      ashsharma22 Did you manage to complete this task?

    • ashsharma22's avatar
      ashsharma22
      Occasional Contributor

      Thanks Himanshu for the help!

       

      I did few more modification in the script and made it dynamic. 

       

      Step1: Only below imports needed

      Step2: Add TestReport property at project level: ${projectDir}/TestReport; This location all extents reports will be stored

      Step3: keep this code at suite level

      Run it; 

       

       

       

      import java.io.File;
      import java.util.Date;
      import com.aventstack.extentreports.ExtentReports;
      import com.aventstack.extentreports.ExtentTest;
      import com.aventstack.extentreports.Status;
      import com.aventstack.extentreports.reporter.ExtentHtmlReporter;
      import com.aventstack.extentreports.reporter.configuration.Protocol;
      import com.aventstack.extentreports.reporter.configuration.Theme;

      log.info "start"

      ExtentReports extent;
      ExtentTest extentTest;


      def testReport = context.expand( '${#Project#TestReport}' )
      assert !testReport.equals(''), 'TestReport location not found'
      log.info "testReport: "+testReport

      if (extent == null) {
      //ExtentReport file name
      Date d=new Date();
      String fileName=d.toString().replace(":", "_").replace(" ", "_")+".html";
      //String folderName="C:\\reports\\";

      File folderPath=new File(testReport);
      if(!folderPath.exists()) {
      log.info "Directory created"
      folderPath.mkdir();
      } else
      log.info "Directory already exists"

      String htmlFilePath=testReport+'/'+fileName;
      log.info 'HTML File Path' + htmlFilePath


      ExtentHtmlReporter htmlReporter=new ExtentHtmlReporter(htmlFilePath);
      extent=new ExtentReports();
      extent.attachReporter(htmlReporter);

      htmlReporter.config().setCSS("css-string");
      htmlReporter.config().setDocumentTitle("Automation Execution Report");
      htmlReporter.config().setReportName("Test Automation Report");
      htmlReporter.config().setEncoding("utf-8");
      htmlReporter.config().setJS("js-string");
      htmlReporter.config().setProtocol(Protocol.HTTPS);
      htmlReporter.config().setReportName("build name");
      htmlReporter.config().setTheme(Theme.STANDARD);
      htmlReporter.config().setTimeStampFormat("MMM dd, yyyy HH:mm:ss");
      }
      for ( testCaseResult in runner.results ) {
      // Getting all test cases’ names from the suite.
      testCaseName = testCaseResult.getTestCase().name
      extentTest = extent.createTest(testCaseName);

      // Checking whether the case has PASSED.
      if ( testCaseResult.getStatus().toString() == 'PASS' ) {
      // Logging passed cases and test steps’ resulting messages.
      extentTest.log(Status.PASS, testCaseName);
      log.info "$testCaseName has passed"
      for ( testStepResult in testCaseResult.getResults() ) {
      testStepResult.messages.each() {
      msg -> log.info msg
      extentTest.log(Status.INFO, msg);
      }
      }
      }

      // Checking whether the case has failed.
      if ( testCaseResult.getStatus().toString() == 'FAIL' ) {
      // Logging failed cases and test steps’ resulting messages.
      log.info "$testCaseName has failed"
      extentTest.log(Status.FAIL, testCaseName);
      for (testStepResult in testCaseResult.getResults() ) {
      testStepResult.messages.each() {
      msg -> log.info msg
      extentTest.log(Status.INFO, msg);
      }

      }
      }
      }
      extent.flush();