Behat on Drupal projects - evolve or die with your manual testing

Artem Miroshnyk

Web Developer

Propeople

Manual testing of websites

and its problems

Most of the QA (developers as well) actions are clicking, typing, visual analysing, thinking

How could we speed up clicking and typing?

Developers has a secret!

Lets count how much time is required to test feature e.g. Drupal.org search

Retest that feature

Retest all those features

Obvious problems:

  • Lack of reusability 
  • Lack of experience sharing
  • Human factor
  • Developers should not need QA after first feature approvement

Do you cover you codefeature with tests?

Developer

 library | service |back-end module

PHPUnit (*Unit)

Anything else
Functional tests on Gherkin (Behat for PHP)

Do you write technical specification for you projects?

 

Write it on Behat

 

Technical Spec, BDD, Test coverage

Meet the Behat&Mink!

Goutte

Example

@api @custom_hint
Feature: Custom hints
  In order to provide/get more information about elements
  As any top malmo admin and administrator
  I should be able to add hints to any page element
  As any user i should be able to see hints

  @api @javascript
  Scenario: Check ability to add and see hints
  Given I am logged in as a user with the "administrator" role
    And I am on "admin/structure/mal-hint"
    And I fill in "edit-hints-items-0-selector" with ".pane-menu-menu-global-menu .pane-title"
    And I fill in "edit-hints-items-0-hint" with "Test hint"
    And I press "Save"
    Then I am on the homepage
    And I hover over the element ".hint"
    And I should see the text "Test hint"

Great integration with Drupal as a CMS


# Add new user with given role and sign in
And I am logged in as a user with the "administrator" role


# Create user with given name and email then create node with given fields
Given users:
    | name     | mail            | status |
    | Joe User | joe@example.com | 1      |
And "article" nodes:
    | title          | author   | body             | promote |
    | Article by Joe | Joe User | PLACEHOLDER BODY | 1       |




Great integration with Drupal as framework with own API

  /**
   * @Given /^I am viewing (?:a|an) "(?P<type>[^"]*)" node with the title "(?P<title>[^"]*)"$/
   * @Given /^(?:a|an) "(?P<type>[^"]*)" node with the title "(?P<title>[^"]*)"$/
   */
  public function createNode($type, $title) {
    $node = (object) array(
      'title' => $title,
      'type' => $type,
      'body' => $this->getDrupal()->random->string(255),
    );
    // Run hooks
    $this->dispatcher->dispatch('beforeNodeCreate', new EntityEvent($this, $node));
    $saved = $this->getDriver()->createNode($node);
    $this->dispatcher->dispatch('afterNodeCreate', new EntityEvent($this, $saved));
    $this->nodes[] = $saved;

    // Set internal page on the new node.
    $this->getSession()->visit($this->locatePath('/node/' . $saved->nid));
  }

Some examples from real project

Future

Behat 3.x.x

Pluggable contexts

Full coverage of Drupal modules