Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using AutomationFramework.Base;
- using TechTalk.SpecFlow;
- using AutomationFramework.Helpers;
- using AutomationFramework.Config;
- using AventStack.ExtentReports;
- using AventStack.ExtentReports.Reporter;
- using AventStack.ExtentReports.Gherkin.Model;
- namespace EmployeeTest.Hooks
- {
- [Binding]
- public class HookInitialize : TestInitializeHook
- {
- private readonly ParallelConfig _parallelConfig;
- private readonly FeatureContext _featureContext;
- private readonly ScenarioContext _scenarioContext;
- public HookInitialize(ParallelConfig parallelConfig, FeatureContext featureContext, ScenarioContext scenarioContext) : base(parallelConfig)
- {
- _parallelConfig = parallelConfig;
- _featureContext = featureContext;
- _scenarioContext = scenarioContext;
- }
- private static ExtentTest featureName;
- private static ExtentTest scenario;
- private static ExtentReports extent;
- [BeforeTestRun]
- public static void TestInitalize()
- {
- //Initialize the Report
- var htmlReporter = new ExtentHtmlReporter(@"C:LogsExtentReport.html");
- htmlReporter.Config.Theme = AventStack.ExtentReports.Reporter.Configuration.Theme.Dark;
- htmlReporter.Config.ReportName = "Automation Test Report";
- extent = new ExtentReports();
- extent.AttachReporter(htmlReporter);
- }
- [AfterStep]
- public void InsertReportingSteps()
- {
- var stepType = _scenarioContext.StepContext.StepInfo.StepDefinitionType.ToString();
- if (_scenarioContext.TestError == null)
- {
- if (stepType == "Given")
- scenario.CreateNode<Given>(_scenarioContext.StepContext.StepInfo.Text);
- else if (stepType == "When")
- scenario.CreateNode<When>(_scenarioContext.StepContext.StepInfo.Text);
- else if (stepType == "Then")
- scenario.CreateNode<Then>(_scenarioContext.StepContext.StepInfo.Text);
- else if (stepType == "And")
- scenario.CreateNode<And>(_scenarioContext.StepContext.StepInfo.Text);
- }
- else if (_scenarioContext.TestError != null)
- {
- if (stepType == "Given")
- {
- scenario.CreateNode<Given>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.InnerException);
- ScreenShotHelpers.CaptureScreen(_parallelConfig.Driver, _featureContext.FeatureInfo.Title);
- }
- else if (stepType == "When")
- {
- scenario.CreateNode<When>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.InnerException);
- ScreenShotHelpers.CaptureScreen(_parallelConfig.Driver, _featureContext.FeatureInfo.Title);
- }
- else if (stepType == "Then")
- {
- scenario.CreateNode<Then>(_scenarioContext.StepContext.StepInfo.Text).Fail(_scenarioContext.TestError.Message);
- ScreenShotHelpers.CaptureScreen(_parallelConfig.Driver, _featureContext.FeatureInfo.Title);
- }
- }
- }
- [BeforeScenario]
- public void Initialize()
- {
- InitializeSettings();
- Settings.ApplicationCon = Settings.ApplicationCon.DBConnect(Settings.AppConnectionString);
- //Create feature name
- featureName = extent.CreateTest<Feature>(_featureContext.FeatureInfo.Title);
- //Get scenario name
- scenario = featureName.CreateNode<Scenario>(_scenarioContext.ScenarioInfo.Title);
- }
- [AfterScenario]
- public void TestStop()
- {
- _parallelConfig.Driver.Quit();
- }
- [AfterTestRun]
- public static void TearDownReport()
- {
- //Write the report to the report directory
- extent.Flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement