0

Cucumber java

My feature file looks like

Feature Scenario1:.... Generate a unique number

Scenario2:.... Do some validations on the unique number generated

Using spring for dependency injection, the unique number generated @ Scenario1 is assigned to a String, the same need to be used across the Scenario2 as well.

But I'm getting a String value as null @Scenario2. I think the dependency injection @ scenario2 is creatin a new object and is getting the default value as null.

Please help me on to resolve this issue. Need to know how java objects can be passed across different scenarios in a single feature..

Guru
  • 11
  • 2
  • Scenarios are supposed to be state free, maybe you should think about taking both things into one Scenario? – Dude Apr 14 '15 at 14:11

2 Answers2

0

Use Singleton?

1) Generate unique number at 1st scenario 2) getInstance() at 2nd

  • By default all the injected beans will be singleton. Is it? Also, the instances can be used across the scenarios when we make it static. I am not sure if cucumber DI is performing some thing else – Guru Apr 03 '15 at 06:06
0

Use gherkin with qaf where it provides different ways to share information between steps or scenarios.

For example, If your step returns value you can use like:

Then get text of 'element' 
And store into 'applicaiton.refID'

to refer any stored value or any property you can use ${property}. For example

Given application to update is '${applicaiton.refID}'

You can applicaiton.refID in any of subsequent scenario. If you want to do this in java step, you can write code something like below:

//store value for further use
getBundle().setProperty("applicaiton.refID","myvalue");

//retrieve applicaiton.refID any where
getBundle().getString("applicaiton.refID");
user861594
  • 5,733
  • 3
  • 29
  • 45