Driver Instance - With hooks

The best place to implement this code is the @Before and @After scenario hooks given that we want to start a new driver instace before the scenario starts and kill the browser after the scenario is completed.

Consider the following code for StartingSteps class to demonstrate this concept.

public class StartingSteps {

    private WebDriver driver;

    public void beforeScenario() {
        driver = new DriverFactory().getDriver();
        System.out.println("this will run before the actual scenario");

    public void afterScenario() {
        new DriverFactory().destroyDriver();
        System.out.println("this will run after scneario is finished, even if it failed");

    @Given("^the user is on landing page$")
    public void setup() throws Throwable {

    public void signupSetup() {
        System.out.println("This should run everytime before any of the @Signup-DataDriven tagged scenario is going to run");

    public void signupTeardown() {
        System.out.println("This should run everytime after any of the @Signup-DataDriven tagged scenario has run");


results matching ""

    No results matching ""