Saturday, April 22, 2023

 

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");
	}

Related Posts:

  • How to write step definition in cucumber? How to write step definition in cucumber?Java class is used for writing step definition file. This execute each given steps in feature file. We have to write a method for each step in step definition java class with sam… Read More
  • How to pass the Parameter in BDD cucumber? How to pass the Parameter?Passing parameter by using “” (double quotes) OR <> signFrom feature file, we can pass a single parameter by using “” in the step.Example is given below.Step in Feature file Given user lo… Read More
  • BDD cucumber Secondary keywords in feature file BDD cucumber Secondary keywords in feature fileSecondary keywords in feature fileBelow are some lists of secondary keywords which can be use in feature file while writing test case.1. # (hash sign): -hash(#) is used to … Read More
  • Regular expression in step definition in cucumber Regular expression in step definitionBelow are some lists of special character that can be used while writing step definition.1. .(dot)-We can use any character in place of "." In below example, single step definit… Read More
  • Selenium BDD cucumber Keywords in Feature file Selenium BDD cucumber Keywords in Feature fileKeywords in Feature fileFeature file is use to write the test step in Gherkin language. Below are some important keywords in feature file which are used to write test case.•… Read More

0 comments:

Post a Comment

Translate

Popular Posts

Total Pageviews

152,057