I use Specflow for test automation and I need to test that user can register.
The problem is that there are a lot of fields for registering, around 30.
My script looks something like this:
And user is adding <value1> in the TextBox1 field
And user is adding <value2> in the TextBox2 field
...
And user is adding <value3> in the TextBox3 field
Outline scenario
<value1> <value2> <value3>
Is this a good approach in Specflow or should I compact all in something like this:
And the user registers by filling in all the fields
Avoid phrasing your steps with user interface terminology. Instead focus on the business process of registering a user. For large forms, I find vertical data tables in a step to be very clear and concise. You haven't included much information about the user registration process, so I'll make something up and maybe you can extrapolate to your specific application.
When the user registers with the following information:
| Field | Value |
| First Name | ... |
| Last Name | ... |
| Username | ... |
| Address | ... |
| City | ... |
| State | ... |
The complexity of filling out the large form gets handled in the step definition, and perhaps a "page model" class that knows how to interact with the registration page. Use the Table.CreateInstance<T> extension method to map the table
parameter to a strongly typed object in C#.
[When(@"the user registers with the following information:")]
public void WhenTheUserRegistersWithTheFollowingInformation(Table table)
{
var data = table.CreateInstance<RegisterUserDataRow>();
var registrationPage = new RegistrationPage(driver); // pass Selenium driver object
registrationPage.RegisterNewUser(username: data.Username,
firstName: data.FirstName,
lastName: data.LastName,
address: data.Address,
city: data.City,
state: data.State);
}
And the page model class:
public class RegistrationPage
{
public void RegisterNewUser(string username, string firstName, string lastName, string address, string city, string state)
{
UsernameField.SendKeys(username);
FirstNameField.SendKeys(firstName);
...
RegisterButton.Click();
}
}