WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

Behat testing and Drupal

Submitted by barnettech on Wed, 06/03/2015 - 17:32

1.)  https://behat-drupal-extension.readthedocs.org/en/3.0/globalinstall.html

2.)    in the sites/default/behat-tests folder you'll need to create run the command:  behat -dl to see available out of the box commands

3.)  Run behat --init in the behat-tests folder

4.)  More documentation is here

5.)  In the sites/default/behat-tests folder make a behat.yml file:

 

* another good blog on creating your own gherkin https://www.previousnext.com.au/blog/custom-step-definitions-drupal-dru…

* https://davidwinter.me/testing-javascript-websites-with-behat/

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://drupal7/
    Drupal\DrupalExtension:
      blackbox: ~
      api_driver: 'drupal'
      drush:
        alias: 'drupal7'
      drupal:
        drupal_root: '/Users/jbarnett/Sites/drupal7/drupal7'
      region_map:
        content: "#content"
        footer: "#footer"
        left header: "#header-left"
        right header: "#header-right"
        right sidebar: "#column-right"
      selectors:
        message_selector: '.messages'
        error_message_selector: '.messages.messages-error'
        success_message_selector: '.messages.messages-status'

example behat test:

Feature: login
  In order to test that logging in
  as an admin user
  I can run some tests
@api
Scenario: Messages
   Given I am logged in as a user with the "administrator" role
   When I click "Add content"
   Then I should see the text "Article"