我尝试使用数据表并实现我的函数来获取 来自此 Cucumber 数据表的值,我使用了 List< List< String >> 但 它不起作用!
public void myfunction(DataTable dt) throws Throwable {
List> list = 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));}
最佳答案
使用标题,我们可以以更加干净和精确的方式实现数据表,并考虑数据表如下所示 -
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 dataTable 参数替换为以下任意一项:
- List<E>
- List<List<E>>
- List<Map<K,V>>
- Map<K,V>
- Map<K, List<V>>
它还告诉我们每种类型 E、K、V 必须属于以下任何类型:
- 字符串
- 整数
- float ,
- 双
- 字节
- 简短
- 长
- 大整数
- 大十进制
关于java - 如何修复 cucumber Selenium JAVA中的 "The type List is not generic; it cannot be parameterized with arguments <String>"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55793559/