无法使用动态对象在另一个步骤中调用步骤定义

时间:2015-12-04 11:16:09

标签: c# specflow

我正在使用specflow编写一些UI测试。

情景

Scenario: I can add multiple users
    Given I add the following users
        | FirstName | Surname | Age |
        | Tom       | Jerrum  | 21  |
        | Another   | Person  | 38  |
        | Jimmy     | Jones   | 25  |
    Then I have 3 users displayed

步骤定义

[Given(@"I add the following users")]
public void GivenIAddTheFollowingUsers(IEnumerable<dynamic> people)
{
    foreach(var person in people)
    {
        When(@"I go to the add person page");
        Then(@"I enter the details of the person", person);
        When(@"I save the new person");
        Then(@"I am taken back to the view people page");
    }
}


[Then(@"I enter the details of the person")]
public void ThenIEnterTheDetailsOfThePerson(dynamic person)
{
    AddPersonPage.EnterDetails(person);
}

尝试执行此操作时,我收到以下错误...

  

{“'TechTalk.SpecFlow.Steps.When(string,TechTalk.SpecFlow.Table)'的最佳重载方法匹配'有一些无效的参数”}

尝试呼叫Then(@"I enter the details of the person", person);时出现此错误 由于此错误,未达到步骤定义中的代码。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

解决这个问题的方法是为每个人建立一个表......

[Given(@"I add the following users")]
public void GivenIAddTheFollowingUsers(IEnumerable<dynamic> people)
{
    foreach(var person in people)
    {
        var header = new [] {"FirstName", "Surname", "Age"};
        var personTable = new Table(header);
        personTable.AddRow(person.FirstName, person.Surname, person.Age);

        When(@"I go to the add person page");
        Then(@"I enter the details of the person", personTable);
        When(@"I save the new person");
        Then(@"I am taken back to the view people page");
    }
}

这似乎有效,但我想避免为每个人建立一个新表。