如何在BDD方案之间共享任何变量/对象?我正在使用Cucumber BDD和Java定义我的步骤定义

问题描述 投票:0回答:1

这里登录API调用在所有情况下都很常见,因此我尝试使用“背景”。但是在本例中,在登录API调用之后,我们获得了会话ID,并且该会话ID需要作为标头传递给所有调用,都发生在登录调用之后。同样,同一用户不能多次进行登录呼叫,因此登录呼叫应仅发生一次,而下一次呼叫应仅使用第一次发生的登录呼叫的输出。

Cucumber BDD中有内置的技术可以处理这种情况吗?我只是不想在每种情况下都编写相同的登录步骤。

java cucumber bdd
1个回答
0
投票

您可以使用全局变量示例:

public class Test{

public static final String NAME = "xpto"; // global}

System.out.println(Test.NAME);

使用Ruby,这非常容易:我们只需要添加@

    # steps1.rb
Given /^a person exists by the name of John Galt$/ do
  @person = Person.new
  @person.name = 'John Galt'
end

# steps2.rb
Then /^his name should be John Galt$/ do
  @person.name.should == 'John Galt'
end
© www.soinside.com 2019 - 2024. All rights reserved.