1

我正在尝试使用 Selenium Webdriver C# 的 Extent 报告(版本 =“3.1.3”)生成 HTML 报告,但在指定文件夹中,我无法在成功执行测试脚本后看到 HTML 文件。

如果您能帮助我找出问题所在并为此问题提供解决方案,那就太好了。

提前致谢。

请在下面找到代码片段。

namespace Selenium_Demo_01
 {
[TestFixture]
public class Demo01
{
    IWebDriver driver;
    Program dataDriven = new Program();

    public ExtentReports extent;
    public ExtentTest test;

    [OneTimeSetUp]
    public void ClassSetup()
    {
        var reportPath = new ExtentHtmlReporter(@"I:\Selenium\VS Project 
                                            files\Selenium_Demo_01\
                                                       Selenium_Demo_01\Reports\Demo_Report_01.html");

        extent = new ExtentReports();
        extent.AttachReporter(reportPath);
    }

    [Test]
    public void test_D365Login()
    {
        test = extent.CreateTest("test_D365Login");

        string webTitle, webTitle1;

        //Get web page Title
        driver.Url = appURL;
        webTitle = driver.Title;
        System.Console.WriteLine(webTitle);

        Assert.AreEqual(title1, webTitle);
        test.Pass("Assertion passed");

        //Get web page Title
        webTitle1 = driver.Title;
        System.Console.WriteLine(webTitle1);

        Assert.AreEqual(title2, webTitle1);
        test.Pass("Assertion passed");
    }

    [TearDown]
    public void closeBrowser()
    {
        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace)
                ? ""
                : string.Format("{0}", 
                       TestContext.CurrentContext.Result.StackTrace);
        Status logstatus;

        switch (status)
        {
            case TestStatus.Failed:
                logstatus = Status.Fail;
                break;
            case TestStatus.Inconclusive:
                logstatus = Status.Warning;
                break;
            case TestStatus.Skipped:
                logstatus = Status.Skip;
                break;
            default:
                logstatus = Status.Pass;
                break;
        }

        test.Log(logstatus, "Test ended with " + logstatus + stacktrace);
        extent.RemoveTest(test);
        extent.Flush();
        driver.Close();
    }

}

范围配置.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>Automation testing</documentTitle>

    <chartVisibilityOnOpen>true</chartVisibilityOnOpen>

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

    <!-- location of charts in the test view -->
    <!-- top, bottom -->
    <testViewChartLocation>bottom</testViewChartLocation>

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

            });
        ]]>
    </scripts>

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

        ]]>
    </styles>
</configuration>

4

3 回答 3

0

请按照步骤检查是否正在生成报告,确保您的测试执行正确完成,并且调用了 extent.fluch()。否则,无法生成范围报告。

  1. 在名为“eReport”的项目工作区中创建文件夹
  2. 创建变量名称为 reportLocation = "./eReport/" + "TestReport.html";
  3. 将 reportLocation 变量传递给 ExtentHTMlReport 方法,

    var reportPath = new ExtentHtmlReporter(reportLocation);

您可以进一步检查它是否生成。

您可以尝试使用他们官方文档中的基本示例, http ://extentreports.com/docs/versions/3/net/#examples

于 2018-07-13T06:33:02.067 回答
0

请在下面找到代码片段:

[TestFixture]
class Demo
{
    public ExtentReports extent;
    public ExtentTest test;

    [SetUp]
    public void TestSetup()
    {
        var reportPath = new ExtentHtmlReporter
            (@"C:\Users\Administrator\Documents\visual studio 2015\Projects\Selenium_D365\Selenium_D365\eReports\Demo_Report_01.html");
        //var reportLocation = "./Reports/" + "TestReport.html";
        //var reportPath = new ExtentHtmlReporter(reportLocation);
        extent = new ExtentReports();
        extent.AttachReporter(reportPath);
    }

    [Test]
    public void test_D365Login()
    {
        test = extent.CreateTest("test_D365Login");

        Assert.IsTrue(true);
        test.Pass("Assertion passed");
    }

    [TearDown]
    public void TestCleanup()
    {
        var status = TestContext.CurrentContext.Result.Outcome.Status;
        var stacktrace = string.IsNullOrEmpty(TestContext.CurrentContext.Result.StackTrace);
        Status logstatus = Status.Pass;

        test.Log(logstatus, "Test ended with " + status + stacktrace);

        extent.RemoveTest(test);
        extent.Flush();
    }
}
于 2018-07-13T11:03:54.190 回答
-1

您已经在 HTML 对象中加载了 extent-config 文件位置。

reportPath.LoadConfig("Extent-config.xml")
于 2018-10-08T16:30:18.020 回答