范围报告V4覆盖测试结果

时间:2019-01-17 13:46:07

标签: extentreports selenium-extent-report

我将Extent Reports V3与硒/ C#一起使用,而我刚刚升级到V4。以前,每次运行都会根据日期戳/类名称/时间戳给我一个独特的报告。但是,转到V4后,它始终将所有内容放在同一个名为“索引”的文件和一个单独的名为“仪表板”的文件下,该文件位于另一个文件的上方以进行导航。

这是我启动报告的代码:

hello

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

 ^No\.?\s?(\d+(?:(?:,\s?\d+)+,?\s?&\s?\d+)??),?\s?(.*?)$

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

我最近开始研究Extent Reports v4,为了解决文件替换的问题,您必须按照@Ishita Shah的回答使用v3格式的v4,请参阅此Extent Reports generating two HTML Reports

此外,我做了一些调整,可以在每次运行时生成新的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);
}

replaceTextHTMLFile:

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);
    }
}
相关问题