Trying To Set Up Selenium + Behat On Mac

Richard Knop picture Richard Knop · Jun 5, 2013 · Viewed 8.1k times · Source

So I got Behat working fine with the headless browser, however I wanted to use Selenium 2 to test some JavaScript heavy pages.

When I run vendor/bin/behat, I get this error on the first scenario marked with @javascript:

Curl error thrown for http POST to http://localhost:4444/wd/hub/session with params: {"desiredCapabilities":{"browserName":"firefox","version":"8","platform":"ANY","browserVersion":"8","browser":"firefox","name":"Behat test","deviceOrientation":"portrait","deviceType":"tablet","selenium-version":"2.31.0","max-duration":300},"requiredCapabilities":[]}

      couldn't connect to host

I don't know why it's connecting to a wrong port when I defined 443 in my config file. And why does it say device type is table? Here is my behat.yml:

default:
  paths:
    features: tests/functional/features
    bootstrap: tests/functional/features/bootstrap
  extensions:
    Behat\MinkExtension\Extension:
      base_url: http://myvirtualhost.com
      goutte: ~
      selenium2: ~
  context:
    parameters:
      wd_host: 127.0.0.1:4443/wd/hub
      wd_capabilities: { "browser": "firefox", "version": "21"}

I have Selenium 2 running at 127.0.0.1:4443/wd/hub properly.

I have Firefox version 21 installed.

This is my composer.json, I have the Selenium 2 driver:

{
    "name": "my-website",
    "description": "My Website",
    "minimum-stability": "dev",
    "require": {
        "php": ">=5.3",
        "zendframework/zendframework": "2.1.5",
        "doctrine/common": "dev-master#d7987c96675e153638729383577090feed9854f1"
    },
    "require-dev": {
        "phpunit/phpunit": "3.7.x-dev#19f1d742e0c36150001062f592c93f80aef3a9fd",
        "behat/behat": "dev-develop#1f1bead31e96da5e30fd5d499d5cf66d29b68cf6",
        "behat/mink": "v1.4.3",
        "behat/mink-extension": "dev-master#ef2c8639ebc254f0ff6e555b7834700caf5db9c4",
        "behat/mink-goutte-driver": "dev-master#v1.0.8",
        "behat/mink-selenium2-driver": "v1.0.6"
    }
}

Answer

Jakub Zalas picture Jakub Zalas · Jun 6, 2013

You should configure your wd_host and wd_parameters under the selenium2 section, not parameters:

default:
  extensions:
    Behat\MinkExtension\Extension:
      selenium2:
        wd_host: 127.0.0.1:4443/wd/hub
        capabilities:
          browser: firefox
          version: 21

Double check if wd_host and wd_capabilities are correct parameter names.