java - 如何修复“列表类型不是通用的;它不能用参数参数化“黄瓜硒JAVA中的错误
问题描述
我尝试使用数据表并实现我的函数来从这个 Cucumber 数据表中获取值,我使用了 List< List< String >> 但它不起作用!
public void myfunction(DataTable dt) throws Throwable {
列表> 列表 = dt.asList(String.class);
driver.findElement(By.id("name")).sendKeys(list.get(0).get(0));
driver.findElement(By.id("age")).sendKeys(list.get(0).get(1));
driver.findElement(By.id("nphone")).sendKeys(list.get(1).get(0));
driver.findElement(By.id("address")).sendKeys(list.get(1).get(1));}
解决方案
使用Header我们可以以非常干净和精确的方式实现数据表,并且考虑到数据表如下所示 -
And fill up the first & last name form with the following data
| First Name | Last Name |
| Tom | Adam |
| Hyden | Pointing |
public void myfunction(DataTable table) throws Throwable {
List<Map<String, String>> list = table.asMaps(String.class,String.class);
driver.findElement(By.id("name")).sendKeys(list.get(0).get("First Name"));
driver.findElement(By.id("age")).sendKeys(list.get(0).get("Last Name"));
driver.findElement(By.id("nphone")).sendKeys(list.get(1).get("First Name"));
driver.findElement(By.id("address")).sendKeys(list.get(1).get("Last Name"));
}
实施规则 -下面是 2 个片段,最有趣的片段是第一个片段,它表明该方法的参数是 DataTable 数据表。该片段建议您应该将 DataTable dataTable 参数替换为以下任何一项:
- List<E>
- List<List<E>>
- List<Map<K,V>>
- Map<K,V>
- Map<K, List<V>>
它还告诉我们每种类型 E、K、V 必须是以下任何一种类型:
- 细绳
- 整数
- 漂浮,
- 双倍的
- 字节
- 短的
- 长
- 大整数
- 大十进制
推荐阅读
- angular - 路由器模块中的角度路由url修改
- javascript - 如何在特定索引的中间缩放折线图(HTML5-canvas)?
- google-apps-script - Google Apps 脚本。如何从左侧获取单元格和导航器ov
- reactjs - React Styled-components TypeScript 使用基础样式上的道具扩展样式得到 TS2769 错误
- mobile - 如何在antd上传上使用捕获?
- linux-kernel - Linux 内核源代码中的字符设备主编号范围
- mongodb - Typeorm、MongoDB 和 TypeGraphQL - 填充 - 查找
- linux - 在未分配的磁盘空间上写入数据并验证写入的数据量
- angularjs - 使用带有模板 url 的 ui 路由器时获得“转换拒绝”
- ios - 我可以将`willConnectTo`用作iOS中单窗口应用程序的`didFinishLaunching`吗?