Cucumber Java - How to use returned String from a step in next step? -
i need automate webservices, create methods , want use cucumber can't figure how use returned value in next step.
so, have feature:
feature: create client , place order scenario: syntax given create client type: "66" , create client: "outputvaluefromgiven" account type "123" , create client: "outputvaluefromgiven" account type "321" , want place order for: "outputvaluefromand1"
and have steps:
public class createclientsteps { @given("^i create client type: \"([^\"]*)\"$") public static string icreateclient(string clienttype) { string clientid = ""; system.out.println(clienttype); try { clientid = util.createclient(clienttype); } catch (ioexception e) { e.printstacktrace(); } return clientid; } @and("^i create client: \"([^\"]*)\" account type \"([^\"]*)\"$") public static string createaccount(string clientid, string accounttype) { string orderid = ""; try { orderid = util.createaccount(clientid,accounttype); } catch (ioexception e) { e.printstacktrace(); } return orderid; } }
it's way use returned values step step?
thank you!
sharing state between steps, how interpret question, not done examining returned value. done setting value in instance variable , later read instance variable in step.
i change steps in order achieve that:
public class createclientsteps { private string clientid; private string orderid; @given("^i create client type: \"([^\"]*)\"$") public void icreateclient(string clienttype) { system.out.println(clienttype); try { clientid = util.createclient(clienttype); } catch (ioexception e) { e.printstacktrace(); } } @and("^i create client: \"([^\"]*)\" account type \"([^\"]*)\"$") public void createaccount(string clientid, string accounttype) { try { orderid = util.createaccount(clientid, accounttype); } catch (ioexception e) { e.printstacktrace(); } } }
the things changed are
- two fields sharing state - other steps can read values later
- non static methods - cucumber recreates step class every scenario, therefore don't want fields static since mean values leak between scenarios
this how share state between steps in same class. sharing state between steps in different classes can done. bit more complicated. ask if interested.
Comments
Post a Comment