Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top