Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get the Parameters from Behat.yml to a php file?

Tags:

php

behat

mink

I have a Behat.yml

  default :
     context :
       parameters :
            user: xyz
            password : abc

Also i have a file called FeatureContext.php which retrieves the values from behat.yml through

   public function iExample($user, $password)
    {
       $userName=$this->getParameter($user);
    }

But it throws an error like

   "Call to undefined method FeatureContext::getParameter()"

Am i missing something ? .. i have also added autoload.php in FeatureContext.php through

   require_once __DIR__.'/../../vendor/autoload.php';

Please let know , if you have any idea why it is happening ?

like image 878
sharan Avatar asked Dec 03 '25 22:12

sharan


1 Answers

Your FeatureContext class has to extend BehatContext and then you get the parameters-array as an argument in the constructor of FeatureContext. See http://michaelheap.com/behat-selenium2-webdriver/ for an example.

Edit:

class FeatureContext extends BehatContext
{
    private $params = array();

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

    public function iExample($user, $password)
    {
        $userName = $this->params['user'];
    }
}

I haven't used Behat for a while, but you probably get the idea.

like image 121
olga Avatar answered Dec 06 '25 14:12

olga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!