How to run precondition and postcondition test methods in Cucumber?

CucumberSoftware TestingAutomation Testing

We can run precondition and postcondition test methods with the help of @Before and @After hooks in Cucumber.

Example

Feature file.

Feature: Transaction Table
Scenario: Verify the monthly transactions
Given User is on the Payment Page

Step Definition has methods with hooks @Before and @After. The test method with hook @Before will be executed as a precondition then the test method (naviagteToPayment() method) will run and finally the test method with hook @After which is the postcondition will execute.

Example

@Before
public void method1(){
   System.out.println("The precondition executed successfully");
}
@After
public void method2(){
   System.out.println("The postcondition executed successfully ");
}
@Given ("^User is on payment page$")
public void navigateToPayment(){
   System.out.println ("Payment screen navigation is successful");
}
raja
Published on 11-Jun-2020 16:43:43
Advertisements