在Cucumber groovy中的步骤定义之间传递变量

时间:2014-10-15 00:48:17

标签: groovy cucumber-jvm

我想知道如何在两个步骤定义文件之间传递变量。

我发现这个How to share variables across multiple cucumber step definition files with groovy但是它们的结构与我的不同,因为我没有在步骤定义中使用类。

以下是我的两步定义文件。

功能文件1

Scenario: Consumer registration
    When I try to register with my details with "memberNo" mem no.
    Then I should be able to get success response

stepDef1

When(~'^I try to register with my details with "([^"]*)" mem no.$') { String memdNo ->
   sMemdNo  = memNo + getRanNo()
   // more code here
}

功能文件2

Scenario: Event Generation
    When I activate my account
    Then I can see the file having "logName" event

stepDef2

Then(~'^I can see the file having "([^"]*)" event$') { String logName ->
   eventFile = GetLogtData(logName , sMemdNo )
   // more code here 
}

因此,根据上述内容,我希望从sMemdNo获取stepDef1的值并在stepDef2中使用它。

2 个答案:

答案 0 :(得分:0)

我建议您使用World来存储步骤定义所需的全局变量。 您可以在此处查看示例:cucumber-jvm-groovy-example。 您可以将World与Factory和/或依赖注入模式结合起来。

答案 1 :(得分:0)

要在步骤之间使用变量,可以在步骤文件(groovy或java)的顶部添加变量,并且在一个步骤中使用的变量将具有可用于其他变量的值。 Example

Result

相关问题