I\'ve got a Cucumber Step class that i\'m attempting to initialise a page model for all scenarios. So I added a @Before annotated method :
@Before()
private void
Hello I know that is an old post, but none of these solutions work for me. So I'm going to share my solution.
I created the class Hooks
under the package: com.mycompany.automation.util
package com.mycompany.automation.util;
import com.mycompany.automation.rest.database.AS400DBManager;
import cucumber.api.java.After;
import java.sql.SQLException;
/**
* @author Julian Mesa
* @version 0.1.0
* @since 0.1.0
*/
public class Hooks {
@After
public void beforeScenario() throws SQLException, ClassNotFoundException {
System.out.print("Closing connection.");
AS400DBManager.getInstance().closeConnection();
}
}
and then I specified the package in the glue options in the runner:
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(
features = "src/test/resources/features",
glue = {"com.mycompany.automation.features.steps",
"com.mycompany.automation.util"}
)
And it worked.