我一直在尝试找出如何将场景概述示例解析为(自定义)对象,而无需在步骤名称中显式使用。
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 |
我现在正试图找出如何将示例行解析为自定义约会对象
我一直在用表查看CreateInstance,但这似乎不起作用
[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);
}
运行此程序时出现错误
Message: TechTalk.SpecFlow.BindingException : Parameter count mismatch! The binding method EnterDetails(Table)' should have 0 parameters
这是约会课程
public class Appointment
{
public AppointmentReason Reason { get; set; }
public string Firstnam { get; set; }
public string Lastname { get; set; }
public string Email { get; set; }
}
谁能指出正确的方向,如何将“示例”行解析为约会对象?
答案 0 :(得分:3)
您没有将任何参数传递给Given函数,这就是它引发异常的原因。您可以像这样传递表格:
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 |
给定步骤内的尖括号是参数。在这种情况下放在桌子内。参数是从示例中的表中获取的,因为您使用的是方案大纲。