Jeroen Lamberts
Jeroen Lamberts

Reputation: 301

Parsing Scenario outline 'Example' table as object

I have been trying to figure out how to parse Scenario outline examples as a (custom) object without explicitly using the in the step name.

Scenario Outline: Customer makes an appointment

Given The user enters details on the page
When The user submits the page
Then The appointment details are shown.

Examples:
| Reason | Firstname | Lastname | Email            |
| A      | John      | Doe      | johndoe@mail.com |
| B      | Jane      | Doe      | janedoe@mail.com |

I am now trying to find out how to parse the example row as a custom Appointment object

I have been looking at CreateInstance with a table, but this doesnt seem to be working

 [Given(@"The user enters details on the page")]
 public void EnterDetails(Table table)
 {
     var appointment = table.CreateInstance<Appointment>();

     driver.FindElement(By.Id("Firstname")).SendKeys(appointment.Firstname);    
 }

Error i get when running this

Message: TechTalk.SpecFlow.BindingException : Parameter count mismatch! The binding method EnterDetails(Table)' should have 0 parameters

This is the appointment class

public class Appointment
{
    public AppointmentReason Reason { get; set; }
    public string Firstnam { get; set; }
    public string Lastname { get; set; }
    public string Email { get; set; }
}

Who can point me in the right direction how to parse the Example rows as Appointment objects?

Upvotes: 0

Views: 204

Answers (1)

Mika Sundland
Mika Sundland

Reputation: 18979

You are not passing in any arguments to the Given function, which is why it throws an exception. You can pass in a table like this:

Scenario Outline: Customer makes an appointment

Given The user enters details on the page
    | Reason   | Firstname   | Lastname   | Email   |
    | <Reason> | <Firstname> | <Lastname> | <Email> |
When The user submits the page
Then The appointment details are shown.

Examples:
| Reason | Firstname | Lastname | Email            |
| A      | John      | Doe      | johndoe@mail.com |
| B      | Jane      | Doe      | janedoe@mail.com |

Angle brackets inside the given step are parameters. In this case placed within a table. The arguments are taken from the table in examples, because you are using scenario outline.

Upvotes: 4

Related Questions