I just starting to work with SpecFlow and really like the tool. However I am running across some issues in relation to example data inputs into the Scenario Outlines.
Just wondering if what I am facing is normal or whether there is a trick to it.
I am using C# Visual Studio 2013 and writing an MVC App using the underscore style of step definition. I have also tried the regular expression style but still get similar issues.
So the issue is I am providing username, password etc as parameters and including sample data in my Examples. It appears that the following occurs: -
I have to put "" around the parameters when 1st generating the scenario, otherwise it does not get picked up as a parameter at all. However when passing data in from the examples I get a "/" at the end of the data passed in. When I go back to the scenario I then remove the "" around the parameter. This is a little frustrating but if that is the best way to handle it I can live with that. Just wondering if anyone has any advice on this point.
The next issue is related to the data itself. It appears if I have any characters such as @ or & etc in my data, then it splits that data at that point and feeds it to the next parameter so I get incorrect data being fed through.
I have included my code below - if anyone has any suggestions or resources to look at that would be appreciated.
Feature File Feature: AccountRegistration In order to use Mojito services in my organisation As a guest user I want to create an account with administration privelages
Scenario Outline: Register with valid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will be logged in as <username>
And my account will be assigned the role of <role>
Examples:
| email | organisation | password | passwordConfirmation | username | role |
| usernamea | Bytes | password1 | password1 | usernamea | Admin |
| usernameb | Bytes | password2 | password2 | usernameb | Admin |
| usernamec | Bytes | password3 | password3 | usernamec | Admin |
| usernamed | Bytes | password4 | password4 | usernamed | Admin |
| usernamee | Bytes | password5 | password5 | usernamee | Admin |
Scenario Outline: Register with invalid details
Given I am on the registration page
And I have completed the form with <email> <organisation> <password> and <passwordConfirmation>
When I have clicked on the register button
Then I will get an error message
Examples:
| email | organisation | password | passwordConfirmation |
| [email protected] | Bytes | 1LTIuta&Sc | wrongpassword |
| [email protected] | Bytes | 1LTIuta&Sc | 1LTIuta&Sc |
| [email protected] | No Organisation | 1LTIuta&Sc | 1LTIuta&Sc |
Steps Generated File
[Binding]
public class AccountRegistrationSteps
{
[Given]
public void Given_I_am_on_the_registration_page()
{
ScenarioContext.Current.Pending();
}
[Given]
public void Given_I_have_completed_the_form_with_usernamea_Bytes_password_P0_and_password_P1(int p0, int p1)
{
ScenarioContext.Current.Pending();
}
[Given]
public void Given_I_have_completed_the_form_with_Jonesa_mojito_com_Bytes_P0_LTIuta_Sc_and_wrongpassword(int p0)
{
ScenarioContext.Current.Pending();
}
[When]
public void When_I_have_clicked_on_the_register_button()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_I_will_be_logged_in_as_usernamea()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_my_account_will_be_assigned_the_role_of_Admin()
{
ScenarioContext.Current.Pending();
}
[Then]
public void Then_I_will_get_an_error_message()
{
ScenarioContext.Current.Pending();
}
}
Scenario Outline - This is used to run the same scenario for 2 or more different sets of test data. E.g. In our scenario, if you want to register another user you can data drive the same scenario twice. Examples – All scenario outlines have to be followed with the Examples section.
Scenario outline basically replaces variable/keywords with the value from the table. Each row in the table is considered to be a scenario. Let's continue with the same example of Facebook login feature. So far we have been executing one scenario: Upon providing the correct user name, login is successful.
A Scenario Outline must contain an Examples (or Scenarios ) section. Its steps are interpreted as a template which is never directly run. Instead, the Scenario Outline is run once for each row in the Examples section beneath it (not counting the first header row).
Scenario outline is exactly similar to the scenario structure, but the only difference is the provision of multiple inputs. In order to use scenario outlines, we do not need any smart idea, we just need to copy the same steps and re-execute the code.
RESOLVED - It was not an issue with the use of characters such as @ or &. It was actually using commas in my Given Statement. I found if I used 'and' it works. So to get it working the statement had to be written as below: -
SOLUTION
Write statement as
Given I have completed the form with <email> and <organisation> and <password> and <passwordConfirmation>
Modify statement to put single quotes around paramaters that need to be strings
Given I have completed the form with '<email>' and '<organisation>' and '<password>' and '<passwordConfirmation>'
Generation Step Definitions and then change statement back to exclude single quotes
Given I have completed the form with <email> and <organisation> and <password> and <passwordConfirmation>
A bit of mucking around but it gets the correct results. Hopefully in the future SpecFlow will be updated to handle paramaters as strings as default.
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