Loading...
BehatTest Automation

Installing Behat from scratch!

Hey guys,

I’ve been coaching Behat and relevant tech’s for some time now. Think it be good to share the information out to you start to finish.

I love Behat as an automation testing tool and also as a requirement exploration tool.

So we’re about to cover:

  • Installing Behat.
  • Running Behat for the first time.
  • Writing a feature file.
  • Running a test against a simple website such as wikipedia.

Pre-requisites:

  • Composer
  • PHP 5.4+

Installing Behat:

Plenty of tutorials out there to let you know how this goes. Simply run composer require behat/behat to get the latest version of behat installed. But since we’re interested in running our test against a website it may be worth installing a few different libraries on top.

Lets start from the very beginning. Create a directory where  you want to have your project. Lets have it in the home directory. Create a new folder there.

$_ cd && mkdir my-first-test && cd my-first-test;

Create your composer.json file in the “my-first-test” folder as below:

{
    "require": {
        "behat/behat": "~3.0@stable",
        "behat/mink": "*@stable",
        "behat/mink-extension": "~2.0@stable",
        "behat/mink-goutte-driver": "@stable",
        "fabpot/goutte": "~1.0@stable",
        "genesis/behat-fail-aid": "~1.0",
        "ext-curl": "*",
        "ext-dom": "*"
    },
    "config": {
        "bin-dir":"vendor/bin/"
    }
}

Then run

$_ composer install

This should install Behat and all relevant packages to get us started.

Zoopa Tip!: Note that we’ve got ext-* rules in our composer.json file. This is to ensure that whoever runs the above composer file once you distribute amongst your team has the required php dependencies installed.

Next you need to verify that Behat has installed correctly and run the scaffolding command.

$_ vendor/bin/behat –version

This should output something like “behat 3.4.3”, at least it does now. Next run the scaffold command.

Thats pretty much, you’re all set now.

Next “Behat 101”>>

Handle failures like a pro >>

Leave a Reply