I trying to incorporate pico-container DI into my framework so I can use the @Before and @After tags across multiple step definitions. Please see the error below. Any advice would be great.
You're not allowed to extend classes that define Step Definitions or hooks. class steps.hotelBookingFormPage extends class resources.hooks
import io.cucumber.java.en.Given;
import org.openqa.selenium.internal.ShutdownHooks;
import resources.hooks;
public class hotelBookingFormPage extends hooks {
public hooks base;
hotelBookingFormPage (hooks base) {
base = hooks.startBrowser();
}
@Given("I navigate to the hotel booking form page")
public void iNavigateToTheHotelBookingFormPage() {
base.driver.get("http://hotel-test.equalexperts.io/");
}
Cucumber creates a new instance of all classes defining
StepDefinitionbefore each scenario. It then invokesStepDefinitionmethods on one of those instances whenever it needs to run a step. If I declare a method test in aclassand extended toStepDefinitionextended toclassthen two instances will be created and test method will be available on both instances, and cucumber would not be able to decide what instance to invoke the method on. Incase of inheriting to class(which is having hook methods) then you can use composition.Current way:
Updated way: