2017-05-08 122 views
0

目前我正在Specflow中设计我的项目。我想实施一些报告给我的项目。目前我已经创建了一个单独的.cs文件并保留了我的所有报告设置。但是这些步骤无法实现。任何人都可以请指导我如何设计我的流程,以及如何与特征文件集成? 请找到下面的BaseReport.cs文件和我的步骤定义文件。如何在Specflow项目中生成报告(范围报告)

namespace Verivox.CommonLib 
{ 

    public class BaseReport 
    { 
     public static ExtentReports extent; 
     public static ExtentTest test; 

     [BeforeFeature()] 
     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; 

      string reportPath = projectPath + "Reports\\" + FeatureContext.Current.FeatureInfo.Title + ".html"; 

      extent = new ExtentReports(reportPath, true); 

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

     } 

     [BeforeScenario()] 
     public static void BeforeScenarioSetUp() 
     { 

      test = extent.StartTest("Running Scenario -->" + ScenarioContext.Current.ScenarioInfo.Title); 
     } 

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

       extent.EndTest(test); 

      } 
     } 

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

步骤

namespace Verivox.Steps 
    { 
     [Binding] 
     class CalculationVerificationSteps 
     { 
      [Given(@"I have navigate to Home Page")] 
      public void GivenIHaveNavigateToHomePage() 
      { 
       Browser.Current.Navigate().GoToUrl(ConfigurationManager.AppSettings["seleniumBaseUrl"]); 
       PropertyCollection.currentPage = new HomePage(); 
       Browser.Current.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); 

      } 

      [Given(@"Navigate to Mobile Calculator under All Comparison Section")] 
      public void GivenNavigateToMobileCalculatorUnderAllComparisonSection() 
      { 

       PropertyCollection.currentPage.As<HomePage>().MainCompItemClick("Telekommunikation"); 
       PropertyCollection.currentPage.As<HomePage>().SubCompItemClick("Mobilfunk"); 
       PropertyCollection.currentPage.As<HomePage>().CalculatorLinkClick("Mobiles Internet"); 

      } 

      [Then(@"Mobile Calculator should appear")] 
      public void ThenMobileCalculatorShouldAppear() 
      { 
       Assert.IsTrue(PropertyCollection.currentPage.As<HomePage>().IsMobileInternetCalcExistance()); 
      } 

      [Then(@"(.*) option and (.*) option is selected by default\.")] 
      public void ThenMonatsflatrateOptionAndSIMOptionIsSelectedByDefault_(string defaultTarif, string hardware) 
      { 
       try 
       { 
        Assert.IsTrue(PropertyCollection.currentPage.As<HomePage>().VerifyMobiIntSelectedItem(defaultTarif)); 
        string colorCode = PropertyCollection.currentPage.As<HomePage>().VerifySelectedHardWare(); 
        Assert.AreEqual(0, string.Compare("rgba(253, 138, 2, 1)", colorCode, StringComparison.OrdinalIgnoreCase)); 
       } 
       catch (Exception) 
       { 
        BaseReport.test.Log(LogStatus.Fail, "Default selections are incorrect."); 
       } 


      } 
+0

您能否修复代码格式?这有点难以理解。 –

回答

0

你缺少的BaseReport类的结合 - 属性。没有这个,那里定义的钩子就不会被调用。