I have the following test, using Specflow, Selenium WebDriver and C#:
Scenario Outline: Verify query result
Given I'm logged in
When I enter "<query>"
Then I should see the correct result
Examples:
| query |
| Query1 |
| Query2 |
| Query3 |
After each scenario I save a screenshot to a file which is named based on the ScenarioContext.Current.ScenarioInfo.Title. However, I can't find a good way to differentiate between the iterations, so the screenshots get overwritten. I could add a column in the Examples table, but I want a more generic solution...
Is there a way to know which iteration is being executed?
In your When step definition you could record the current query in ScenarioContext.Current e.g.
[When(@"I enter (.*)")]
public void WhenIEnter(string query)
{
ScenarioContext.Current["query"] = query;
}
Then in your AfterScenario step you could retrieve this value to identify which Example iteration just run e.g.
[AfterScenario]
void SaveScreenShot()
{
var queryJustRun = ScenarioContext.Current["query"];
// You could subsequently append queryJustRun to the screenshot filename to
// differentiate between the iterations
//
// e.g. var screenShotFileName = String.Format("{0}_{1}.jpg",
// ScenarioContext.Current.ScenarioInfo.Title,
// queryJustRun );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With