Behat context per feature

泄露秘密 提交于 2019-12-06 04:17:52

问题


I am wondering if there is a way to use different context classes for different features.

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.


回答1:


It should be possible in Behat 3. See http://everzet.com/tagged/Behat Feature: "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."

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

The FeatureContext.php files for the login-suite and logout-suite features are now separated.

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



来源:https://stackoverflow.com/questions/19565506/behat-context-per-feature

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!