1

我在 Visual Studio C# 中使用 Selenium 使用 ExtentReports,我运行了案例测试,但报告文件 .html 没有在我在解决方案资源管理器中创建的报告文件夹中生成。不知道问题出在哪里,我改了report文件的路径去检查,还是没有生成。这是我的代码:

 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();
    }

    }

}

和范围-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>

4

1 回答 1

1

请先通过静态位置尝试,例如在任何驱动器 C:\ 或 D:\ 并检查其生成,

如果没有,请通过更新报告终止调用来检查调试器。

另外,请确保您的EndReport()方法正在调用其中的报告终止正在调用那里,

如果是这样,请尝试调用方法extent.EndTest(test);EndReport()以便检查它是否调用。

如果报告不是要求终止,则不会生成。

于 2018-05-22T12:35:45.253 回答