重用黄瓜数据表 [英] Reusing cucumber data tables

查看:77
本文介绍了重用黄瓜数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在多个场景或功能文件中重用黄瓜测试数据?
我想绕过表数据代码重复。

How to reuse cucumber test data across several scenarios or feature files? I would like to bypass table data code duplication.

我当前的功能文件:

Scenario: At begining unable to click on first
    When On Sidebar page I click element basic table pagination
    And On PaginationTable page I click element first
    Then On PaginationTable page label pagination info value is Showing 1 to 13 of 1497 rows
    And I check table result pagination for PaginationTable page
        |noId|first_name|last_name|email|
        |1|Abbba|Baaba|big0@data.com|
        |2|Left|Right|big1@data.com|
    And I close and log out

Scenario: At begining unable to click on left
    When On Sidebar page I click element basic table pagination
    And On PaginationTable page I click element left
    Then On PaginationTable page label pagination info value is Showing 1 to 13 of 1497 rows
    And I check table result pagination for PaginationTable page
        |noId|first_name|last_name|email|
        |1|Abbba|Baaba|big0@data.com|
        |2|Left|Right|big1@data.com|
    And I close and log out


推荐答案

I会在下面回答您的问题,但是我认为这可能是场景大纲的一种情况,它使您可以以其他方式重用表。除了单击哪个元素外,您的方案是相同的。这大叫场景大纲。

I'll answer your question below, but I think this is probably a case for a scenario outline instead, which would allow you to reuse your table just in a different fashion. Your scenarios are identical save for which element you click. This screams scenario outline.

仅查看您的小黄瓜,就好像您有太多的特异性并且正在建立一个脆弱的测试,但是您知道其中存在的数据及其方式在测试运行期间加载/管理。只是要考虑一下。

Just looking at your gherkin, it feels like you have too much specificity and are building a brittle test, but you know more what data you have in there and how it is loaded/managed during the test run. Just something to think about.

回答您的问题

这种类型的功能不受Cucumber的直接支持,但是,如果您使用后台步骤进行设置,则可以在那里构建表并重复使用它,而只能在同一功能文件中使用。

This type of feature is not directly supported by Cucumber, however if you use a background step for setup, you can build your table there and reuse it, but only within the same feature file. It would not work across feature files.

在给定的背景下,只需将表存储为变量并在步骤中引用即可。

In the background given, just store the table as a variable and reference that in your steps.

Background:
  Given I expect table result pagination to be:
        |noId|first_name|last_name|email        |
        |1   |Abbba     |Baaba    |big0@data.com|
        |2   |Left      |Right    |big1@data.com|

Scenario: At beginning unable to click on first
    When On Sidebar page I click element basic table pagination
    And On PaginationTable page I click element first
    Then On PaginationTable page label pagination info value is Showing 1 to 13 of 1497 rows
    And I check table result pagination for PaginationTable page
    And I close and log out

Scenario: At beginning unable to click on left
    When On Sidebar page I click element basic table pagination
    And On PaginationTable page I click element left
    Then On PaginationTable page label pagination info value is Showing 1 to 13 of 1497 rows
    And I check table result pagination for PaginationTable page
    And I close and log out






使用方案大纲的替代实现

Scenario Outline: At beginning unable to click on element
    When On Sidebar page I click element basic table pagination
    And On PaginationTable page I click <element>
    Then On PaginationTable page label pagination info value is Showing 1 to 13 of 1497 rows
    And I check table result pagination for PaginationTable page
        |noId|first_name|last_name|email|
        |1|Abbba|Baaba|big0@data.com|
        |2|Left|Right|big1@data.com|
    And I close and log out

  Examples:
     | element |
     | first   |
     | left    |

这篇关于重用黄瓜数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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