如何修复“类型列表不是通用的;它不能用参数参数化 “黄瓜硒JAVA的错误

问题描述 投票:0回答:1

我试图使用数据表并实现我的函数来从这个Cucumber数据表中获取值,我使用List <List <String >>但它不起作用!

public void myfunction(DataTable dt)抛出Throwable {

List> list = dt.asList(String.class);

driver.findElement(By.id( “名称”))的SendKeys(list.get(0)获得(0))。 。driver.findElement(By.id( “年龄”))的SendKeys(list.get(0)获得(1)); 。driver.findElement(By.id( “nphone”))的SendKeys(list.get(1)获得(0)); 。driver.findElement(By.id( “地址”))的SendKeys(list.get(1)获得(1));

}

java eclipse drop-down-menu selenium-chromedriver cucumber-jvm
1个回答
2
投票

使用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 dataTable参数:

 - List<E>
 - List<List<E>>
 - List<Map<K,V>>
 - Map<K,V>
 - Map<K, List<V>>

它还告诉我们每种类型,E,K,V必须是以下任何类型:

  • 整数
  • 浮动,
  • 字节
  • long
  • 的BigInteger
  • BigDecimal的
© www.soinside.com 2019 - 2024. All rights reserved.