Behat, simplest test using only blackbox driver

There is not much documentation and examples of drupal with behat test, so I will start with simplest. I will assume you have installed

- drupal 8 website and up and running server
- installed behat library
- installed drupal behat extension https://www.drupal.org/project/drupalextension
- have basic knowledge how behat works

and that is it.

You will write this test as FirstTest.feature, add it into your drupal_root/features/ directory and then in the same drupal_root run "vendor/bin/beaht --init" which will auto create FeatureContext.php class in features/bootstrap.

in your  FirstTest.feature 

Feature: First test
  My first Behat try. Be patient :)

  Scenario: The Drupal installer should enable the footer block
    Given I am an anonymous user
    Given I am on the homepage
    Then I should see "Powered by Drupal"

Which should do exactly what it says, check your drupal installation for "Powered by drupal" block. I recommend you run this test with drush cutie installation http://drupaldump.com/drush-cutie-about-minute-install-full-instance-dr… or any fresh drupal installation.

After that, add a behat.yml file in drupal_root (whatever your drupal root path is) and fill it with:

default:
  suites:
    default:
      contexts:
        - FeatureContext
        - Drupal\DrupalExtension\Context\DrupalContext
        - Drupal\DrupalExtension\Context\MinkContext
        - Drupal\DrupalExtension\Context\MessageContext
        - Drupal\DrupalExtension\Context\DrushContext
  extensions:
    Behat\MinkExtension:
      goutte: ~
      selenium2: ~
      base_url: http://127.0.0.1:8888
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'blackbox'

What is what check with behat config manual, important thing is we are using "blackbox" driver which comes frome behat drupal extension, which is enough for running our test.  More info and examples here http://behat-drupal-extension.readthedocs.io/en/3.1/blackbox.html

With all that we can go to drupal_root again and type 

vendor/bin/behat and out test will be run.

and  you should get output like this. Simple but fun. We didn't write any PHP code as we are using all the steps available out of the box which comes as part of integration of Behat Drupal extension library. For more advanced things we will need to write some PHP methods, but that is a case for another tutorial.
 

?  ~/Drupal/test/quick-drupal-20171108105658/drupal : vendor/bin/behat
Feature: First test
  My first Behat try. Be patient :)

  Scenario: The Drupal installer should enable the footer block # features/bootstrap/first.feature:4
    Given I am an anonymous user                                # Drupal\DrupalExtension\Context\DrupalContext::assertAnonymousUser()
    Given I am on the homepage                                  # Drupal\DrupalExtension\Context\MinkContext::iAmOnHomepage()
    Then I should see "Powered by Drupal"                       # Drupal\DrupalExtension\Context\MinkContext::assertPageContainsText()

1 scenario (1 passed)
3 steps (3 passed)