Installing WordHat

Requirements

WordHat requires PHP (version 7.0+), Composer, and a WordPress site to test (version 4.8+).

We strongly recommend using WP-CLI1 (version 1.3.0+), and Selenium2 to help with browser automation. Selenium is fiddly to set up, so we recommend using vvo/selenium-standalone, which requires the Java Platform JDK.

Installation

  1. Create a folder for your tests. From a terminal:
    mkdir project
    cd project
  2. Tell Composer to download WordHat:
    composer require --dev paulgibbs/behat-wordpress-extension behat/mink-goutte-driver behat/mink-selenium2-driver
  3. Copy WordHat's sample configuration file into your project folder and rename it:
    cp vendor/paulgibbs/behat-wordpress-extension/behat.yml.dist behat.yml
  4. Edit your behat.yml and:

  5. Initialise Behat:
    vendor/bin/behat --init

    What does this do?

    This creates a features/ folder for your Features (tests), and a new Context class. These will come in handy later!

  6. To confirm that everything is set up correctly, run:
    vendor/bin/behat -dl
    If it worked, you will see a list of text that looks a little like the following (but much longer):
    Given I am an anonymous user
    Given I am not logged in
    Given I am logged in as a user with the :role role(s)
    Given I am logged in as :name
    …

Next steps

Now that you have WordHat set up, we recommend reading our introduction to Behat to help you learn the basics before you start writing tests for your site.


  1. The WP-CLI executable must be named wp and be within your system’s $PATH

  2. Selenium is recommended for testing websites that require Javascript. Behat requires the Mink Selenium2 library, which we include in the installation instructions above.