【问题标题】:Test Executed successfully but report doesn't extent report doesn't generate in specflow测试已成功执行,但报告未扩展报告未在 specflow 中生成
【发布时间】:2019-01-18 00:23:04
【问题描述】:

目前我正在 Specflow 中设计我的项目。我想对我的项目实施一些报告。目前我已经创建了一个单独的 .cs 文件并保留了我所有的报告设置。但是当我执行我的代码测试运行成功但没有生成报告时。我正在使用给定的代码,请检查并建议我

SeleniumDriver.cs

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ReportDemoPOC
{
    class SeleniumDriver
    {
        public static IWebDriver WebDriver { get; set; }

        public static string BaseAddress
        {
            get { return Constants.Url; }
        }

        public static void Intitialize()
        {
            WebDriver = new ChromeDriver();
            WebDriver.Manage().Window.Maximize();
            TurnOnWait();
        }

        public static void Navigate()
        {
            WebDriver.Navigate().GoToUrl(BaseAddress);
        }

        public static void Close()
        {
            WebDriver.Close();
        }
        public static void Quit()
        {
            WebDriver.Quit();
        }
        private static void TurnOnWait()
        {
            WebDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            WebDriver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(2);
        }

        public void Shutdown()
        {
            WebDriver.Quit();
        }
    }
}

Start.cs

using AventStack.ExtentReports;
using AventStack.ExtentReports.Reporter;
using AventStack.ExtentReports.Reporter.Configuration;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;

namespace ReportDemoPOC
{

    public class Start
    {
        public static ExtentReports extent;
        public static ExtentHtmlReporter htmlReporter;
        public static ExtentTest test;

       static Start()
        {
            if (extent == null)
            {
                BasicSetUp();
            }

        }
        [BeforeScenario]
        public void Setup()
        {
            SeleniumDriver.Intitialize();
            SeleniumDriver.Navigate();
            test = extent.CreateTest(ScenarioContext.Current.ScenarioInfo.Title);
        }

        [AfterScenario]
        public void TearDown()
        {
            if (ScenarioContext.Current.TestError != null)
            {
                var error = ScenarioContext.Current.TestError;
                var errormessage = "<pre>" + error.Message + "</pre>";
                //Add capture screen shot line here

                extent.AddTestRunnerLogs(errormessage);
                test.Log(Status.Error, errormessage);
                test.Fail(errormessage);
            }
            SeleniumDriver.Close();
        }

        [OneTimeSetUp]
        public static void BasicSetUp()
        {
           string pth = System.Reflection.Assembly.GetCallingAssembly().CodeBase;
           // string pth = System.IO.Directory.GetCurrentDirectory();
            string actualPath = pth.Substring(0, pth.LastIndexOf("bin"));
            string projectPath = new Uri(actualPath).LocalPath;
            Console.WriteLine(" -----------Project Path--------------------------------------");
            Console.WriteLine(projectPath);
            // string reportPath = projectPath + "Reports\\" + FeatureContext.Current.FeatureInfo.Title + ".html";
             string reportPath = projectPath + "Reports\\TestRunReport.html";
            // Console.WriteLine("Report Path is " + reportPath);


           htmlReporter = new ExtentHtmlReporter(reportPath);
           htmlReporter.Configuration().Theme = Theme.Dark;

           htmlReporter.Configuration().DocumentTitle = "SpecFlow Test Resport Document";

           htmlReporter.Configuration().ReportName = "Feature Run Results";

           extent = new ExtentReports();

            extent.AttachReporter(htmlReporter);
            //extent.LoadConfig(projectPath + "Extent-Config.xml");

        }


        [AfterFeature()]
        public static void EndReport()
        {
            extent.Flush();


        }
    }
}

LoginSteps.cs

using NUnit.Framework;
using ReportDemoPOC.Page;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TechTalk.SpecFlow;

namespace ReportDemoPOC.Steps
{
    [Binding]
    [TestFixture]
    class LoginSteps : Start
    {
        LoginPage loginPage;

        [Given(@"I am at Facebook login page")]
        public void GivenIAmAtFacebookLoginPage()
        {
            //Navigate();
            loginPage = new LoginPage();
        }

        [When(@"I enter ashusoni(.*)@gmail\.com in the Email or Phone textbox")]
        public void WhenIEnterAshusoniGmail_ComInTheEmailOrPhoneTextbox(String p0)
        {
            loginPage.enterValueInUser("abcd" + p0 + "@gmail.com");
        }

        [When(@"I Enter (.*) in the password")]
        public void WhenIEnterInThePassword(String p0)
        {
            loginPage.enterValueInPassword(p0);
        }

        [When(@"Click on the Login button")]
        public void WhenClickOnTheLoginButton()
        {
            loginPage.clickOnLoginButton();
        }

        [Then(@"Application should display an error message")]
        public void ThenApplicationShouldDisplayAnErrorMessage()
        {
            Console.WriteLine("Verification");
           // loginPage.Shutdown();
        }


    }
}

【问题讨论】:

    标签: c# selenium-webdriver specflow extentreports


    【解决方案1】:

    这听起来像是跑题了,但仍然... 我不确定为您使用 C# 编写的自动化框架使用 ExtentReports 是否有意义。 从 v.4 ExtentReports 开始,他们不再支持它。 他们的回答是他们将只支持 Java。

    【讨论】:

    • .NET 支持正在考虑中,如果团队同意,预计开始日期为 2019 年 1 月。如果一切顺利,那么所有记者和 Klov 的完全支持将可用。当我有更多信息时,我会更新这个线程。放弃支持的原因只是因为社区的贡献是零,而且我担心如果重复,同样的情况可能会发生。如果计划开发,我只是希望事情会变得更好。
    【解决方案2】:

    这是 NUnit 3 的一项功能。您应该通过名为“NUnit3TestAdapter”的 NuGet 包安装 Visual Studio 测试适配器 (https://github.com/nunit/docs/wiki/Visual-Studio-Test-Adapter) 以使 OneTimeSetup 正常工作。

    然后您可以检查报告的执行情况:-)

    【讨论】:

    • 您好 Jeroen,感谢您的回复,但我已经在使用 NUnit3TestAdapter" version="3.9.0" 仍然无法生成报告,您能否建议任何其他解决方案
    • 这很奇怪。设置断点时,BasicSetup()中的代码是否到达?
    • 我在 BasicSetup() ,TearDown() 上尝试了断点,但它没有到达那里
    【解决方案3】:

    也许您的报告是在临时文件夹中创建的(一段时间后,我使用 Windows 搜索找到了它)。我在使用 Visual Studio 运行测试时也有同样的情况。尝试使用 Nunit 控制台应用程序运行您的测试。单独下载,然后使用控制台命令运行测试

    nunit "带有测试的已编译 .dll 的路径"

    在这种情况下,我认为您应该在 .dll 文件附近找到报告。这发生在我的案例中(使用 Allure 报告)。

    【讨论】:

    • 您好乌克兰人,感谢您的回复,我更改了我的代码,现在生成的报告很少,但步骤名称stackoverflow.com/q/53260273/1678415 中存在一些问题请检查给定的票证并建议我的代码有什么问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-17
    • 2018-07-16
    • 1970-01-01
    • 2014-02-15
    相关资源
    最近更新 更多