在Cucumber中使用Java将一个步骤定义中的已实现步骤调用到其他步骤定义中,可以通过以下步骤实现:
import io.cucumber.java.en.Given;
public class StepDefinitions {
@Given("I have a step")
public void iHaveAStep() {
// 已实现的步骤逻辑
}
}
import io.cucumber.java.en.When;
public class OtherStepDefinitions {
@When("I call the step")
public void iCallTheStep() {
StepDefinitions stepDefinitions = new StepDefinitions();
stepDefinitions.iHaveAStep(); // 调用已实现的步骤
}
}
Feature: Using steps from other step definitions
Scenario: Calling a step from another step definition
Given I have a step
When I call the step
Then the step is executed
这样,在执行Cucumber测试时,当步骤"Given I have a step"被调用时,它会执行已实现的步骤逻辑。
领取专属 10元无门槛券
手把手带您无忧上云