【问题标题】:using AventStack.ExtentReports gives an error使用 AventStack.ExtentReports 会出错
【发布时间】:2017-08-04 06:45:38
【问题描述】:

在 YouTube 演示中,我收到了这段代码,但我得到了这个让我难过的错误——“ExtentReports”不包含带有 2 个参数的构造函数。我的参考错了吗?我使用的是 3.03 版的 ExtentReports

using NUnit.Framework;
using AventStack.ExtentReports;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

    namespace ExtentDemoYoutube
    {
        [TestFixture]
        public class BasicReport
        {
            public ExtentReports extent;
            public ExtentTest test;

            [OneTimeSetUp]
            public void StartReport()
            {
                string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
                string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
            string projectPath = new Uri(actualPath).LocalPath;

            string reportPath = projectPath + "Reports\\MyOwnReport.html";

            extent = new ExtentReports(reportPath, true);

            extent.AddSystemInfo("Host Name", "Joe Loyzaga")
                .AddSystemInfo("Environment", "QA")
                .AddSystemInfo("User Name", "Joe Loyzaga");

            extent.LoadConfig(projectPath + "extent-config.xml");

        }

        [Test]
        public void DemoReportPass()
        {
            test = extent.StartTest("DemoReportPass");
            Assert.IsTrue(true);
            test.log(LogStatus.Pass, "Assert Pass as condition is True");
        }

        [Test]
        public void DemoReportFail()
        {
            test = extent.StartTest("DemoReportFail");
            Assert.IsTrue(false);
            test.log(LogStatus.Pass, "Assert Pass as condition is Fail");

        }

        [TearDown]
        public void GetResult()
        {
            var status = TestContext.CurrentContext.Result.Outcome.Status;
            var stackTrace = "<pre>" +TestContext.CurrentContext.Result.StackTrace+"</pre>";
            var errorMessage = TestContext.CurrentContext.Result.Message;

            if(status==NUnit.Framework.Interfaces.TestStatus.Failed)

            {
                test.Log(LogStatus.Fail, stackTrace + errorMessage);
            }
            extent.EndTest(test);
        }

        [OneTimeTearDown]
        public void EndReport()
        {
            extent.Flush();
            extent.Close();
        }


    }
}

【问题讨论】:

  • 我认为你缺少合适的标签

标签: c# html


【解决方案1】:

这是一个使用 selenium 的示例 extentreport,它生成使用 selenium webdriver 的报告

using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports.Reporter.Configuration;
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;

namespace FrameworkForJoe
{
    [TestFixture]
    public class SampleTest
    {
        private static IWebDriver driver;
        private static ExtentReports extent;
        private static ExtentHtmlReporter htmlReporter;
        private static ExtentTest test;

        [OneTimeSetUp]
        public void SetupReporting()
        {
            htmlReporter = new ExtentHtmlReporter(@"C:\Git\joesreport.html");

            htmlReporter.Configuration().Theme = Theme.Dark;

            htmlReporter.Configuration().DocumentTitle = "JoesDocument";

            htmlReporter.Configuration().ReportName = "JoesReport";

            /*htmlReporter.Configuration().JS = "$('.brand-logo').text('test image').prepend('<img src=@"file:///D:\Users\jloyzaga\Documents\FrameworkForJoe\FrameworkForJoe\Capgemini_logo_high_res-smaller-2.jpg"> ')";*/
            htmlReporter.Configuration().JS = "$('.brand-logo').text('').append('<img src=D:\\Users\\jloyzaga\\Documents\\FrameworkForJoe\\FrameworkForJoe\\Capgemini_logo_high_res-smaller-2.jpg>')";
            extent = new ExtentReports();

            extent.AttachReporter(htmlReporter);
        }

        [SetUp]
        public void InitBrowser()
        {
            driver = new ChromeDriver();
            driver.Manage().Window.Maximize();            
        }

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

            driver.Navigate().GoToUrl("http://www.google.com");

