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

本文关键字:另一个 定义 调用 对象 动态 | 更新日期: 2023-09-27 18:25:35

我正在使用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);时发生此错误由于此错误,无法访问步骤定义中的代码。

我该如何解决这个问题?

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

解决方案是为每个人建立一个表。。。

[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");
    }
}

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