Reputation: 369
How do I programmatically in c# get a list and count of all specflow/specrun test scenarios or tests during a test run (aka. multiple scenarios selected), and iterate through their test results so that I may generate my own status report and pass/fail chart. I would like to create a chart that provides a number of failed versus passed tests within a test run. I want to create my own custom report, despite knowing I could reuse specflow's preset report for this.
Upvotes: 0
Views: 1654
Reputation: 16
In case, if we are selecting one or two scenarios and run selected tests if we wanted to know the total number of tests run for creating any custom reports with the scenario names and status.. below method will help you out.. you can add them to the list and display it in the UI as preferred
int executedTests = 0;
List<string> scenarioNames = new List<string>();
List<string> scenarioStatuses = new List<string>();
[AfterScenario]
public void ScenarioCounter()
{
CaptureScenarioInformation();
}
public void CaptureScenarioInformation()
{
scenarioName = ScenarioContext.Current.ScenarioInfo.Title;
PropertyInfo pInfo = typeof(ScenarioContext).GetProperty("TestStatus", BindingFlags.Instance | BindingFlags.NonPublic);
MethodInfo getter = pInfo.GetGetMethod(nonPublic: true);
scenarioStatus = getter.Invoke(ScenarioContext.Current, null).ToString();
scenarioNames.Add(scenarioName);
scenarioStatuses.Add(scenarioStatus);
executedTests++;
}
Upvotes: 0