Hooks(Ordering/Priority)(Example)

 @Par6 @setcookies @test

Scenario Outline: Home Page Links

Given I am in Ebay Shopping Homepage

When I click on '<link>'

Then I validated the page navigates to '<url>' and titie is '<title>'


Examples:

| link | url | title | |

| Deals | https://www.ebay.com/globaldeals | Daily Deals on eBay | Best deals and Free Shipping |

| Fashion | https://www.ebay.com/b/Fashion/bn_7000259856 | Fashion | eBay |

| Sports | https://www.ebay.com/b/Sporting-Goods/888/bn_1865031 | Sporting Goods | eBay |

============================================

package testRunner;

import org.junit.runner.RunWith;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/java/Features"},
glue = {"Steps"},
tags = "@Par6",
monochrome = true
)
public class ParameterRunner {
}


============================================

package Steps;


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.chrome.ChromeDriver;

import io.cucumber.java.After;

import io.cucumber.java.Before;


public class HookSteps {


private WebDriver driver;

@Before(order =0)

public void setup() {

driver = new ChromeDriver();

driver.manage().window().maximize();

System.out.println("global BEFORE got executed");

}

@Before(value="@setcookies", order =1)

public void setcookies() {

System.out.println("Scenario specific hook - setcookies got executed");

}

@After(order =1)

public void teardown() throws InterruptedException {

driver.quit();

System.out.println("global AFTER got executed");

Thread.sleep(2000);

}


@After(value="@test", order =0)

public void afterHook() throws InterruptedException {

System.out.println("Scenario specific hook - test got executed");

}

public WebDriver getDriver() {

return driver;

}

}



global BEFORE got executed

Scenario specific hook - setcookies got executed

global AFTER got executed

Scenario specific hook - test got executed

============================================