我想知道是否有一种方法可以为不同的功能使用不同的上下文类。
我希望有一个功能使用 MinkExtensions 进行浏览器测试,另一个功能使用和 HTTP 客户端(如 Guzzle)进行 API 测试 - 两者都有类似的步骤和不同的实现。
最佳答案
在 Behat 3 中应该是可能的。见 http://everzet.com/tagged/Behat
特征:
“支持按标签、按目录和按角色的上下文类的多上下文运行。我一直宣扬的“角色的重要性”口号最终将成为可能
每个角色最终都能拥有自己的步骤字典。”
目前,在 Behat 2 中,您可以使用不同的配置文件来分离功能。在你的 behat.yml 中,你可以有这样的东西:
#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
login-suite 和 logout-suite 功能的 FeatureContext.php 文件现在是分开的。
问题是现在你不能一次运行所有的测试。使用上下文可能会这样做:
http://docs.behat.org/guides/7.config.html#Context
关于每个功能的 Behat 上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19565506/