1

I´m using cucumber-selenium to run some integration tests. I manage to create the feature file and the Test class. But once that I´m in my Give method I see that the ScenarioSteps(ProjectMemberSteps) class that I define to talk with the object page is null. I was expecting to be injected like JBehave does.

public class OrderTest extends StepsLibrary {

    @Steps ProjectMemberSteps projectManager;//This one is null

    @Before
    public void beforeScenarios() throws Exception {
       initializeDemoUIServer();
     }
    @Given("I open the login page")
    public void openLoginPage(){
        projectManager.openLoginPage();
    }
   }

This is the Scenario runner class for the test

           /**
   * Serenity story for login.
     */
  @RunWith(CucumberWithSerenity.class)
@CucumberOptions(features="src/test/resources/features/order/order.feature",
    glue = Order.BEHAVIOUR_PACKAGE)
    public class Order {
    public static final String BEHAVIOUR_PACKAGE =    "com.behaviour.steps.serenity";
    }

This is class ProjectMemberSteps is under steps/serenity/ as the documentation suggest. I´m using Maven, and the libraries that I´m using are

          <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-junit</artifactId>
    </dependency>

    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>core</artifactId>
        <version>1.0.47</version>
    </dependency>

Anyway this particular test I´m running with the IDE and not through Maven, but I was expecting that "ProjectMemberSteps" would be inject as JBehave use to do.

Any idea what´s wrong?

Regards.

4

1 回答 1

1

我也是新手。我看不到您的 OrderTest.java 类有任何问题,只是它不必要地扩展了一个名为 StepsLibrary 的类。在 Java-Cucumber 中,我不扩展任何其他类。唯一的例外是当 StepDefinition 文件(您的 OrderTest.java)将方法调用委托给 xxxxSteps.java 类,而后者又委托给 xxxPageObject.java(必须从 Serenity 扩展 PageObject 类import net.serenitybdd.core.pages.PageObject;)

我假设在注释之前是重复一个场景。相反,另一种选择是在功能文件本身中使用 Background 关键字。尽管如此,我并没有声称有任何优势。

就我而言,您的 Test Runner 类应该只给出 xxxxStepDefinitions.java 所在的包,就像glue = {"stepdefinitions"},我相信花括号是可选的一样。

其余的在我看来完全没问题。包括定义

@Steps ProjectMemberSteps projectManager;

再试一次。

于 2019-02-24T21:28:13.597 回答