admin管理员组文章数量:1344944
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.
本文标签:
版权声明:本文标题:c# - How to write the Then clause in a SpecFlow Scenario addressing a method with a Table parameter defining a set of values - S 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743767593a2535527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论