【问题标题】:How do i get the Specflow scenario outline example data to a table如何将 Specflow 场景大纲示例数据获取到表中
【发布时间】:2021-05-09 14:36:04
【问题描述】:

有什么方法可以获取场景上下文大纲示例值,我的意思是表中的所有值

Scenario Outline: Create a Matter

Given I enter  "< parameter1 >"
Then I enter "<parameter2>"
Then I enter "<parameter3>"
Then I enter "<parameter4>"
Then review all the parameters entered above in this final step

Examples:
| parameter1   | Paramter2|Parameter3|Parameter4|....|parameter14|
| value        |value2    |value3    |value4    |....|value14|

在上面的场景中,有没有办法将步骤 4 中的所有示例值获取到表中 我知道我可以在每个步骤中设置 ScenarioContext.Current[parameter1] = value 在我的情况下,我有 14 个参数用于每个步骤,但在最后一步我需要使用所有 14 个参数 有什么方法可以将示例值放入表中。

我不想闯入较小的场景 如下所示

Scenario: breaking in to smaller chunks    
Given I enter  the following
| parameter1   | Paramter2|
| value        |value2|

【问题讨论】:

  • 您可以将场景发布为文本吗?然后我可以轻松地将其调整为我认为您想要的。
  • 我已经完成了@AndreasWillich

标签: selenium specflow


【解决方案1】:

这是我使用的可能会有所帮助的东西。 Andreas 是这方面的专家,他可能有更好的主意。由于您的格式不太理想,因此我使用了基本场景。

将其更改为“场景”并删除“场景大纲”。

该功能如下所示:

Scenario: Validate Shipping Fees
When the user enters the State then we can verify the city and shipping fee

| City                      | State         | Shipping |
| Boulder                   | Colorado      | 6.00  |
| Houston                   | Texas         | 8.00  |

添加表格。

public class ShippingTable
{
    public string City { get; set; }
    public string State { get; set; }
    public string Shipping { get; set; }

}

然后在你的步骤:

     [When(@"the user enters the State then we can verify the city and shipping fee")]
    public void WhenTheUserEnterTheStateThenWeCanVerifyTheCityAndShippingFee(Table table)
    {

        var CityState = table.CreateSet<ShippingTable>();
        foreach (var row in CityState)
        {
             
            try
            {
                Pages.CheckoutPage.SelectState(row.State);
                Pages.CheckoutPage.SelectCity(row.City);
                var recdPrice = Pages.CheckoutPage.GetShippingPrice;
                Assert.AreEqual(row.shipping, recdPrice);

            }
            catch (Exception)
            {
                throw new Exception("This is jacked up");
            }

         }

    }

【讨论】:

  • Thanks@Dazed 但我将在每个步骤中有一个包含 3 或 4 个参数的表格。就像在您的示例中一样,我将在一个场景中进行城市国家运输......我有 4 到 5 个场景在我的案例&在最后一步中,我需要上述 4 到 5 个场景中的信息
  • @user4391664 您需要一步完成所有示例的参数吗?您只能访问当前示例的参数。
  • 是的,在最后一步我需要所有示例的参数@AndreasWillich
猜你喜欢
  • 2014-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-29
  • 1970-01-01
  • 2016-01-25
  • 2017-03-28
相关资源
最近更新 更多