黄瓜 - 根据数据库中的记录多次运行相同的功能

时间:2016-06-21 07:31:10

标签: ruby cucumber rake

我有一个黄瓜功能,可以检查网站是否正确处理了付款文件(BACS,SEPA,FPS等)。该过程的第一阶段是创建支付文件,该支付文件又在数据库中创建预期结果数据。然后,此数据用于验证付款处理网站。

如果我处理一个文件,我的功能可以完美地验证预期结果。我遇到的问题是如何根据最初处理的记录/文件的数量来运行(n)次数。

我尝试过使用记录计数迭代而没有快乐的'Around'钩子,无法看到我如何将其融入大纲场景中,现在认为调用该功能的rake任务也许可行。< / p>

任何想法都将不胜感激。

以下是该功能的示例:

功能:处理SEPA学分转移文件。同日价值付款。

Background:
    Given we want to test the "SEPA_Regression" scenario suite  
        And that we have processed a "SEPA" file from the "LDN" branch
        And we plan to use the "ITA1" environment 
    Then we log in to "OPF" as a "SEPA Department" user

@feature @find_and_check_sepa_interchange @all_rows
Scenario:   Receive SEPA Credit Transfer Files for branch
    Given that we are on the "Payment Management > Interchanges" page
    When I search for our Interchange with the following search parameters:
        | Field Name |
        | Transport Date From |
        | Bank |
        | Interchange Reference |
    Then I can check the following fields for the given file in the "Interchanges" table:
        | Field Name|
        | Interchange Reference |
        | Transport Date |
        | File Name |
        | File Format |
        | Clearing Participant |
        | Status |
        | Direction |
        | Bank |
    When I select the associated "Interchange Id" link
    Then the "Interchange Details" page is displayed

更新我已经为该功能实现了嵌套步骤,以便我可以先调用数据库记录并将每组记录(或至少是行ID)提供给主要功能,如下所示:

功能

@trial_feature 
Scenario:   Validate multiple Files
    Given we have one or more records in the database to process for the "SEPA_Regression" scenario
    Then we can validate each file against the system

功能步骤:

Then(/^we can validate each file against the system$/) do
x = 0
while x <= $interchangeHash.count - 1
    $db_row = x
    # Get the other sets of data using the file name in the query       
    id = $interchangeHash[x]['id']
    file_name = $interchangeHash[x]['CMS_Unique_Reference_Id']
    Background.get_data_for_scenario(scenario, file_name)
    steps %{
    Given that we are on the "Payment Management > Interchanges" page
        When I search for our Interchange with the following search parameters:
            | Field Name |
            | Transport Date From |
            | Bank |
            | Interchange Reference |
        Then I can check the following fields for the given file in the "Interchanges" table:
            | Field Name|
            | Interchange Reference |
            | Transport Date |
            | File Name |
            | File Format |
            | Clearing Participant |
            | Status |
            | Direction |
            | Bank |
        When I select the associated "Interchange Id" link
        Then the "Interchange Details" page is displayed

似乎有点'黑客',但它确实有效。

1 个答案:

答案 0 :(得分:0)

如果你有批处理软件,那么你应该有几个Given(设置)步骤,1个(触发)步骤,几个Then(条件)步骤。

Given I have these SEPA bills
 | sepa bill 1 |
 | sepa bill 2 |
And I have these BAC bills
 | bac bill 1 |
 | bac bill 2 |
When the payments are processed
Then these sepa bills are completed
 | sepa bill 1 |
 | sepa bill 2 |
And I these bac bills are completed
 | bac bill 1 |
 | bac bill 2 |

它更简单,更容易阅读应该完成的任务,并且可以扩展到更多。这些工作应该在设置和验证的步骤定义中完成。