Search code examples
javaspringcucumbercucumber-jvmgherkin

How to access common variables created through Gherkin step definitions in Java without redundancy?


We have a couple of feature files, that share common steps. Login for example is the simplest step that comes to mind, if I want to get the user object that the login step created and was set in the LoginStepDefinitions.java file. Is it in my context, is there someway to access this class' variables, can I Autowire another step definition or something?


Solution

  • nilesh's answer is close, but to be more modular, you can keep your step definitions separated from each other and have context-aware objects injected into each of them. Cucumber can guarantee the state cleanliness before each scenario.