jeudi 25 décembre 2014

Cucumber Java - How to use returned parameters from a step in a new step?

I'm using cucumber with java in order to test my app ,

I would like to know if it is possible to take an object returned from first scenario step and use it in other steps. Here is an example for the desirable feature file and Java code :



Scenario: create and check an object
Given I create an object
When I am using this object(@from step one)
Then I check the object is ok


@Given("^I create an object$")
public myObj I_create_an_object() throws Throwable {
myObj newObj = new myObj();
return newObj;
}

@When("^I am using this object$")
public void I_am_using_this_object(myObj obj) throws Throwable {
doSomething(obj);
}

@Then("^I check the object is ok$")
public void I_check_the_object_is_ok() throws Throwable {
check(obj);
}


I rather not to use variables in the class

(Because then all method variables will be in class level)

but i'm not sure it's possible.


Is it possible to use a return value in a method as an input in the next step?


Aucun commentaire:

Enregistrer un commentaire