简体   繁体   English

如何将一个特征文件的数据(从示例中)传递到另一个特征文件?

[英]how to pass the data(from Examples) of one feature file to other feature file?

When I first execute a feature file , am updating the fields of it during run time. 当我第一次执行功能文件时,正在运行时更新它的字段。 The same field's value is required to pass to other feature file. 传递给其他功能文件需要相同字段的值。 Is it possible to pass the data of one feature file to another feature file using java? 是否可以使用Java将一个功能文件的数据传递给另一个功能文件?

feature file 1:
scenario outline: test xxx functionality
Examples :
|user|password|
|abc|pass|

feature file2:
Scenario Outline : test yyy functionality
Examples:
|user|password|
|    |        |

Here, I want the data that is there in the feature file1 to be passed to feature file 2 ie, abc and pass should be copied to Examples of feature file 2. Please do suggest.Thanks in advance!! 在这里,我希望将特征文件1中的数据传递到特征文件2,即abc,并将传递信息复制到特征文件2的示例中。请务必提出建议。谢谢!!

Passing values from one feature file to another is not supported. 不支持将值从一个功能文件传递到另一个功能文件。 It would force you to execute your scenarios in a specific order. 这将迫使您按特定顺序执行方案。 That is a well known anti pattern. 这是众所周知的反模式。 Your scenarios should be possible to execute in any order and that is not possible if you expect one scenario to be executed before another. 您的方案应该可以按任何顺序执行,而如果您希望一个方案先于另一个方案,则不可能。

So how should you be able to reuse your setup from the first feature file in the second? 那么,如何在第二个功能文件中重用您的设置呢? The short answer is don't. 简短的答案是不。 Instead implement a helper that the features that need the user to be setup can use to prepare the system under test. 而是实现一个帮助程序,以帮助需要设置用户的功能来准备要测试的系统。 Call this helper from each scenario that need this setup before it's execution. 在执行此设置之前,请从需要此设置的每个方案中调用此帮助程序。 This may sound as a lot of unnecessary work, but it will save you from a lot of problems with scenarios that depends on each other and leaves your system in unexpected states between executions. 这听起来可能是很多不必要的工作,但是它将使您避免许多相互依赖的场景带来的问题,并使您的系统在两次执行之间处于意外状态。

Strictly speaking, you should not be passing data from one BDD test to another. 严格来说,您不应将数据从一个BDD测试传递到另一个BDD测试。 This would defeat the purpose of having an independent unit BDD test. 这将破坏进行独立的单元BDD测试的目的。 In general, software unit tests are supposed to be independent of one another. 通常,软件单元测试应该相互独立。

That being said, you can certainly persist some state from one step definition and then reuse it another one: 话虽如此,您当然可以从一个步骤定义中保留某些状态,然后再将其重复使用:

@When("^I login with username \"(.*)\"$") 
public void enterUsername(String username) { 
    // do something with username

    // make a database call and insert the username in a temporary table
}

Then, in the second feature file you can query the same table and retrieve the username. 然后,在第二个功能文件中,您可以查询同一表并检索用户名。

This may not be exactly what you have in mind, but the general idea is just to persist some state during the first test, which can then be used in a second test. 这可能与您的想法不完全相同,但是总体思路只是在第一次测试期间保持某种状态,然后可以在第二次测试中使用它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Cucumber 功能文件中传递具有不同数量参数的多个示例 - How to pass multiple examples with different number of parameters in Cucumber feature file 如何在Cucumber中将原始数据json格式从特征文件传递到stepdefinition文件 - How to pass raw data json format from feature file to stepdefinition file in Cucumber 如何为 Android 和 iOS 运行一个功能文件 - How to run one feature file for Android and iOS 如何将参数传递给Selenium Java测试文件中的空手道特征文件 - How to pass arguments to karate feature file from selenium java test file 如何从Jenkins读取Cucumber功能文件 - How to read Cucumber feature file from Jenkins 并行运行 cucumber 功能文件中的场景,一次一个功能文件 - Run scenarios in a cucumber feature file in parallel, one feature file at a time 在给定数据上循环功能文件 - loop a feature file on the given data 如何使用java Cucumber将“#”作为特征文件中的有效参数传递 - How to pass "#" as a valid parameter in feature file using java cucumber 如何在黄瓜功能文件的“示例”中提及布尔值,并确保它在Java中创建方法? - How to mention Boolean value in 'Examples' in feature file of cucumber and make sure it creates a method in java? 如何将 Cucumber 功能文件中的场景名称作为 Cucumber 步骤中的参数传递? - How to pass Scenario name from the Cucumber feature file as a parameter in the Cucumber steps?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM