将场景大纲 'Example' table 解析为对象

Parsing Scenario outline 'Example' table as object

我一直在尝试弄清楚如何在不明确使用步骤名称的情况下将场景大纲示例解析为(自定义)对象。

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 |

我现在正在尝试了解如何将示例行解析为自定义约会对象

我一直在查看带有 table 的 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

这是约会class

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

谁能指出正确的方向如何将示例行解析为约会对象?

您没有向 Given 函数传递任何参数,这就是它抛出异常的原因。您可以像这样传递 table:

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 |

给定步骤中的尖括号是参数。在本例中放置在 table 内。参数取自示例中的 table,因为您使用的是场景大纲。