2

我正在使用带有 selenium / C# 的 Extent Reports V3,我刚刚升级到 V4。以前每次运行都会根据日期戳/班级名称/时间戳给我一个独特的报告。但是,在迁移到 V4 之后,它总是将所有内容放在一个名为“index”的文件和一个名为“dashboard”的单独文件下,该文件位于另一个文件之上,用于导航目的。

这是我开始报告的代码:

    htmlReporter = new ExtentHtmlReporter($"C:\\Test-Results\\" + dateStamp + "\\" + TestClassName + " " + timeStamp + ".html");
    extent = new ExtentReports();
    extent.AttachReporter(htmlReporter);
    extent.AddSystemInfo("Host Name", "Extent Framework");
    extent.AddSystemInfo("Environment", "Local Machine");
    extent.AddSystemInfo("User Name", "MyName");
    htmlReporter.LoadConfig(CurrentDirectory + "\\extent-config.xml");

现在,每次我运行测试时,它都会用新的测试结果覆盖现有的索引文件,而不是附加我当前的结果或给我一个唯一的索引文件。如果需要,我可以提供有关如何开始报告/创建测试所需的任何其他信息,但现在这是我的测试文件中的内容:

    [ClassInitialize()]
    public static void MyClassInitialize(TestContext testContext)
    {
        report.startReport("Report Name");
    }

    [ClassCleanup()]
    public static void MyClassCleanup()
    {
        report.Flush();
    }

    [TestInitialize()]
    public void MyTestInitialize()
    {
        string name = TestContext.TestName;
        report.CreateTest(name);

    }
4

2 回答 2

2

它是 v4 的增强功能。为了克服它,我们必须在版本 4 中使用 ExtentV3HtmlReporter 类。通过使用这个类,我们将拥有像以前一样的报告。它不会被索引文件覆盖。此外,V4 解决了许多错误。所以使用的东西与第 4 版报告相同。您可以比较这两个报告,您将得到您的解决方案。

于 2019-01-18T05:27:59.803 回答
0

我最近开始研究 Extent Reports v4 并解决文件被替换的问题,您必须按照 @Ishita Shah 的回答使用 v4 和 v3 格式,请参阅此Extent Reports 生成两个 HTML 报告

另外,我做了一些调整,为每次运行生成新的 html 文件,而不替换已经生成的文件。

string fileName = "ExtentReport_" + DateTime.Now.ToString("MMM-dd-yyyy hh-mm-ss");
//Rename index.html with a new file name
renameFile("C:\\Reports\\index.html", fileName + "_Index.html");

//Replace "index.html" string inside the "index.html" file with the new filename
replaceTextHTMLFile("C:\\Reports\\" + fileName + "_Index.html", "index.html", fileName + "_Index.html");

Dashboard.html 和 tags.html 可以使用相同的逻辑

重新命名文件:

public static void renameFile(string filePath, string oldFileName, string newFileName)
{
    System.IO.File.Move(filePath + oldFileName, filePath + newFileName);
}

替换文本HTML文件:

public static void replaceTextHTMLFile(string filePath, string findText, string replaceText)
{
    try
    {
        StreamReader objReader = new StreamReader(filePath);
        string content = objReader.ReadToEnd();
        objReader.Close();

        content = Regex.Replace(content, findText, replaceText);

        StreamWriter writerObj = new StreamWriter(filePath);
        writerObj.Write(content);
        writerObj.Close();
    }
    catch (Exception e)
    {
        Console.WriteLine("Exception occurred. Messgae: " + e.Message);
    }
}
于 2019-11-04T17:14:33.317 回答