我们可以在Cucumber中的@Before和@After挂钩的帮助下运行前置条件和后置条件测试方法。
功能文件。
Feature: Transaction Table Scenario: Verify the monthly transactions Given User is on the Payment Page
步骤定义具有带有钩子@Before和@After的方法。带有钩子@Before的测试方法将作为前提条件执行,然后将运行测试方法(naviagteToPayment()方法),最后将带钩子@After的测试方法作为后置条件执行。
@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"); }