使用AventStack.ExtentReports会出错

时间:2017-03-14 03:43:07

标签: c# html

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

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


    }
}

4 个答案:

答案 0 :(得分:0)

这是一个使用selenium的示例范围报告,它生成一个使用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();
        }
    }
}

答案 1 :(得分:0)

按如下方式使用导入方式

    using RelevantCodes.ExtentReports;

答案 2 :(得分:0)

#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
    }

答案 3 :(得分:0)

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