Search code examples
seleniumbehatmink

I can't connect to my site using Behat (but a browser is fine)


I've just started playing around with Behat, and I was loving it. Then I shut down my computer and went home for the day and when I came back, nothing worked for me any more. I've been trying to trouble-shoot this, but looks like the configurations vary so widely, I can't find anything that works for me. I'm getting the following error

Given I am on the homepage                  # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
      Could not open connection: Curl error thrown for http POST to http://localhost:4444/wd/hub/session with params: {"desiredCapabilities":{"tags":["rio","PHP 5.5.9-1ubuntu4.9"],"browser":"firefox","version":"14","ignoreZoomSetting":false,"name":"Behat feature suite","browserName":"firefox"}}

      The requested URL returned error: 500 Server Error (Behat\Mink\Exception\DriverException)

I've got my behat.yml file setup as such:

default:
default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
  extensions:
    Behat\MinkExtension:
      base_url: http://localhost:80/vic
      goutte: ~
      default_session: selenium2
      browser_name: 'firefox'
      selenium2:                    
        capabilities: { "browser": "firefox", "version": "14"}
      javascript_session: selenium2
    Drupal\DrupalExtension:
      blackbox: ~
      drush:
        root: /var/www/html/vic
      api_driver: 'drupal'
      drupal: 
        drupal_root: '/var/www/html/vic'

Like I said, this was previously working just fine. Now I don't know why it stopped. The error is weird to me too. the base url doesn't seem to be registering and I have no idea why it's pulling up port 4444 or going to the folder structure wd/hub/session.

Some background. I'm running this on my local machine on a local environment. I'm on a Linux box. The base url works for me in my browser, but Behat can't seem to reach it, and it's adding a weird port (should be 80), and path. It worked the other day, and nothing has changed other than a reboot (so I need to start up a service or something)?


Solution

  • Found the answer. Make sure selenium is running first.

    java -jar selenium-server-standalone-2.45.0.jar (make sure your version is right)
    

    Once it's running it'll give you connection info, make sure that matches in your behat.yml

      extensions:
        Behat\MinkExtension:
          base_url: http://localhost:80
          goutte: ~
          javascript_session: selenium2
          default_session: selenium2
          browser_name: 'firefox'
          selenium2:                    
            capabilities: { "browser": "firefox", "version": "14"}
            wd_host: http://127.0.0.1:4444/wd/hub
    

    ^^ do that by pointing the wd_host to the selenium instance