Selenium C# Extent report не генерирует HTML-файл в указанной папке

Я пытаюсь сгенерировать отчет в HTML, используя отчет Extent (версия ="3.1.3") для Selenium Webdriver C#, но в указанной папке я не могу увидеть файл 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();
    }

}

Степень-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>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>

3 ответа

Выполните этот шаг и проверьте, генерируется ли отчет или нет, убедитесь, что выполнение теста выполнено правильно, и экстент.fluch() был вызван. Иначе, отчет о протяженности не может быть сгенерирован.

  1. Создайте папку в рабочей области вашего проекта с именем "eReport"
  2. Создать имя переменной как reportLocation = "./eReport/" + "TestReport.html";
  3. Передайте переменную reportLocation в метод ExtentHTMlReport,

    var reportPath = new ExtentHtmlReporter (reportLocation);

И в дальнейшем вы можете проверить, сгенерировано оно или нет.

Вы можете попробовать пример с Basic из их официального документа http://extentreports.com/docs/versions/3/net/.

Ниже приведен фрагмент кода:

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

Вы загрузили расположение файла экстента-конфигурации в объекте HTML.

reportPath.LoadConfig("Extent-config.xml")
Другие вопросы по тегам