extentreports-java icon indicating copy to clipboard operation
extentreports-java copied to clipboard

I can't generate html file extent Report selenium C#

Open MedAmineMerzouk opened this issue 7 years ago • 0 comments

I worked with ExtentReports with selenium in visual studio C #, I ran the case tests, but the report file .html doesn't generate in the report folder that I created in solution explorer. I don't know where is the problem, I changed the path of the report file to check, and it still doesn't generate. Here is my code:

  using NUnit.Framework;
  using RelevantCodes.ExtentReports;
    using System;
  using System.Collections.Generic;
 using System.Linq;
   using System.Text;
 using System.Threading.Tasks;

  namespace ExtentReportsDemo
   {
    [TestFixture]
    public class BasicReport
  {
  public ExtentReports extent;
   public ExtentTest test;

   [OneTimeSetUp]
   public void StartReport()
   {
    string pth = 
       System.Reflection.Assembly.GetCallingAssembly().CodeBase;
    string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
    Console.WriteLine("actual" + actualPath);

    string projectPath = new Uri(actualPath).LocalPath; // project path 
                                                of your solution
    //Console.WriteLine("project" + projectPath);
    string reportPath = projectPath + "Reports\\testreport.html";
    Console.WriteLine("report" + reportPath);

    // true if you want to append data to the report.  Replace existing 
    report with new report.  False to create new report each time
    extent = new ExtentReports(reportPath, false);
    extent.AddSystemInfo("Host Name", "MININT-F36S5EH")
        .AddSystemInfo("Environment", "QA")
        .AddSystemInfo("User Name", "testUser");

    extent.LoadConfig(projectPath + "extent-config.xml");

  }

  [Test]
  public void DemoReportPass()
   {
    test = extent.StartTest("DemoReportPass");
    Assert.IsTrue(true);
    test.Log(LogStatus.Pass, "Assert Pass as consition is true");

   }

[Test]
public void DemoReportFail()
{
    test = extent.StartTest("DemoReportPass");
    Assert.IsTrue(false);
    test.Log(LogStatus.Fail, "Assert Pass as condition is false");

}

[TearDown]
public void GetResult()
{
    var status = TestContext.CurrentContext.Result.Outcome.Status;
    var stackTrace = "<pre>" + 
 TestContext.CurrentContext.Result.StackTrace + "</pre>";
    var errorMessage = TestContext.CurrentContext.Result.Message;

    if (status == NUnit.Framework.Interfaces.TestStatus.Failed)
    {
        test.Log(LogStatus.Fail, stackTrace + errorMessage);
    }
    extent.EndTest(test);

}

[OneTimeTearDown]
public void EndReport()
{
    extent.Flush();
    extent.Close();
}

}

}

and extent-config.xml:

  <?xml version="1.0" encoding="UTF-8"?>
  <extentreports>
 <configuration>
 <!-- report theme -->
 <!-- standard, dark -->
 <theme>standard</theme>

<!-- document encoding -->
 <!-- defaults to UTF-8 -->
<encoding>UTF-8</encoding>

    <!-- protocol for script and stylesheets -->
    <!-- defaults to https -->
    <protocol>https</protocol>

   <!-- title of the document -->
    <documentTitle>ExtentReports 2.0</documentTitle>

      <!-- report name - displayed at top-nav -->
    <reportName>Automation Report</reportName>

         <!-- report headline - displayed at top-nav, after reportHeadline -->
        <reportHeadline></reportHeadline>

   <!-- global date format override -->
    <!-- defaults to yyyy-MM-dd -->
      <dateFormat>yyyy-MM-dd</dateFormat>

      <!-- global time format override -->
  <!-- defaults to HH:mm:ss -->
   <timeFormat>HH:mm:ss</timeFormat>

     <!-- custom javascript -->
  <scripts>
 <![CDATA[
 $(document).ready(function() {

  });
   ]]>
   </scripts>

  <!-- custom styles -->
  <styles>
   <![CDATA[

 ]]>
</styles>
</configuration>

I tried to put the static path and it doesn't work, and about debugging to check where the problem is located, I can't debugged because it's a class library so there is no point of execution.

MedAmineMerzouk avatar May 29 '18 09:05 MedAmineMerzouk