我如何在 Behat + Mink 中使用我的 类?
How can I use my classes in Behat + Mink?
我有很大的(1000 多行)FeatureContext class,我想将这个文件分成几个逻辑部分。但我不知道如何在 Behat 中创建自己的 classes。我阅读了文档 http://docs.behat.org/en/v2.5/guides/4.context.html 但我不明白。在文档示例 FeatureContext extends BehatContext 中,但我需要 FeatureContext extends MinkContext,因为没有它 Mink 就无法工作。如果您可以编写我自己的 class 示例以及使用 Mink 的函数并向我展示如何在 FeatureContext 中使用此 class 那会很棒
这个配置应该可以达到你的需要
文件:behat.yml
default:
suites:
yourCustomSuite:
paths:
- %paths.base%/src/your/bundle/name/Features/YourSuiteName
contexts:
- YourBundleName\Contexts\YourContextName
文件:YourBundleName\Contexts\YourContextName.php
class YourContextName extends FeatureContext
{
}
并让 FeatureContext
扩展 \Behat\MinkExtension\Context\MinkContext
我刚刚在 Behat with Mink 中找到了使用子上下文 (类) 的正确方法 http://blog.scur.pl/2012/06/subcontexts-behat-mink/
希望对某人有所帮助
Page object pattern is a way of keeping your context files clean by separating UI knowledge from the actions and assertions.
我在我的项目中使用了 PageObjectsExtension,我的上下文看起来像这样:
/**
* @When /^I order products by "([^"]*)"$/
*
* @param $order
*/
public function orderProductsBy($order)
{
$this->getPage("Catalog")->orderProductsBy($order);
}
在 behat.yml
上配置扩展
SensioLabs\Behat\PageObjectExtension:
namespaces:
page: [NS1\Features\Page, NS2\Features\Page]
element: [NS1\Features\Page\Element, NS2\Features\Page\Element]
如果您需要多个 Contexts
,您可以将其添加到您的 behat.yml
default:
suites:
selenium:
mink_session: selenium
mink_javascript_session: selenium
contexts:
- Namespace\FeatureContext
- Namespace\CatalogContext
- Namespace\CheckoutFinishContext
- Namespace\CheckoutIndexContext
- Namespace\HomeContext
- Namespace\ProductDetailsContext
- Namespace\CartContext
- Namespace\CustomerAccountContext
- Namespace\CustomerLoginContext
- Namespace\FilterContext
- Namespace\TelesalesContext
- Namespace\HelpdeskContext
- Namespace\FaqContext
- Namespace\BrandContext
我有很大的(1000 多行)FeatureContext class,我想将这个文件分成几个逻辑部分。但我不知道如何在 Behat 中创建自己的 classes。我阅读了文档 http://docs.behat.org/en/v2.5/guides/4.context.html 但我不明白。在文档示例 FeatureContext extends BehatContext 中,但我需要 FeatureContext extends MinkContext,因为没有它 Mink 就无法工作。如果您可以编写我自己的 class 示例以及使用 Mink 的函数并向我展示如何在 FeatureContext 中使用此 class 那会很棒
这个配置应该可以达到你的需要
文件:behat.yml
default:
suites:
yourCustomSuite:
paths:
- %paths.base%/src/your/bundle/name/Features/YourSuiteName
contexts:
- YourBundleName\Contexts\YourContextName
文件:YourBundleName\Contexts\YourContextName.php
class YourContextName extends FeatureContext
{
}
并让 FeatureContext
扩展 \Behat\MinkExtension\Context\MinkContext
我刚刚在 Behat with Mink 中找到了使用子上下文 (类) 的正确方法 http://blog.scur.pl/2012/06/subcontexts-behat-mink/ 希望对某人有所帮助
Page object pattern is a way of keeping your context files clean by separating UI knowledge from the actions and assertions.
我在我的项目中使用了 PageObjectsExtension,我的上下文看起来像这样:
/**
* @When /^I order products by "([^"]*)"$/
*
* @param $order
*/
public function orderProductsBy($order)
{
$this->getPage("Catalog")->orderProductsBy($order);
}
在 behat.yml
上配置扩展SensioLabs\Behat\PageObjectExtension:
namespaces:
page: [NS1\Features\Page, NS2\Features\Page]
element: [NS1\Features\Page\Element, NS2\Features\Page\Element]
如果您需要多个 Contexts
,您可以将其添加到您的 behat.yml
default:
suites:
selenium:
mink_session: selenium
mink_javascript_session: selenium
contexts:
- Namespace\FeatureContext
- Namespace\CatalogContext
- Namespace\CheckoutFinishContext
- Namespace\CheckoutIndexContext
- Namespace\HomeContext
- Namespace\ProductDetailsContext
- Namespace\CartContext
- Namespace\CustomerAccountContext
- Namespace\CustomerLoginContext
- Namespace\FilterContext
- Namespace\TelesalesContext
- Namespace\HelpdeskContext
- Namespace\FaqContext
- Namespace\BrandContext