Resources to setup a Behat integration in Drupal using a Vagrant Machine

I was working setting up an integration with Behat and Drupal in an environment with Vagrant, this post contains the list of resources that help me to implement the integration.

Introduction to Behat Concepts

This post will explain you the basic things that you need to know about Behat.

Setup for Vagrant Machines

This post will explain how to setup the selenium server to run in the host machine and run the test from the vagrant machine.

General information about Behat

Things that I found in the road.

Curl didn’t work with our homemade SSL cert

I had a validation error with Goutte and our SSL certs since our certs are not “real certs”, we are using home made certs for development. In order to skip the SSL validation we had to add these lines to the behat.yml

        verify: false
            ssl.certificate_authority: false
            verify: false

Issue with the Dependency Injector

I found a weird trouble with the Symfony dependency injector, some constant were not found, googling for the solutions I found that the problem was since the versions of the components. The solution is to force the symfony/dependency-injection to an specific version. For that, in the composer.json of the behat project (not the one of drupal), add these required libraries.

"symfony/dependency-injection": "2.8.2",
"symfony/event-dispatcher": "2.8.2",

Then do a composer update and composer install to download the specific library versions.

Run it with selenium

Once I had all configured I tried to run a Feature and Behat was trying to use the Goutte Client, not selenium. Trying to find why didn’t run in selenium I found that Behat is pretty smart and if you do not need JavaScript capabilities he will just use Goutte Driver (since is faster) but if you need Js support you can define in the feature that you will required that, add this notation on top of your feature, the ones with the @ at the first line.

@javascript @api
Feature: Open Home
  Scenario: Homepage for users

That will indicate to Behat to use Selenium Server.

Chrome Didn’t Opened

Once I have tried to test my feature with Selenium, Chrome didn’t started and I got a nice Java stack trace dump error. Trying to identify the problem I realize that I ran the Selenium Node in the host machine as Root. Be sure that you are running the Servers as the host session user so selenium will be able to open Chrome.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.