Installing Behat on Windows
Behat for everyone
By Frank Ralf
After reading "Generic Web Behat Test Setup" and "Setting up Behat on Windows" I thought I give it try and install Behat on my Windows machine without resorting to Cygwin. I'm using XAMPP 1.7.7 on Windows 7 (64 bit).
Install Composer
The first thing you have to do is installing Composer, a dependency manager for PHP which will take care of installing Behat and all its dependencies. Installing Composer on Windows is quite easy as there is an installer available.
- Download the Windows installer from http://getcomposer.org/download/.
- Run the installer. Composer will look for a php.exe file and check your PHP version.
- Composer will modify your system path variable so that you can run Composer from any directory.
You now should be able to run Composer from any directory. This will give you the following output.
Create a Behat directory
Behat is an independent PHP command line tool so it need not be installed on your web server. I prefer installing it separately in a directory from which I also run batch scripts and the like, e.g. C:\myprograms. (You better do not install Behat in the usual C:\Program Files folder as Windows is quite strict regarding write access to this folder.)
Create a composer.json file
I took just the one recommended at http://docs.behat.org/cookbook/behat_and_mink.html and put it in C:\myprograms\behat:
{<br> "require": {<br> "behat/behat": "2.4.*@stable",<br> "behat/mink": "1.4.*@stable",<br> "behat/mink-extension": "*",<br> "behat/mink-goutte-driver": "*",<br> "behat/mink-selenium2-driver": "*"<br> },<br> "minimum-stability": "dev",<br> "config": {<br> "bin-dir": "bin/"<br> }<br>}
Run Composer to install Behat
Now you can give it a try and run composer from the Behat directory:
C:\myprograms\behat>composer install
Chances are that you get the following error message:
So we now know that Composer fetches files via Git so your shell must be aware of Git. So let's give it another try, this time using a Git shell (in my case the Windows PowerShell).
This time Composer complains about the missing PHP Curl extension. I checked my php.ini file and the line extension=php_curl.dll
was commented out. So I uncommented it.
Now we get a bit further but this time it's the missing OpenSSL extension which throws an error. So I also uncomment the line extension=php_openssl.dll
Requirements
The information regarding the requirements for running Behat differ slightly but these are the ones which finally got me going on Windows:
- PHP 5.3.1
- Git
- PHP Curl extension
- PHP OpenSSL extension
See also http://www.dspeak.com/drupalextension/requirements.html
Add Behat path to your system path variable
A last step is required to be able to run Behat from any directory, namely your Behat project directories: add the Behat path to your system path variable. The path should point to Behat's bin directory: "C:\myprograms\behat\bin". Now Behat could be run from anywhere. If you give it a try and just run behat you probably will see something like this:
That's because you probably haven't run Behat from a Behat project directory. Better try behat --help or behat --version to see that you indeed installed Behat correctly.
Next steps
Now that you have set up Behat on your local Windows machine you can run your first Behat test. I would suggest trying the example from http://comm-press.de/en/blog/generic-web-behat-test-setup.
Further resources
- Official Behat documentation: http://docs.behat.org
- Behat Cheat Sheet: http://blog.lepine.pro/wp-content/uploads/2012/03/behat-cheat-sheet-en.pdf