0

I was just trying to follow the http://docs.behat.org/cookbook/behat_and_mink.html tutorial

I installed Mink+Behat using the following composer.json:

    "require": {
        "behat/behat": "2.4.*@stable",
        "behat/mink": "1.4.*@stable",
        "behat/mink-extension": "*",
        "behat/mink-goutte-driver": "*",
        "behat/mink-selenium2-driver": "*"
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}

I did the init that created the features directory.

bin/behat --init

I created a search.features in the features directory:

Feature: Search
  In order to see a word definition
  As a website user
  I need to be able to search for a word

  Scenario: Searching for a page that does exist
    Given I am on "/wiki/Main_Page"
    When I fill in "search" with "Behavior Driven Development"
    And I press "searchButton"
    Then I should see "agile software development"

  Scenario: Searching for a page that does NOT exist
    Given I am on "/wiki/Main_Page"
    When I fill in "search" with "Glory Driven Development"
    And I press "searchButton"
    Then I should see "Search results"

I updated the features/bootstrap/FeatureContext.php to extend MinkContext.

If i run bin/behat -dl i see the following definitions loaded:

Given /^(?:|I )am on (?:|the )homepage$/
 When /^(?:|I )go to (?:|the )homepage$/
Given /^(?:|I )am on "(?P<page>[^"]+)"$/
 When /^(?:|I )go to "(?P<page>[^"]+)"$/
 When /^(?:|I )reload the page$/
 When /^(?:|I )move backward one page$/
 When /^(?:|I )move forward one page$/
 When /^(?:|I )press "(?P<button>(?:[^"]|\\")*)"$/
 When /^(?:|I )follow "(?P<link>(?:[^"]|\\")*)"$/
 When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with "(?P<value>(?:[^"]|\\")*)"$/
 When /^(?:|I )fill in "(?P<field>(?:[^"]|\\")*)" with:$/
 When /^(?:|I )fill in "(?P<value>(?:[^"]|\\")*)" for "(?P<field>(?:[^"]|\\")*)"$/
 When /^(?:|I )fill in the following:$/
 When /^(?:|I )select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
 When /^(?:|I )additionally select "(?P<option>(?:[^"]|\\")*)" from "(?P<select>(?:[^"]|\\")*)"$/
 When /^(?:|I )check "(?P<option>(?:[^"]|\\")*)"$/
 When /^(?:|I )uncheck "(?P<option>(?:[^"]|\\")*)"$/
 When /^(?:|I )attach the file "(?P[^"]*)" to "(?P<field>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should be on "(?P<page>[^"]+)"$/
 Then /^(?:|I )should be on (?:|the )homepage$/
 Then /^the (?i)url(?-i) should match (?P<pattern>"([^"]|\\")*")$/
 Then /^the response status code should be (?P<code>\d+)$/
 Then /^the response status code should not be (?P<code>\d+)$/
 Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should see text matching (?P<pattern>"(?:[^"]|\\")*")$/
 Then /^(?:|I )should not see text matching (?P<pattern>"(?:[^"]|\\")*")$/
 Then /^the response should contain "(?P<text>(?:[^"]|\\")*)"$/
 Then /^the response should not contain "(?P<text>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/
 Then /^(?:|I )should not see "(?P<text>(?:[^"]|\\")*)" in the "(?P<element>[^"]*)" element$/
 Then /^the "(?P<element>[^"]*)" element should contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^the "(?P<element>[^"]*)" element should not contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^(?:|I )should see an? "(?P<element>[^"]*)" element$/
 Then /^(?:|I )should not see an? "(?P<element>[^"]*)" element$/
 Then /^the "(?P<field>(?:[^"]|\\")*)" field should contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^the "(?P<field>(?:[^"]|\\")*)" field should not contain "(?P<value>(?:[^"]|\\")*)"$/
 Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should be checked$/
 Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" (?:is|should be) checked$/
 Then /^the "(?P<checkbox>(?:[^"]|\\")*)" checkbox should not be checked$/
 Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" should (?:be unchecked|not be checked)$/
 Then /^the checkbox "(?P<checkbox>(?:[^"]|\\")*)" is (?:unchecked|not checked)$/
 Then /^(?:|I )should see (?P<num>\d+) "(?P<element>[^"]*)" elements?$/
 Then /^print current URL$/
 Then /^print last response$/
 Then /^show last response$/

But I try to actually test the search.features , i get the error:

PHP Fatal error:  Call to a member function getSession() on a non-object in /home/nishant/behat/vendor/behat/mink-extension/src/Behat/MinkExtension/Context/RawMinkContext.php on line 103

I did a Google of what the error could be, but didnot find anything more useful that telling to put the behat.yml in the right place.

My bin/behat -> ../vendor/behat/behat/bin/behat is this symlink and i have tried putting behat.yml in vendor/behat/behat/behat.yml. content on behat.yml

default:
    extensions:
        Behat\MinkExtension\Extension:
            base_url: http://en.wikipedia.org
            goutte: ~
            selenium2: ~

Any help would be much appreciated!!

If I go to vendor/behat/behat and create the search.feature and run bin/behat I get the error:

  [ReflectionException]
  Class Guzzle\Http\Client does not exist
rsjaffe
  • 5,600
  • 7
  • 27
  • 39
  • 2
    Please give your question a suitable title. And no, "Behat mink - newbie" is **not** suitable. The tags should be removed from the title and the remaining "newbie" word should be replaced by something describing your actual problem. – JensG May 31 '14 at 20:19

1 Answers1

4

Ok.. i managed to fix my problem !

Added these lines in my __construct() method in features/bootstrap/FeatureContext.php

$clientOptions = array();
$client = new \Behat\Mink\Driver\Goutte\Client();
$client->setClient(new \Guzzle\Http\Client('', $clientOptions));
$driver = new \Behat\Mink\Driver\GoutteDriver($client);

Also updated my composer.json to

{
    "require": {
        "behat/behat": "2.4.*@stable",
        "behat/mink": "1.4.*@stable",
        "behat/mink-extension": "*",
        "behat/mink-goutte-driver": "1.0.*",
        "behat/mink-selenium2-driver": "*",
        "guzzle/http": "*"
    },
    "minimum-stability": "dev",
    "config": {
        "bin-dir": "bin/"
    }
}
  • I didn't require those lines in my __construct() method, however, I did have this in my behat.yml file: `default_session: goutte`. Its possible they do the same thing. – zkent Aug 15 '16 at 16:26