Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1. using AutomationFramework.Base;
  2. using TechTalk.SpecFlow;
  3. using AutomationFramework.Helpers;
  4. using AutomationFramework.Config;
  5. using AventStack.ExtentReports;
  6. using AventStack.ExtentReports.Reporter;
  7. using AventStack.ExtentReports.Gherkin.Model;
  8.  
  9. namespace EmployeeTest.Hooks
  10. {
  11.  
  12. [Binding]
  13. public class HookInitialize : TestInitializeHook
  14. {
  15.  
  16. private readonly ParallelConfig _parallelConfig;
  17. private readonly FeatureContext _featureContext;
  18. private readonly ScenarioContext _scenarioContext;
  19.  
  20. public HookInitialize(ParallelConfig parallelConfig, FeatureContext featureContext, ScenarioContext scenarioContext) : base(parallelConfig)
  21. {
  22. _parallelConfig = parallelConfig;
  23. _featureContext = featureContext;
  24. _scenarioContext = scenarioContext;
  25. }
  26.  
  27. private static ExtentTest featureName;
  28. private static ExtentTest scenario;
  29. private static ExtentReports extent;
  30.  
  31.  
  32. [BeforeTestRun]
  33. public static void TestInitalize()
  34. {
  35. //Initialize the Report
  36. var htmlReporter = new ExtentHtmlReporter(@"C:LogsExtentReport.html");
  37. htmlReporter.Config.Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;
  38. htmlReporter.Config.ReportName = "Automation Test Report";
  39. extent = new ExtentReports();
  40. extent.AttachReporter(htmlReporter);
  41.  
  42. }
  43.  
  44.  
  45. [AfterStep]
  46. public void InsertReportingSteps()
  47. {
  48. var stepType = _scenarioContext.StepContext.StepInfo.StepDefinitionType.ToString();
  49.  
  50.  
  51. if (_scenarioContext.TestError == null)
  52. {
  53. if (stepType == "Given")
  54. scenario.CreateNode<Given>(_scenarioContext.StepContext.StepInfo.Text);
  55. else if (stepType == "When")
  56. scenario.CreateNode<When>(_scenarioContext.StepContext.StepInfo.Text);
  57. else if (stepType == "Then")
  58. scenario.CreateNode<Then>(_scenarioContext.StepContext.StepInfo.Text);
  59. else if (stepType == "And")
  60. scenario.CreateNode<And>(_scenarioContext.StepContext.StepInfo.Text);
  61. }
  62. else if (_scenarioContext.TestError != null)
  63. {
  64. if (stepType == "Given")
  65. {
  66. scenario.CreateNode<Given>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.InnerException);
  67. ScreenShotHelpers.CaptureScreen(_parallelConfig.Driver, _featureContext.FeatureInfo.Title);
  68. }
  69. else if (stepType == "When")
  70. {
  71. scenario.CreateNode<When>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.InnerException);
  72. ScreenShotHelpers.CaptureScreen(_parallelConfig.Driver, _featureContext.FeatureInfo.Title);
  73. }
  74. else if (stepType == "Then")
  75. {
  76. scenario.CreateNode<Then>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.Message);
  77. ScreenShotHelpers.CaptureScreen(_parallelConfig.Driver, _featureContext.FeatureInfo.Title);
  78. }
  79. }
  80.  
  81.  
  82.  
  83. }
  84.  
  85. [BeforeScenario]
  86. public void Initialize()
  87. {
  88. InitializeSettings();
  89. Settings.ApplicationCon = Settings.ApplicationCon.DBConnect(Settings.AppConnectionString);
  90.  
  91. //Create feature name
  92. featureName = extent.CreateTest<Feature>(_featureContext.FeatureInfo.Title);
  93.  
  94. //Get scenario name
  95. scenario = featureName.CreateNode<Scenario>(_scenarioContext.ScenarioInfo.Title);
  96.  
  97. }
  98.  
  99.  
  100. [AfterScenario]
  101. public void TestStop()
  102. {
  103. _parallelConfig.Driver.Quit();
  104.  
  105. }
  106.  
  107. [AfterTestRun]
  108. public static void TearDownReport()
  109. {
  110. //Write the report to the report directory
  111. extent.Flush();
  112.  
  113.  
  114. }
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement