@Before doesn't execute in java Cucumber Step

前端 未结 7 1688
一生所求
一生所求 2021-02-04 06:19

I\'ve got a Cucumber Step class that i\'m attempting to initialise a page model for all scenarios. So I added a @Before annotated method :

@Before()
private void         


        
7条回答
  •  死守一世寂寞
    2021-02-04 06:59

    Hello I know that is an old post, but none of these solutions work for me. So I'm going to share my solution.

    I created the class Hooks under the package: com.mycompany.automation.util

    package com.mycompany.automation.util;
    
    import com.mycompany.automation.rest.database.AS400DBManager;
    import cucumber.api.java.After;
    import java.sql.SQLException;
    
    /**
     * @author Julian Mesa
     * @version 0.1.0
     * @since 0.1.0
     */
    
        public class Hooks {
    
          @After
          public void beforeScenario() throws SQLException, ClassNotFoundException {
            System.out.print("Closing connection.");
            AS400DBManager.getInstance().closeConnection();
          }
    
        }
    

    and then I specified the package in the glue options in the runner:

    @RunWith(CucumberWithSerenity.class)
    @CucumberOptions(
        features = "src/test/resources/features",
        glue = {"com.mycompany.automation.features.steps",
            "com.mycompany.automation.util"}
    )
    

    And it worked.

提交回复
热议问题