cucumber - 有没有办法用黄瓜中的不同数据集一个一个地重复执行几个步骤
问题描述
考虑一个场景 第 1 步:网站中可用的过滤器很少 第 2 步:我们必须从每个过滤器中选择值 第 3 步:然后根据应用的过滤器验证显示的数据
预期的:
- 从过滤器中选择一个值
- 然后验证结果中显示的过滤值
- 再次从过滤器中选择不同的值
- 然后验证结果中显示的过滤值
我已经尝试使用数据表从过滤器中选择值,但它是一个一个地选择所有数据,并且验证仅在最后发生而不是在选择每个值之后发生所以有没有办法选择和验证然后选择和验证像这样
解决方案
您必须使用示例表而不是数据表来使用场景大纲。如果您想使用不同的值执行相同的场景,那么您需要创建一个场景大纲,并且在示例表中您需要传递与过滤器相关的数据。
这就是你可以实现的方式。
特点:
Feature: Title of your feature
I want to use this template for my feature file
Scenario Outline: Title of your scenario outline
Given I select a value from the "<filters>"
When I check for the filter in step
Then I verify the filter in step
Examples:
| filters |
| Data1 |
| Data2 |
| Data3 |
步骤定义:
boolean result = false;
String filter = null;
List<String> expectedFilters = new ArrayList<>();
{
expectedFilters.add("Data1");
expectedFilters.add("Data2");
expectedFilters.add("Data3");
}
@Given("I select a value from the {string}")
public void i_select_a_value_from_the_filters(String filter)
{
result = false;
this.filter = filter;
}
@When("I check for the filter in step")
public void i_check_for_the_filter_in_step()
{
if( this.expectedFilters.contains(this.filter))
{
result = true;
}
}
@Then("I verify the filter in step")
public void i_verify_the_filter_in_step()
{
if( result )
{
System.out.println("Validation is successful for data [ " + this.filter + " ]" );
}
else
{
System.out.println("Validation failed!");
}
}
推荐阅读
- android - 存在实施时禁用中介网络 (Android Admob)
- gnuplot - 是否可以调整 gnuplot 方框图的高度?
- typescript - NodeJS FactoryGirl:错误:“代码”列中的空值违反非空约束
- python - Python多处理一个工人动态所有工人数据的接收者数量(1:n)
- docker - Jenkins 声明式管道调用方法阶段
- amazon-web-services - 如何查找特定区域和实例类型的 AMI ID?
- postgresql - 将 bytea 转换回 varchar
- java - 如何使用 java 代码设置基本身份验证(用户名和密码)
- regex - sed 和正则表达式规则替换文本
- bixby - Bixby:免提导航列表不适用于单个项目