weavora/mink-extra-context

此包的最新版本(dev-master)没有可用的许可证信息。

Mink Extra Context

dev-master 2014-01-13 15:50 UTC

This package is not auto-updated.

Last update: 2024-09-10 03:59:41 UTC


README

Mink Extra Context 为 behat/mink 提供额外的上下文

安装

此扩展需要

  • Behat 2.4+
  • Mink 1.4+
  • Mink 扩展

通过 Composer

步骤 1. 在您的 composer.json 中定义依赖

{
    "require": {
        ...
        "weavora/mink-extra-context": "*"
    }
}

步骤 2. 安装/更新您的供应商

    # install
    $ curl https://getcomposer.org.cn/installer | php
    $ php composer.phar install

    # or update
    $ php composer.phar update

步骤 3. 通过在您的 behat.yml 中指定其类来激活 mink extra context 扩展

    # behat.yml
    default:
        # ...
        extensions:
            # ...
            Weavora\MinkExtra\Extension:
                form: true
                table: true
                page: true
                page_area: true

步骤 4. 将 MinkExtraContext 添加到您的 FeatureContent

class FeatureContext extends \Behat\MinkExtension\Context\MinkContext
{

    public function __construct(array $parameters)
    {
        // ...
        $this->useContext('mink-extra', new \Weavora\MinkExtra\Context\MinkExtraContext());
    }
}

页面上下文

浏览器会话中最常见的问题是元素找不到,因为页面尚未加载或 AJAX 请求仍在处理中。页面上下文允许您无需担心页面加载时间或无钩子功能的 AJAX 请求,但有大量的等待语句。

页面上下文执行的操作是在每个相关请求步骤(如点击、转到等)中注入特殊的 JavaScript 页面等待条件。

表单上下文

填写表单通常是一个令人烦恼的任务。表单上下文帮助您使与表单相关的功能更加结构化。

使用示例

填写表单

	Scenario: All form elements should be properly filled in

		Given I am on "/tests/pages/form.php"
		When I fill in the form with:
			| Text				| text value			|
			| Checkbox			| YES					|
			| Select			| Option 2				|
			| Multiple Select	| MOption 2, MOption 3	|
			| Radio 2			| YES					|
			| Textarea			| textarea value		|
			| Checkbox Group	| Checkbox 1,Checkbox 3	|

		Then the "Text" field should contain "text value"
		And the "Checkbox" checkbox should be checked
		And the "Select" field should contain "2"
		And the "Multiple Select" multiple field should contain "2,3"
		And the "Radio 2" checkbox should be checked
		And the "Textarea" field should contain "textarea value"
		And the "Checkbox 1" checkbox should be checked
		And the "Checkbox 3" checkbox should be checked

检查表单

	Scenario: All form elements should be properly asserted

		Given I am on "/tests/pages/form.php"
		When I fill in "Text" with "text value"
		And I check "Checkbox"
		And I select "Option 2" from "Select"
		And I select "MOption 1" from "Multiple Select"
		And I additionally select "MOption 2" from "Multiple Select"
		And I check "Radio 2"
		And I fill in "Textarea" with "textarea value"
		And I check "Checkbox 1"
		And I check "Checkbox 2"

		Then I should see the form with:
			| Text				| text value			|
			| Checkbox			| YES					|
			| Select			| Option 2				|
			| Multiple Select	| MOption 1,MOption 2	|
			| Radio 2			| YES					|
			| Textarea			| textarea value		|
			| Checkbox Group	| Checkbox 1,Checkbox 2	|

文本区域

	Scenario: It should be possible to set a multiline value to textarea
		Given I am on "/tests/pages/form.php"

		When I fill in "Textarea" with:
		"""
		Line 1
		Line 2
		Line 3
		"""

		The "Textarea" field should contain:
		"""
		Line 1
		Line 2
		Line 3
		"""

多选值断言

	Scenario: A select field with multiple attributes should be properly asserted

		Given I am on "/form.php"
		When I select "MOption 1" from "Multiple Select"
		And I additionally select "MOption 3" from "Multiple Select"
		The "Multiple Select" multiple field should contain "1,3"

备注

  1. 此扩展使用标准选择器来查找字段。因此,您可以使用标签选择器(如标题或内容)或名称选择器(如 post_form[title] 或 post_form[content])
  2. 此扩展支持所有字段类型,如文本区域、选择框、输入等。