Did you miss Part 1?
Behat is a tool you can use to automate testing of your website with behaviour driven tests.

Sample FeatureContext.php

The FeatureContext.php is the file holding your custom test commands. In your file structure, it is at D:\Behat\features\bootstrap\FeatureContext.php.
This is what mine looks like. Including in full because this was one piece of the puzzle that caused stress for me. For a vanilla file, remove all functions after __construct().

<?php
use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\MinkContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
 * Defines application features from the specific context.
 */
class FeatureContext extends MinkContext 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()
    {

    }

    /**
     * @When I wait for :text to appear
     * @Then I should see :text appear
     * @param $text
     * @throws \Exception
     */
    public function iWaitForTextToAppear($text)
    {
        $this->spin(function(FeatureContext $context) use ($text) {
            try {
                $context->assertPageContainsText($text);
                return true;
            }
            catch(ResponseTextException $e) {
                // NOOP
            }
            return false;
        });
    }


    /**
     * @When I wait for :text to disappear
     * @Then I should see :text disappear
     * @param $text
     * @throws \Exception
     */
    public function iWaitForTextToDisappear($text)
    {
        $this->spin(function(FeatureContext $context) use ($text) {
            try {
                $context->assertPageContainsText($text);
            }
            catch(ResponseTextException $e) {
                return true;
            }
            return false;
        });
    }

    /**
     * Based on Behat's own example
     * @see https://docs.behat.org/en/v2.5/cookbook/using_spin_functions.html#adding-a-timeout
     * @param $lambda
     * @param int $wait
     * @throws \Exception
     */
    public function spin($lambda, $wait = 30)
    {
        $time = time();
        $stopTime = $time + $wait;
        while (time() < $stopTime)
        {
            try {
                if ($lambda($this)) {
                    return;
                }
            } catch (\Exception $e) {
                // do nothing
            }

            usleep(5000);
        }

        throw new \Exception("Spin function timed out after {$wait} seconds");
    }

    /**
     * @Then page should have body class :text 
     * @param $text
     * @throws \Exception
     */
    public function pageShouldHaveBodyClass($text)
    {
        $session = $this->getSession();
        $page = $session->getPage();
        $el = $page->find('css', 'body');
        try {
            $outer = $el->getOuterHtml();
            if ($el->hasClass($text)) {
                return;
            }
        } catch (\Exception $e) {
            // do nothing
        }

        throw new \Exception ("Body does not have {$text} class.");
    }
}

Sample Feature File

Your feature file holds your tests. Best practice is to have one feature file per feature of your site. e.g. recipes.feature
If you put @javascript on the first line, Behat will attempt to run the tests with Selenium -> Firefox. Otherwise Behat will run the tests with Goutte. Note: Goutte runs tests MUCH faster than Firefox does. Don’t be put off by the weird name. Give Goutte a try.

@recipes 
 Feature: 
  Publish my best recipes

 @cake
 Scenario: Cake main page
  Given I go to "https://mysite/cake"
  Then I should see "Torte"
  And I should see "Muffin"
  And I should see "Sponge"

Don’t forget, you can type “behat -dl” at the command line to see all the commands that are enabled by Mink Extension.

Run your tests

From the command line at D:\Behat, all you need to do is type “behat” and all tests in your feature files will run.
Use

--tag

to limit which feature files run. e.g.

behat --tags=recipes

combined with @recipes at the start of the feature file will select those tests only.


Let me know if this helped you test with Behat in the comments below.