Skip to content

BDD : Behat with PHP using Visual Studio Code on Windows

Behat is a one of the BDD tools.It’s something like Cucumber which allows you to easily test Business scenarios and flows.

Let us see here how to setup Behat with Php using Visual Studio Code

Step 1: Install Composer

Step 2: Then run the below command
php C:\xampp\htdocs\composer.phar require –dev behat/behat

Step 3: Then initiate BeHat by using the below command

vendor/bin/behat –init


Step 4: After adding the Steps files by placing the function under FeatureContext.php, run the Behat testcases by executing the below script

You will get a result as shown above.

Here are my feature files and steps files

Feature: Test1

Scenario: Testing1
    Given I am on the homepage of Google

use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;

 * Defines application features from the specific context.
class FeatureContext implements Context
     * Initializes context.
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
    public function __construct()

     * @Given I am on the homepage of Google
    public function iAmOnTheHomepageOfGoogle()
        return $a1;