测试已成功执行,但报告未在specflow中未生成报告

时间:2018-10-15 09:29:21

标签: c# selenium-webdriver specflow extentreports

当前,我正在使用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();
        }


    }
}

3 个答案:

答案 0 :(得分:1)

这听起来似乎有点题外话,但仍然... 我不确定为您使用C#编写的自动化框架使用ExtentReports是否有意义。 从第4版ExtentReports开始,他们不再支持它。 他们的答复是他们将仅支持Java。

答案 1 :(得分:0)

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

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

答案 2 :(得分:0)

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

  

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

在这种情况下,我认为您应该在.dll文件附近找到报告。就我而言(使用“魅力”报告)。

相关问题