java怎么返回string_黄瓜Java-如何在下一步中使用返回的String?

我需要自动化一些Web服务,为此我创建一些方法,并且我想为此使用Cucumber,但是我无法弄清楚如何在下一步中使用返回值.

所以,我有这个功能:

Feature: Create Client and place order

Scenario: Syntax

Given I create client type: "66"

And I create for client: "OUTPUTVALUEfromGiven" an account type "123"

And I create for client: "OUTPUTVALUEfromGiven" an account type "321"

And I want to place order for: "outputvalueFromAnd1"

我有以下步骤:

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 for client: \"([^\"]*)\" an 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;

}

}

是否可以逐步使用返回值?

谢谢!

解决方法:

步骤之间共享状态(这就是我如何解释您的问题)不是通过检查返回的值来完成的.通过在实例变量中设置值并随后在另一步骤中读取该实例变量来完成此操作.

我将更改您的步骤以实现以下目标:

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 for client: \"([^\"]*)\" an account type \"([^\"]*)\"$")

public void createAccount(String clientID, String accountType) {

try {

orderID = util.createAccount(clientID, accountType);

} catch (IOException e) {

e.printStackTrace();

}

}

}

我改变的是

>两个用于共享状态的字段-其他步骤以后可以读取值

>非静态方法-黄瓜会为每个场景重新创建步骤类,因此我不希望字段为静态,因为这将意味着它们的值会在场景之间泄漏

这是您在同一类中的步骤之间共享状态的方式.也可以在不同类的步骤之间共享状态.这有点复杂.询问您是否有兴趣.

标签:java,cucumber,cucumber-java

来源: https://codeday.me/bug/20191014/1911785.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值