这是我写的一个 Demo
feature 文件

Feature: Demo1

  @Smoke1
  Scenario Outline: demo Test
    Given go to "<url>"
    And print person
    Examples:
      | url                   |
      | https://www.baidu.com |
      | https://www.sina.com  |
      | https://www.qq.com    |

步骤定义类

public class MyStepdefs {

    Person1 person1 = new Person1();

    @Given("^go to \"([^\"]*)\"$")
    public void goTo(String arg0) {
        person1.setName(arg0);
        System.out.println(arg0);
    }

    @And("^print person$")
    public void printPerson() {
        String name = person1.getName();
        System.out.println("name = " + name);
    }

}
class Person1{
    String name;

    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "Person1{" +
                "name='" + name + '\'' +
                '}';
    }

    public void setName(String name) {
        this.name = name;
    }
}

运行结果

https://www.baidu.com
name = null

https://www.sina.com
name = null

https://www.qq.com
name = null

虽然可以通过设置成 static 的方式解决,但是如果多线程也是会有问题的。看到网上用 cucumber-picoContainer 来解决,但是尝试后还是一样,不知道大佬们有遇到过类似的问题吗?


↙↙↙阅读原文可查看相关链接,并与作者交流