【问题标题】:Parsing Scenario outline 'Example' table as object将场景大纲“示例”表解析为对象
【发布时间】:2019-04-10 15:21:35
【问题描述】:

我一直在试图弄清楚如何将场景大纲示例解析为(自定义)对象,而无需在步骤名称中显式使用。

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; }
}

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

【问题讨论】:

    标签: c# specflow


    【解决方案1】:

    您没有将任何参数传递给 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 |
    

    给定步骤中的尖括号是参数。在这种情况下放置在一个表内。参数取自示例中的表格,因为您使用的是场景大纲。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 1970-01-01
      相关资源
      最近更新 更多