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"
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"
Share
Improve this question
asked 21 hours ago
Bug RaptorBug Raptor
2716 silver badges16 bronze badges
1 Answer
Reset to default 0Here is how to do it:
- 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.