0

Considering the following Then verifying method already implemented:

/// <summary> /// Verifies the elements of a <see cref="ComboBox" />. /// </summary> /// <param name="automationId"> /// The automation Id of the <see cref="ComboBox" />. /// </param> /// <param name="values"> /// The expected values for the <see cref="ComboBox" />. /// </param> [Then(@"the combobox with id ([^ ""]+) contained the following elements")] public void VerifyComboboxContainsValues(AutomationIdString automationId, Table values) 

I'm searching how to correctly write the corresponding scenario in a feature file to define the expected ComboBox values to be passed in the values Table:

So something like that:

Scenario: xxx Given xxx Then the combobox with id "SomeAutomationId" contains the following elements "Value_1", "Value_2"... "Value_n" 

1 Answer 1

1

Here is how to do it:

  1. Define the table in your feature file. Tables are represented by rows and columns in a pipe-delimited (|) format. SpecFlow can automatically identify that a table is being used because it looks like this:
Then the combobox with id "SomeAutomationId" contains the following elements: | values | | Value_1 | | Value_2 | | ... | | Value_n | 

2. Define the step definition. You can pass in the values parameter of type Table as you have done and use it like this:

[Then(@"the combobox with id ([^ ""]+) contained the following elements:")] public void ComboboxContainsValues(AutomationIdString automationId, Table values) { _driver.ValidateComboBoxValues(automationId, values).Should().Be(true); } 

3. Define your validation logic. The idea is I can extract the values information from the rows because I made it a header in my feature file. Then once you have that information you can perform the assertion you need.

public bool ValidateComboBoxValues(AutomationIdString automationId, Table table) { var expectedValues = table.Rows.Select(row => row["values"]).ToList(); //perform assertion against ComboBox values return true; } 

One thing to note, is that I am a bit confused that in your feature file you have passed in the id like "SomeAutomationId" implying you are trying to pass in a string but in your step definition you have referred to it as type AutomationIdString. I would be mindful of this. If you are trying to pass in an object, you cannot do it directly like this in SpecFlow without a parameter transformation. If you are using a string, I would change the type to string in your step definition, and you should be fine.

Sign up to request clarification or add additional context in comments.

2 Comments

TY for your answer Alex. Concerning your note: my codedescription was incomplete. There is a [Binding] SpecFlowTransformationService class transforming the argument of type AutomatedIdString to string. Actually, the AutomationIdString class contains a private static field associating a key to each AutomationId private static Dictionary<string, string> automationIds; So my Then step should be written like this Then the combobox with id SomeAutomationIdKey contained the following elements: | values | | Value_1 | | Value_2 | | ... | | Value_n |
@BugRaptor - please edit your question to include this information.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.