3

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 ?

sharan
  • 213
  • 9
  • 17

1 Answers1

7

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.

olga
  • 320
  • 2
  • 9
  • I have tried with BehatContext also . It gives me the same error .... "PHP Fatal error: Call to undefined method FeatureContext::getParameter() in D:\ mypgms\Again\features\bootstrap\FeatureContext.php on line 61" – sharan Jan 03 '14 at 06:12
  • See my edited answer. Don't use getParameter (it doesn't seem to exist and I can't find it from the API docs either), instead save the parameters to a member variable in constructor for later use. – olga Jan 03 '14 at 07:46