Question

We're using behat to run some functional tests on our system, simulating the journey of a user through our site. I've written some Contexts with definitions of things to check.

Because behat will be running on different environments (our dev PCs, then our staging server...) the @BeforeSuite function that runs needs different settings. I'd put them in behat.yml, with custom profiles, but I don't know how to read that information

So, what I'm asking is how can I get to the behat config info within my context file?

Was it helpful?

Solution

Parameters configured in behat.yml are injected into the main context file via a constructor (in Behat 2):

class FeatureContext extends BehatContext
{
    private $parameters;

    public function __construct(array $parameters)
    {
        $this->parameters = $parameters;
    }
}

However, since you use @BeforeSuite, context instance is not yet available (and hook method is static).

You can still fetch parameters from the event:

class FeatureContext extends BehatContext
{ 
    /** @BeforeSuite */
    public static function setup(SuiteEvent $event)
    {
        $parameters = $event->getContextParameters();
    }
}

Related docs: http://docs.behat.org/guides/3.hooks.html#suite-hooks

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