lovers-of-behat/table-extension

Behat 扩展,用于检查 HTML 表格

安装次数: 82,540

依赖项: 1

建议者: 0

安全性: 0

星标: 7

关注者: 8

分支: 5

开放问题: 2

类型:behat-extension

1.5.2 2024-07-09 11:10 UTC

This package is auto-updated.

Last update: 2024-09-09 13:06:37 UTC


README

此库提供了 Behat 场景中检查 HTML5 表格的步骤定义。

安装

$ composer require lovers-of-behat/table-extension

配置

将扩展和上下文添加到您的测试套件中的 behat.yml

suites:
  default:
    contexts:
      - LoversOfBehat\TableExtension\Context\TableContext:
  extensions:
    LoversOfBehat\TableExtension:
      table_map:
        'Users': 'page.users .main-content table'
        'Country codes': 'table#country-codes'

选项

  • tableMap:将人类可读的表格名称映射到标识网页中表格的 CSS 选择器。这允许您在 Behat 场景中使用人类可读的名称。

使用方法

给定以下示例表格

并且我们已经将表格添加到 behat.yml 中的 table_map

suites:
  extensions:
    LoversOfBehat\TableExtension:
      table_map:
        'Employees': '#employees'

然后我们可以使用以下步骤来检查表格

# Check that the table is present on the page.
Then I should see the Employees table

# Check basic properties.
And the Employees table should have 5 columns

# Check the contents of the table. Cells that contain colspans and
# rowspans can be left empty.
And the Employees table should contain:
  | Name            | Department |                | Contact information |              |
  |                 | Office     | Position       | E-mail address      | Phone number |
  | Lelisa Ericsson | Healthcare | Nurse          | lelisa@example.com  | 555-1234567  |
  | Genista Sumner  | Science    | Anthropologist | genista@example.com | 555-987654   |

# The same step definition can be used to check partial data, as long as
# it is in a consecutive block of cells:
And the Employees table should contain:
  | Lelisa Ericsson | Healthcare | Nurse          |
  | Genista Sumner  | Science    | Anthropologist |

# Check non-consecutive columns by identifying them with the header
# text. This works even though the headers are in different rows in the
# original table.
And the Employees table should contain the following columns:
  | Name            | Office     | Phone number |
  | Lelisa Ericsson | Healthcare | 555-1234567  |
  | Genista Sumner  | Science    | 555-987654   |

有关更完整的示例,请参阅 tables.feature。或者检查 TableContext.php 以获取所有可用步骤的完整列表。

开发

本地运行测试

$ git clone git@github.com:LoversOfBehat/TableExtension.git table-extension
$ cd table-extension
$ composer install
$ php -S localhost:8000 -t fixtures &
$ ./vendor/bin/behat

致谢

本扩展的开发由欧洲委员会信息总局(DIGIT)作为 OpenEuropa 创新计划的一部分赞助。