Selenium C#范围报告未在指定的文件夹中生成HTML文件

时间:2018-07-12 14:03:07

标签: selenium extentreports selenium-extent-report

我正在尝试使用Selenium Webdriver C#的范围报告(版本“ 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();
    }

}

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>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 个答案:

答案 0 :(得分:0)

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

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

    var reportPath = new ExtentHtmlReporter(reportLocation);

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

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

答案 1 :(得分: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();
    }
}

答案 2 :(得分:-1)

您已在HTML对象中加载了扩展配置文件的位置。

reportPath.LoadConfig("Extent-config.xml")