【问题标题】:Specflow scenario outline examples table - to object?Specflow 场景大纲示例表 - 反对?
【发布时间】:2019-02-04 16:17:00
【问题描述】:

我正在使用 specflow,并且在我的示例中有一个相当大的表:

它有大约 14 个字段。

有没有更好的方法将所有这些字段传递到 item1 和 item2 和 item4 的方法中

我可以看到有一个create set方法,但这似乎不适合示例,并且仅在步骤中......以及步骤。

有没有办法在对象中传递数据而不是发送 14 个字符串?

希望这是有道理的。

塔,

史蒂夫

** 编辑 ** 添加示例 这是我的示例文件的标题 | propLocation | locPropToBuy | propertyType | newBuild | appsLiveProprty | ownershipType | purchPrice | totLoanAmount | intOnlyAmount | prefLoanTermYrs | prefLoanTermMths |

为此生成的方法如下所示:

[When(@"the user provides input for the Property and Loan Requirements Section (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*) and (.*)")] public void WhenTheUserProvidesInputForThePropertyAndLoanRequirementsSectionEnglandAndYesAndTerracedHouseAndYesAndYesAndStandardAndAndAndAndAndAndAndAndSAnd(string propLocation, string locPropToBuy, string propertyType, string newBuild, string legalOwnership, string ownershipType, string equityShreScheme, string purchPrice, string fullMarketVal, string termShareLoanYrs, string termShareLoanMths, string totLoanAmount, string intOnlyAmount, string prefLoanTermYrs, string prefLoanTermMths)

虽然我最终会将编码值更改为 (.*) 等。

如果我可以只传递一个对象或所有值的列表而不是长字符串实例,那对我来说会更容易。

【问题讨论】:

  • 能否提供您的步骤、表格、示例和绑定的示例?我不确定你是什么意思。谢谢!
  • 我已经更新了一点。这有意义吗?

标签: specflow


【解决方案1】:

查看 Specflow 表

When the user provides input for the Property and Loan Requirements Section
| Key         | Value      |
| propLocation| NYC        |
| locPropToBuy| House123   |
| propertyType| House      |
| newBuild    | Nope       |

等等等等

使用 PropertyLoanData 创建一个新类,然后解释该表

    public class PropertyLoanData
    {
      public string propLocation { get; set; }
      public string locPropToBuy { get; set; }
      public string propertyType { get; set; }
      public string newBuild     { get; set; }
    }

.

   [When(@"the user provides input for the Property and Loan Requirements Section
    public void WhenUserprovidesinputforPropertyAndLoanSection(Table table)
    {
        var proploandata = table.CreateInstance<PropertyLoanData>();
        driver.FindElement(By.Id("propLocation")).SendKeys(proploandata.propLocation);
        driver.FindElement(By.Id("locPropToBuy")).SendKeys(proploandata.locPropToBuy);
        driver.FindElement(By.Id("propertyType")).SendKeys(proploandata.propertyType);
        driver.FindElement(By.Id("newBuild")).SendKeys(proploandata.newBuild);
    }

【讨论】:

    猜你喜欢
    • 2014-10-12
    • 2021-04-29
    • 2016-01-25
    • 2017-03-28
    • 2021-05-09
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多