如何为基于环境的黄瓜情景实现不同的数据 [英] How to implement different data for cucumber scenarios based on environment

查看:326
本文介绍了如何为基于环境的黄瓜情景实现不同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在执行cucumber-jvm场景在不同的环境中有一个问题。并入场景的功能文件中的数据属于一个环境。为了在不同环境中执行场景,我需要根据要执行的环境更新features文件中的数据。



例如,在以下场景中,i具有包括在特征文件中的搜索标准。搜索条件对于允许说QA环境有效。

 场景:使用有效标准搜索用户

用户导航到登录页面
并点击搜索链接
当提供搜索条件搜索时
| fname1 | lname1 | address1 | address2 | city1 | state1 | 58884 |
然后验证显示的结果

它在QA env中正常工作。但是在其他环境(UAT,stage ..)中执行相同的场景,我需要根据这些环境中的数据修改要素文件中的搜索条件。



I



如果数据在属性文件中,情景将如下所示:下面。而不是搜索条件,我将给propertyName:

 场景:使用有效标准搜索用户

给定用户导航到登录页面
和点击的搜索链接
通过提供搜索条件搜索时
| validSearchCriteria |
然后验证显示的结果

是否有其他方法可以维护数据对于所有环境并根据场景使用它的场景正在执行?请让我知道。



感谢

解决方案

以两种方式


  1. 向上推动编程,以便按照运行cucumber的方式传递搜索条件


  2. 将程序向下推,以便您的步骤定义使用环境来决定从

    获取有效搜索条件的位置

这两个都涉及编写一个不指定搜索条件详细信息的更抽象的功能。所以你最终应该有一个功能,像

 场景:搜索有效的标准
当我搜索有效条件
然后我得到有效的结果

我将使用第二个方法实现这个,步骤定义如下:

 当我使用有效条件搜索do 
search_with_valid_criteria
end

module SearchStepHelper
def search_with_valid_criteria
条件= retrieve_criteria
search_with条件
end

def retrieve_criteria
#获取环境您正在使用
#使用环境来检索搜索条件
#返回条件
end
end
World SearchStepHelper

请注意,我所做的都是将工作的地方从功能改为模块中的帮助方法。 p>

这意味着,当你使用正确的编程语言(而不是特性)编程时,你可以做任何你想得到正确的标准。


I have an issue with executing the cucumber-jvm scenarios in different environments. Data that is incorporated in the feature files for scenarios belongs to one environment. To execute the scenarios in different environemnts, I need to update the data in the features files as per the environment to be executed.

for example, in the following scenario, i have the search criteria included in the feature file. search criteria is valid for lets say QA env.

Scenario: search user with valid criteria

Given user navigated to login page
And clicked search link
When searched by providing search criteria
|fname1  |lname1  |address1|address2|city1|state1|58884|
Then verify the results displayed 

it works fine in QA env. But to execute the same scenario in other environments (UAT,stage..), i need to modify search criteria in feature files as per the data in those environments.

I'm thinking about maintaing the data for scenarios in properties file for different environments and read it based on the execution environment.

if data is in properties file, scenario will look like below. Instead of the search criteria, I will give propertyName:

Scenario: search user with valid criteria

Given user navigated to login page
And clicked search link
When searched by providing search criteria
|validSearchCriteria|
Then verify the results displayed 

Is there any other way I could maintain the data for scenarios for all environments and use it as per the environment the scenario is getting executed? please let me know.

Thanks

解决方案

You can do this in two ways

  1. Push the programming up, so that you pass in the search criteria by the way you run cucumber

  2. Push the programming down, so that your step definition uses the environment to decide where to get the valid search criteria from

Both of these involve writing a more abstract feature that does not specify the details of the search criteria. So you should end up with a feature that is like

Scenario: Search with valid criteria
  When I search with valid criteria
  Then I get valid results

I would implement this using the second method and write the step definitions as follows:

When "I search with valid criteria" do
  search_with_valid_criteria
end

module SearchStepHelper
  def search_with_valid_criteria
    criteria = retrieve_criteria
    search_with criteria
  end

  def retrieve_criteria
    # get the environment you are working in
    # use the environment to retrieve the search criteria
    # return the criteria
  end
end
World SearchStepHelper

Notice that all I have done is change the place where you do the work, from the feature, to a helper method in a module.

This means that as you are doing your programming in a proper programming language (rather than in the features) you can do whatever you want to get the correct criteria.

这篇关于如何为基于环境的黄瓜情景实现不同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