Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sandersjj's avatar

Running Behat with Selenium2Driver in combination with Homestead

I have a Homestead installation running with Behat to test my Laravel project. I am running into some problems when using the @javasccript tag to run my tasks as Selenium.

I have downloaded Selenium standalone server on my Windows host machine. Its version is 2.42.2

In my behat.yml i have got the following configuration:

default:
    extensions:
     Behat\MinkExtension:
         base_url: http://my.app:8000/
         sessions:
            default_session:
                goutte: ~
            selenium_session:
                selenium2:
                      wd_host: http://x.x.x.x:4444/wd/hub/static/resource/hub.html
    suites:
        functional:
            paths:    [ %paths.base%/features/functional ]
            contexts: [ LaravelFeatureContext ]

However when I run my scenarios I get the following error:

Given I am on the "/users/create" page # LaravelFeatureContext::iAmOnThePage() Could not open connection: Curl error thrown for http POST to http://x.x.x.x:4444/wd/hub/static/resource/hub.html/session with params: {"desiredCapabilities":{"tags":["homestead","PHP 5.6.0-1+deb.sury.org~trusty+1"],"browserName":"firefox","version":"21","platform":"ANY","browserVersion":"9","browser":"firefox","ignoreZoomSetting":"false","name":"Behat feature suite","deviceOrientation":"portrait","deviceType":"tablet"}}

  Failed to connect to 127.0.0.1 port 4444: Connection refused (Behat\Mink\Exception\DriverException)

When i go to http://x.x.x.x:4444/wd/hub/static/resource/hub.html I see that the selenium hub is up and running.

Could the issue here be that I am running Behat from the homestad terminal through SSH and that does not resolve to the IP address of the hub? Because the ip address of the host is localhost

How can I solve this?

It has something to do with the fact that Mink is starting a firefox session on the Homestead box in stead of on the Host box.

0 likes
2 replies
mad93's avatar

If you want to have access to your host machine from your guest vagrant machine you should create a internal network to allow to connect to each other.

You can set it in your Vagrantfile, as example: config.vm.network :private_network, ip: "192.168.50.4"

Where your guest machine will have the ip, 192.168.50.4 and your host machine will have the ip 192.168.50.1

Please or to participate in this conversation.