[BeforeTestRun]
public static void InitializeReport()
{
var configuration = ConfigurationReader.GetConfigurationData();
//Initialize Extent report before test starts
string filename = DateTime.Now.ToString().Replace("/", "_").Replace(":", "_").Replace(" ", "_") + ".html";
htmlReporter = new ExtentHtmlReporter(configuration.ReportLocation + "ParcelMotel_" + filename);
htmlReporter.LoadConfig(configuration.ExtentXmlLocation + "extent-config.xml");
htmlReporter.Configuration().DocumentTitle = "Parcel Motel Regression Test Report";
htmlReporter.Configuration().Theme = Theme.Dark;
htmlReporter.Configuration().ReportName = "Regression Testing Report ";
extent = new ExtentReports();
htmlReporter.Configuration().ChartVisibilityOnOpen = true;
extent.AttachReporter(htmlReporter);
extent.AddSystemInfo("OS", "Windows 7");
extent.AddSystemInfo("Host Name", "Ina Prisacari");
extent.AddSystemInfo("Environment info", "Parcel Motel - Dev");
extent.AddSystemInfo("Use Name", "Swati Gupta");
extent.AddSystemInfo("Selenium Version", "3.9.1");
extent.AddSystemInfo("Parcel Motel - Dev Site Url", configuration.RegistrationDevUrl);
extent.AttachReporter(htmlReporter);
}
[AfterTestRun]
public static void TearDownReport()
{
//Flush report once test completes
extent.Flush();
}
[BeforeFeature]
public static void BeforeFeature()
{
//Create dynamic feature name
featureName = extent.CreateTest<Feature>(FeatureContext.Current.FeatureInfo.Title);
}
[AfterStep]
public void InsertReportiMOngSteps()
{
var stepType = ScenarioStepContext.Current.StepInfo.StepDefinitionType.ToString();
var status = TestContext.CurrentContext.Result.Outcome.Status;
var stackTrace = "" + TestContext.CurrentContext.Result.StackTrace + "";
var errorMessage = TestContext.CurrentContext.Result.Message;
if (ScenarioContext.Current.TestError == null)
{
if (stepType == "Given")
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text);
else if (stepType == "When")
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text);
else if (stepType == "Then")
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text);
else if (stepType == "And")
scenario.CreateNode<And>(ScenarioStepContext.Current.StepInfo.Text);
}
else if (ScenarioContext.Current.TestError != null)
{
if (stepType == "Given")
{
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.InnerException);
}
else if (stepType == "When")
{
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.InnerException);
}
else if (stepType == "Then")
{
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
}
}
//Pending Status
if (ScenarioContext.Current.ScenarioExecutionStatus.ToString() == "StepDefinitionPending")
{
if (stepType == "Given")
{
scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
else if (stepType == "When")
{
scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
else if (stepType == "Then")
{
scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Skip("Step Definition Pending");
}
}
ITakeScreenShot();
}
[BeforeScenario]
public void Initialize()
{
SelectBrowser(BrowserType.Chrome);
//Create dynamic scenario name
scenario = featureName.CreateNode<Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
}