首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用AventStack.ExtentReports会产生错误

使用AventStack.ExtentReports会产生错误
EN

Stack Overflow用户
提问于 2017-03-14 11:43:07
回答 4查看 14K关注 0票数 0

在一个YouTube演示中,我得到了这个代码,我得到了这个错误-- 'ExtentReports‘没有包含一个接受2个参数的构造函数。我的推荐信是错的吗?我使用的是3.03版的ExtentReports

代码语言:javascript
复制
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();
        }


    }
}
EN

回答 4

Stack Overflow用户

发布于 2017-03-29 11:20:49

这是一个使用selenium生成使用selenium webdriver的报告的范围报告示例

代码语言:javascript
复制
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();
        }
    }
}
票数 0
EN

Stack Overflow用户

发布于 2018-08-21 17:01:00

使用导入字符串,如下所示

代码语言:javascript
复制
    using RelevantCodes.ExtentReports;
票数 0
EN

Stack Overflow用户

发布于 2019-07-03 17:05:15

代码语言:javascript
复制
#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
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42777398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档