What Is Hooks In Cucumber?

What Is Hooks In Cucumber?

Hooks in Cucumber

Hooks is nothing but the script which run before or after each scenarios. There are some annotation which are used to execute script before or after each scenarioes.

Below are the lists of cucumber annotation which can use in BDD.

1. @Before:-
This annotation is same like @BeforeMethod annotation in TestNG. This annotation invoke before each test case in feature file.Example is given below.

Step definition

@Before
	public void beforeAnnotation()
	{
		System.out.println("This is before Annotation");
	}
      

2. @Before(order =1):-
In case, if you have more than one before annotation in one class then this will arrange the order of before annotation Example is given below.

Step definition

  
  @Before (order=0)
	public void beforeOrderMethod0()
	{
		System.out.println("Before Order 0");
	}
    
@Before (order=1)
	public void beforeOrderMethod()
	{
		System.out.println("Before Order 1");
	}
    
    
    

3. @BeforeStep:-
This annotation will execute before each step in feature file. Example is given below.

Step definition

 
@BeforeStep
	public void beforeStep()
	{
		System.out.println("this will execute before each step");
	}
    

4. @After:-
This annotation is same like @AfterMethod annotation in TestNG. This annotation invoke after each test case in feature file. Example is given below.

Step definition

  
    @After
	public void AfterMethod()
	{
		System.out.println("This is After Method");
	}
    

5. @After(order=2):-
In case, if you have more than one after annotation in one class then this will arrange the order of after annotation. Example is given below.

Step definition

  
   
   @After (order=0)
	public void AfterOrderMethod0()
	{
		System.out.println("After Order 0");
	}
    
    
@After (order=1)
	public void AfterOrderMethod()
	{
		System.out.println("After Order 1");
	}
    

6. @AfterStep:-
This annotation will execute after each step in feature file. Example is given below.

Step definition

     
@AfterStep
	public void afterStep()
	{
		System.out.println("this will execute after each step");
	}
    
You Can Also View Related Topics :-
Keywords in Feature file










No comments:

Post a Comment