java - 如何在java代码中获取cucumber中具有多个管道的步骤的参数?

标签 java selenium cucumber gherkin

我的功能文件中有以下针对场景的步骤。

Given my_first_step

And my_second_step
  | Themes          | one | three |

  | Service Windows | two | four  |

And my_third_step

  | Create Apps |

  | Config      |

我们可以在java代码中以列表的形式获取'my_third_step'的参数,如下所示

public void my_third_step(List listOfItems) {}

但是如何获取 'my_second_step' 中的参数? 我需要在java代码中获取一行作为元素数组。我怎样才能做到这一点?

最佳答案

您必须传递一个对象列表,您的对象将如下所示

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    |

我希望这会有所帮助。

关于java - 如何在java代码中获取cucumber中具有多个管道的步骤的参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56344866/

相关文章:

java - 为什么我在 Java 中遇到 stackoverflow?

java - Thymeleaf:编辑表单的对象列表

java - 如何根据表中同一行上其他元素的文本值获取元素的文本?

javascript - Protractor 中的 setTimeout 替代方案

java - TestNG 中的非静态驱动程序和屏幕截图监听器

java - Junit Runner 类无法找到步骤定义文件

ruby - 捕获小 cucumber 表中的尾随空格

java - 结果集 getString 抛出 ArrayIndexOutOfBoundsException

java - 在 Weblogic 上部署 OpenID Azure AD java Web 应用程序时出现 NoClassDefFoundError

java - 如何使用 jar 运行 cucumber ?