            try {
                Assert.IsTrue(true);
                test.Pass("Assertion passed");
            } catch (AssertionException)
            {
                test.Fail("Assertion failed");
                throw;
            }
        }

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

            driver.Navigate().GoToUrl("http://www.yahoo.com");

            try
            {
                Assert.IsTrue(false);
                test.Pass("Assertion passed");
            }
            catch (AssertionException)
            {
                test.Fail("Assertion failed");
                throw;
            }
        }

        [TearDown]
        public void CloseBrowser()
        {
            driver.Quit();
        }

        [OneTimeTearDown]
        public void GenerateReport()
        {
            extent.Flush();
        }
    }
}

【讨论】:

    【解决方案2】:

    如下使用import语句

        using RelevantCodes.ExtentReports;
    

    【讨论】:

      【解决方案3】:
      #create 2 files#
      1) ExtentManager.cs n write following code
          using AventStack.ExtentReports;
          using AventStack.ExtentReports.Reporter;
          using AventStack.ExtentReports.Reporter.Configuration
      namespace ProTradeExeAutomation
      {
           public class ExtentManager
              {
                      public static ExtentHtmlReporter htmlReporter;
                      private static ExtentReports extent;
      
                      private ExtentManager()
                      {
      
                      }
                      public static ExtentReports GetInstance()
                      {
                          if (extent == null)
                          {
      
      
          string startupPath = System.IO.Directory.GetCurrentDirectory();
                          string startupPathSubString = startupPath.Substring(0, 49);
                          string fullProjectPath = new Uri(startupPathSubString).LocalPath;
                          string reportpath = fullProjectPath + "Reports\\SampleReport.html";
      
                          htmlReporter = new ExtentHtmlReporter(reportpath);
                          htmlReporter.Configuration().Theme = Theme.Dark;
      
                          extent = new ExtentReports();
                          extent.AttachReporter(htmlReporter);
                          extent.AddSystemInfo("Host Name", "ABC");
                          extent.AddSystemInfo("Environment", "Test QA");
                          extent.AddSystemInfo("Username", "XYZ");
                          htmlReporter.LoadConfig("urpath\\extent-config.xml"); //Get the config.xml file 
                      }
                      return extent;
                  }
          }
      }
      ##In Test File create obj of ExtentManager n use to create test##
      
       public class LoginPageTest
          {
              LoginPage loginPage;
              ExtentReports rep = ExtentManager.GetInstance();
              ExtentTest test;
      
              [Test,Order(1)]
              public void LoginPageTestMethod()
              {
                  test = rep.CreateTest("LoginPageTest");
                  test.Log(Status.Info, "Starting test");
                  loginPage.LogginPage(Constant.USERNAME, Constant.PASSWORD);
                  Thread.Sleep(9000);
                  Thread.Sleep(5000);
                  try
                  {
                      Assert.IsTrue(true);
                      test.Pass("Test passed");
                  }
                  catch (AssertionException)
                  {
                      test.Fail("Test failed");
                  }
                  rep.Flush();//remember to do this
          }
      

      【讨论】:

      • 能否请您也添加解释?
      • 文件 1 将充当范围管理器,它将拥有您保存报告和其他信息的路径,称为 GetInstance() 文件 2 是您编写测试方法的测试类,您可以在其中创建范围对象经理,可以调用 GetInstance() 并使用它
      【解决方案4】:

      回答上面的问题: 使用 RelevantCodes.ExtentReports。 转到管理 Nuget 包->浏览 ExtentReports。 在下载之前选择版本 2.41.0 然后安装。 2.41.0 支持 RelevantCodes.ExtentReport,而 4.0.3 版本支持 Aventstack.ExtentReports。

      【讨论】:

      • 您好,欢迎来到 StackOverflow。一年多后,您的答案与@AshishKamble 相同,请尝试改进现有答案,而不是复制/粘贴您自己的答案。
      猜你喜欢
      • 1970-01-01
      • 2021-04-27
      • 1970-01-01
      • 2020-07-20
      • 2016-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      相关资源
      最近更新 更多