重用黄瓜数据表

2024-04-16

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

我当前的功能文件:

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|[email protected] /cdn-cgi/l/email-protection|
        |2|Left|Right|[email protected] /cdn-cgi/l/email-protection|
    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|[email protected] /cdn-cgi/l/email-protection|
        |2|Left|Right|[email protected] /cdn-cgi/l/email-protection|
    And I close and log out

我将在下面回答您的问题,但我认为这可能是场景大纲的情况,这将允许您以不同的方式重用您的表。除了您单击的元素之外,您的场景是相同的。这尖叫场景大纲。

看看你的小黄瓜,感觉你有太多的特殊性并且正在构建一个脆弱的测试,但你更了解其中有哪些数据以及在测试运行期间如何加载/管理它。只是需要思考一下。


回答你的问题

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

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

Background:
  Given I expect table result pagination to be:
        |noId|first_name|last_name|email        |
        |1   |Abbba     |Baaba    |[email protected] /cdn-cgi/l/email-protection|
        |2   |Left      |Right    |[email protected] /cdn-cgi/l/email-protection|

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|[email protected] /cdn-cgi/l/email-protection|
        |2|Left|Right|[email protected] /cdn-cgi/l/email-protection|
    And I close and log out

  Examples:
     | element |
     | first   |
     | left    |
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

重用黄瓜数据表 的相关文章

随机推荐