Cucumber class extending step definitions and hooks
The only problem is with the cucumber annotations which use AOP and create a proxy class so just move the @Before
and @After
in your concrete implementations
public class BaseStepDefinition {
protected void init(){
PageFactory.initElements(..);
}
}
public class MyStepDefinition extends BaseStepDefinition {
@Before
@Override
public void init() {
super.init();
}
}
As I understand your problem, you want to reduce the logic for steps. Here is the solution.
1) Define a common class in this case A
with steps in a general package like co.com.test
2) Define the steps config to use the base package
@CucumberOptions(format = {"pretty", "html:target/html/"},
features = {"src/test/resources/acceptance/general/general.feature"},
glue = {"co.com.test"})
3) Doesn't inheritance from class B with specific steps to A
It will cause that steps will be searched in all packages and will find the common steps and the specific steps.