简体   繁体   English

单个功能中不同场景之间的Java共享数据

[英]java-Share data among different scenarios in a single feature

Cucumber java 黄瓜爪哇

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.

相关问题 如何在java中的swing之间共享数据? - How to share data among swing in java? 如何在一组Java对象中共享一个名称? - How does one share a single name among a group of Java Objects? 在不同情况下,将多个Java文件中的单个单词替换一个不同的许多字符或单词 - Replace a different and many characters or word's to single word in multiple Java files in different scenarios [DynamoDB]:我可以使用DynamoDBMapper在DynamoDB的多个表之间共享单个数据模型吗? - [DynamoDB]: Can I share single data model among multiple tables in DynamoDB using DynamoDBMapper? 在多个设备之间共享单个Google Map - Share single google map among multiple device 如何在不同的字符串之间共享子字符串? - How to share a substring among different strings? TomEE在不同应用程序之间的共享持久性 - TomEE Share Persistence among different applications 如何在本地网络上的多个主机之间状态共享我的Java应用程序的数据更改 - How to state-fully share my Java application's data changes among multiple hosts on a local network 在Web服务之间共享数据的最佳方法 - Best way to share data among webservices 用标签排除cucumber特征文件中的几种不同场景 - Excluding several different scenarios in cucumber feature file with tags
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM