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.

https://www.lullabot.com/articles/an-overview-of-testing-in-drupal-8

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.

https://www.lullabot.com/articles/running-behat-tests-in-a-vagrant-box

General information about Behat

https://www.phparch.com/2016/08/testing-your-drupal-site-with-behat/

http://docs.behat.org/en/v2.5/quick_intro.html

http://docs.behat.org/en/latest/guides.html

http://docs.behat.org/en/v2.5/guides/1.gherkin.html

https://behat-drupal-extension.readthedocs.io/en/3.1/index.html#

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

extensions:
  Behat\MinkExtension:
    goutte:
      guzzle_parameters:
        verify: false
    sessions:
      default:
        goutte:
          guzzle_parameters:
            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.

0 comments on “Resources to setup a Behat integration in Drupal using a Vagrant MachineAdd yours →

Leave a Reply

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