2017-05-08 134 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類的結合 - 屬性。沒有這個,那裏定義的鉤子就不會被調用。