Specflow方案大纲示例表-对象?

时间:2019-02-04 16:17:00

标签: specflow

我正在使用specflow,示例中有一个很大的表:

它有大约14个字段。

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

我可以看到有一个create set方法,但这似乎并不能满足示例的需要,只是一步一步...好吧。

是否有一种方法可以在对象中传递数据,而不是发送14个字符串?

希望如此。

Ta

史蒂夫

**编辑**添加示例 这是我的exmaple文件的标题 | 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)

尽管我最终会将编码值更改为(。*)等。

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

1 个答案:

答案 0 :(得分: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);
    }