digitalist-se/behat-tools

Behat 工具

v2024.02.07 2024-03-07 10:38 UTC

This package is auto-updated.

Last update: 2024-09-12 11:57:01 UTC


README

Behat 相关工具

设置

将此添加到您的 composer.json 文件的 repositories 部分

        {
            "type": "vcs",
            "url": "https://github.com/digitalist-se/behat-tools"
        },

执行

composer require --dev digitalist-se/behat-tools

将此添加到您的 behat.yml

default:
  suites:
    default:
      contexts:
        - digitalistse\BehatTools\Context\CommonContext

根据需要使用相同的结构添加更多上下文。

实体上下文

您可以在 behat.yml 中像这样设置每个字段日期的格式

default:
  suites:
    default:
      parameters:
        entity_context:
          datetime_format:
            announcement:
              publish_date: 'Y-m-d'
              unpublish_date: 'Y-m-d'
            announcement_tracker:
              created_date: 'Y-m-d\TH:i:s'
              sent_date: 'Y-m-d\TH:i:s'
              read_date: 'Y-m-d\TH:i:s'

在这种情况下,您可以使用 php 格式的相对日期

Given a "license_tracker" entity exists with the properties:
      | label | status | uid:user:mail       | field_license:license:title | created     | activated   | expire  | first_notification | second_notification | service_requirement_expired |
      | TRK10 | 1      | license-01@test.com | Test license 1              | 6 month ago | 6 month ago | 91 days | tomorrow           | 61 days             | tomorrow                    |
      | TRK10 | 1      | license-02@test.com | Test license 1              | 6 month ago | 6 month ago | 90 days | today              | 60 days             | tomorrow                    |
      | TRK10 | 1      | license-03@test.com | Test license 1              | 6 month ago | 6 month ago | 89 days | yesterday          | 59 days             | tomorrow                    |

实体字段支持

实体字段支持如下示例: (<field_type>) <field_name>.<field_property>

  • 具有简单结构的字段(例如:布尔值、文本字段等): field_archived.value
  • 具有更复杂结构的字段类型: (daterange) field_date.value

注意:目前仅支持 daterange 类型。如果需要支持更复杂的字段,可以在 EntityContext::processEntityFields 中添加处理。

使用实体字段和属性的示例

Given a "license_tracker" entity exists with the properties:
      | label | status | uid:user:mail       | field_archived.value | (daterange) field_date.value | (daterange) field_date.end_value |
      | TRK10 | 1      | license-01@test.com | 1                    | 6 month ago                  | 6 month ago                      |
      | TRK10 | 1      | license-02@test.com | 0                    | 6 month ago                  | 6 month ago                      |
      | TRK10 | 1      | license-03@test.com | 1                    | 6 month ago                  | 6 month ago                      |

屏幕截图上下文

您可以在 behat.yml 中设置不同的参数,如下所示

default:
  suites:
    default:
      screenshot_context:
        screenshot_path: '%paths.base%/screenshots-build'
        do_resizing: true
        display_sizes:
          mobile:
            width: 375
            height: 667
          tablet:
            width: 768
            height: 1024
          desktop:
            width: 1920
            height: 1080

将调整大小设置为 true 将创建与 display_sizes 中相同数量的屏幕截图。如果您打算比较屏幕截图,这可能是一个问题,因为调整大小可能会导致问题。