SpecFlow doesn't support such functionality.
One choice related to reading examples from file is to use SpecFlow+ Excel and read data from excel file.
Load data for Scenario Context from CSV file
-
21-07-2023 - |
Question
I use SpecFlow with Coded UI to create automated functional tests for a WPF application.
I would like to create a Scenario Outline
which loads Examples
from a CSV
file.
Scenario:
Scenario Outline: Demo_01
When I press Login button
When I have entered [<Username>] and [<Password>]
When I press OK button
Then I should be logged in as [<Username>]
Examples:
| Username | Password |
| user1 | pass1 |
Step Definition:
[When(@"I have entered \[(.*)] and \[(.*)]")]
public void WhenIHaveEnteredLoginData(string username, string password)
{
UILoader.Main.EnterUsername(username);
UILoader.Main.EnterPassword(password);
}
UIMap class (MainUIMap.cs
):
public void EnterUsername(string username)
{
WpfEdit uIUsername = this.UISoftwareWindow.UILoginView.UIUsername;
uIUsername.Text = username;
}
public void EnterPassword(string password)
{
WpfEdit uIPassword = this.UISoftwareWindow.UILoginView.UIPassword;
Keyboard.SendKeys(uIPassword, password, true);
}
It is possible to load the Examples
from a CSV
file? If yes, how (please provide code snippets)?
Thanks,
P.S.: The above presented scenario is for presentation purpose. I have some scenarios which should be executed with 500+ test data (which means 500+ Examples
rows in Scenario Outline
). I don't really want to ruin the visibility of my feature files so I would like to ask for your help.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow