java - 如何使用 java 将示例部分中的 Cucumber 数据表转换为 Map<Key,Value>

标签 java datatable cucumber

我有兴趣获得有关将示例部分中的数据表转换为 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/

相关文章:

cucumber capybara 滚动到页面底部

java - 将 getter 合并到静态方法中时遇到问题

java - 在服务器/客户端程序中发送给所有人与发送给一个人

java - 根据特定单元格值划分 Excel 工作表

c# - C#中快速匹配DataTable和String Array的方法

css - 桌面浏览器中的 primefaces 数据表重排

java - Spring - 下载 < 1 kb 小文件时出错

c# - 数据表内存泄漏

javascript - 使用 Vue、Cypress 和 Cucumber 进行测试时如何使用类?

cucumber - 运行测试时出现超时错误 Cucumber/Watir