问题描述
我想知道是否有一种方法可以将不同的上下文类用于不同的功能.
I am wondering if there is a way to use different context classes for different features.
我希望一个功能使用MinkExtensions进行浏览器测试,而另一个功能使用HTTP客户端(如Guzzle)进行API测试-两者都将具有相似的步骤,但实现方式不同.
I would like to have one feature use MinkExtensions for browser testing and another one using and HTTP client like Guzzle for API testing - both would have similar steps with different implementation.
推荐答案
在Behat 3中应该是可行的.请参见 http ://everzet.com/tagged/Behat 特征:支持每个标签,每个目录和每个角色的上下文类的多上下文运行.我一直宣扬的这种角色的重要性"口头禅最终将成为可能.每个角色最终都将拥有自己的步骤字典."
It should be possible in Behat 3. See http://everzet.com/tagged/BehatFeature:"Multi-contextual runs with support for per-tag, per-directory and per-role context classes. This "importance of the role" mantra I was always preaching will finally become possible as each role will eventually be able to have own steps dictionary."
目前,在Behat 2中,您可以使用不同的配置文件来分离功能.在您的behat.yml中,您可能会遇到这样的情况:
For the moment, in Behat 2, you could use different profiles in order to separate the features. In your behat.yml, you could have something like this:
#running login suite using Mink
login-suite:
paths:
features: features/login-suite
bootstrap: features/login-suite/bootstrap
extensions:
mink-extension.phar:
base_url: http://domain.org
formatter:
name: pretty, junit, html
parameters:
output_path: null, logs/login-suite/, logs/login-suite/out.html
#running logout suite using the WebApi
logout-suite:
paths:
features: features/logout-suite/
bootstrap: features/logout-suite/bootstrap/
formatter:
name: pretty, junit, html
parameters:
output_path: null, logs/login-suite/, logs/logout-suite/out.html
extensions:
Behat\WebApiExtension\Extension:
base_url: http://api.domain.org
登录套件和注销套件功能的FeatureContext.php文件现在已分离.
The FeatureContext.php files for the login-suite and logout-suite features are now separated.
问题在于,现在您无法一次运行所有测试.可以使用上下文来做到这一点: http://docs.behat.org/guides/7.config.html#Context
The problem is that now you cannot run all the tests at once. It might be possible to do so using contexts:http://docs.behat.org/guides/7.config.html#Context
这篇关于每个功能的Behat上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!