我有兴趣获得有关将示例部分中的数据表转换为 map 的反馈
Feature: Data Table Reader
Scenario Outline: User Login scenario
Given User is at the login page of the application
When User login with the following <username> and <password> with data in excel
Examples:
| username | password |
| value_1 | value_1 |
| value_2 | value_2 |
| value_3 | value_3 |
我们必须将示例中的上述数据表转换为 map 。 map 应存储为 , , ,, < 密码: value_2>, < 密码: value_3>
最佳答案
您如何获取示例数据?示例中的每一行不是都刚刚传递到该步骤中吗?
如果您有一个带有数据表的步骤
Given the following usernames and passwords
| username | password |
| value_1 | value_1 |
| value_2 | value_2 |
| value_3 | value_3 |
您可以直接以 map 列表的形式访问该表。列表中的每一项代表数据表的一行,该数据表以映射的形式提供,其中键是列标题,值是数据表中的值。
@Given("^the following usernames and passwords$")
public void the_following_usernames_and_passwords(List<Map<String, String>> dataTable) {
for (Map<String, String> dataRow : dataTable) {
String username = dataRow.get("username");
String password = dataRow.get("password");
// ... do something ...
}
}
关于java - 如何使用 java 将示例部分中的 Cucumber 数据表转换为 Map<Key,Value>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53751940/