0
votes

I am using specflow and I have a rather large table in my examples:

it has around 14 fields.

is there a better way of passing all of those filds into a method that is item1 and item2 and item4

I can see that there is a create set method, but this doesn't seem to cater for examples, and only in step....well steps.

is there a way to pass the data in an object rather than sending 14 strings?

Hope that makes sense.

Ta,

Steve

** Edit ** adding an example Here is the headers for my exmaple file | propLocation | locPropToBuy | propertyType | newBuild | appsLiveProprty | ownershipType | purchPrice | totLoanAmount | intOnlyAmount | prefLoanTermYrs | prefLoanTermMths |

the method generated for this will look like this:

[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)

Although I will eventually change the coded values to (.*) etc.

It would be easier for me if I could just pass an object or a list of all the values rather than long instances of strings.

1
Could you please provide an example of your steps, tables, examples and bindings? I am not sure what do you mean. Thanks! - Andreas Willich
I've updated it a bit. Does that make sense? - thegoatboy

1 Answers

1
votes

Take a look at Specflow tables

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

and so on and so on

Create a new class with PropertyLoanData and then interpret the table

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