[英]java-Share data among different scenarios in a single feature
My feature file looks like 我的功能文件看起来像
Feature Scenario1:.... Generate a unique number 功能场景1:....生成唯一编号
Scenario2:.... Do some validations on the unique number generated 方案2:....对生成的唯一编号进行一些验证
Using spring for dependency injection, the unique number generated @ Scenario1 is assigned to a String, the same need to be used across the Scenario2 as well. 使用spring进行依赖项注入时,将@ Scenario1生成的唯一编号分配给一个String,同样需要在Scenario2中使用相同的编号。
But I'm getting a String value as null @Scenario2. 但是我将String值设置为null @ Scenario2。 I think the dependency injection @ scenario2 is creatin a new object and is getting the default value as null.
我认为依赖注入@场景2是在一个新对象中创建的,并且将默认值设置为null。
Please help me on to resolve this issue. 请帮助我解决此问题。 Need to know how java objects can be passed across different scenarios in a single feature..
需要知道如何在单个功能中跨不同场景传递Java对象。
Use Singleton? 使用Singleton?
1) Generate unique number at 1st scenario 2) getInstance() at 2nd 1)在第一种情况下生成唯一编号2)在第二种情况下生成getInstance()
Use gherkin with qaf where it provides different ways to share information between steps or scenarios. 将小黄瓜与qaf结合使用,它提供了不同的方法来在步骤或方案之间共享信息。
For example, If your step returns value you can use like: 例如,如果您的步骤返回值,则可以这样使用:
Then get text of 'element'
And store into 'applicaiton.refID'
to refer any stored value or any property you can use ${property}
. 引用任何可以使用
${property}
存储值或任何属性。 For example 例如
Given application to update is '${applicaiton.refID}'
You can applicaiton.refID
in any of subsequent scenario. 您可以在任何后续方案中使用
applicaiton.refID
。 If you want to do this in java step, you can write code something like below: 如果要在Java步骤中执行此操作,可以编写如下代码:
//store value for further use
getBundle().setProperty("applicaiton.refID","myvalue");
//retrieve applicaiton.refID any where
getBundle().getString("applicaiton.refID");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.