如何为Java代码获取黄瓜中具有多个管道的步骤的参数?

时间:2019-05-28 14:50:19

标签: java selenium cucumber gherkin

我的方案的特征文件中包含以下步骤。

const A = (a)=>{
  const b = (b)=>{
    console.log('A:',a)
    console.log('B:',b)
  }
  b(2);
}
a('1');
//output will be:
// A:1
// B:2

我们可以在Java代码中以列表的形式获取如下所示的“ my_third_step”参数

public void my_third_step(List listOfItems){}

但是如何在“ my_second_step”中获取参数? 我需要获取一行作为java代码中元素的数组。我该怎么办?

2 个答案:

答案 0 :(得分:1)

您必须传递对象列表,您的对象看起来像

public class MyObject {
    private Integer themes;
    private Integer service;

    public Integer getThemes() {
       return this.themes;
    }

    public void setThemes(Integer themes) {
       this.themes = themes;
    }

    public Integer getService() {
       return this.service;
    }

    public void setService(Integer service) {
       this.service = service;
    }
}

然后,您可以将List<MyObject>传递给该方法。

public void my_second_step(List<MyObject>) {
...
}

在功能文件中更改定义,如下所示:

And my_second_step
  | Themes          | Service |
  | one             | two     |
  | three           | four    |

我希望这会有所帮助。

答案 1 :(得分:0)

使用 Header ,我们可以以非常精确的方式实现数据表,并考虑到数据表如下图所示-

And my_second_step
    | Heading_1        | Heading_2 | Heading_3 | 
    |  Themes          |    one    | three     |
    |  Service Windows |    two    | four      |

public void my_second_step(DataTable table) throws Throwable {

List<Map<String, String>> list = table.asMaps(String.class,String.class); 

System.out.println(list.get(0).get("Heading_1") + " : " + list.get(1).get("Heading_1"));
System.out.println(list.get(0).get("Heading_2") + " : " + list.get(1).get("Heading_2"));
System.out.println(list.get(0).get("Heading_3") + " : " + list.get(1).get("Heading_3"));

}