我在Visual Studio C#中使用selenium与ExtentReports合作,我运行了案例测试,但报告文件.html在我在解决方案资源管理器中创建的报告文件夹中没有生成。我不知道问题出在哪里,我更改了报告文件的路径以进行检查,但仍然无法生成。 这是我的代码:
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();
}
}
}
和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>
答案 0 :(得分:1)
请首先按静态位置尝试,就像在任何驱动器C:\或D:\中一样,检查它的生成位置,
如果没有,请通过更新报告终止呼叫来检查调试器。
另外,请确保您的EndReport()
方法正在调用哪个报告终止,
如果有,请尝试使用extent.EndTest(test);
方法拨打EndReport()
,以便检查是否有通话。
如果报告没有要求终止,则不会生成。