automation in drupal

57
Automation in Drupal by Bozhidar Boshnakov

Upload: bozhidar-boshnakov

Post on 22-Jun-2015

164 views

Category:

Software


0 download

DESCRIPTION

In this session we will cover as much as possible the following topics: - Quick intro to TDD (Test-Driven Development) and BDD (Behavior-Driven Development) - Gherkin - Behat - Mink - Drupal extension with Drush integration - Acceptance criteria - Demonstrations and show cases

TRANSCRIPT

Page 1: Automation in Drupal

Automation in Drupalby Bozhidar Boshnakov

Page 2: Automation in Drupal

About me

• Bozhidar Boshnakov• Team leader @ ProPeople• [email protected]• Skype: bo6nakov• Drupal.org – bboshnakov• linkedin.com/in/bboshnakov

Page 3: Automation in Drupal

Table of contents• TDD – Test-Driven Development• BDD – Behavior-Driven Development• Gherkin• Behat• Mink• Drupal extension• Acceptance criteria• Demonstrations and show cases

Page 4: Automation in Drupal

INTELLIGENCE IS

A LIABILITY!

Page 5: Automation in Drupal

SMART PEOPLE

Can make progress …… without process

This is not a good thing !!!

Page 6: Automation in Drupal

Professionals• Design, plan and prepare first• …then do the work

• This produces better results FASTER !!!

Page 7: Automation in Drupal

Process is the difference between

Software Engineering & Programming

Page 8: Automation in Drupal

In order to verify application behaviorAs a software developer

I need tests

Preferably automated tests

Page 9: Automation in Drupal

Test-Driven Development

• Write a test• Ensure the new test fails• Write code to satisfy the test• Ensure all tests pass• Refactor• Repeat

…is an iterative design process

Page 10: Automation in Drupal

Behavior-Driven Development

• Write test cases in a natural language– Understood by developers and business folks alike– Helps relate domain language of requirements to

the code• Do this with user stories and scenarios– User stories describe a feature’s benefit in context– Scenarios are executable acceptance criteria

…builds upon TDD

Page 11: Automation in Drupal

GherkinGherkin is a Business Readable, Domain Specific Language created especially for behavior descriptions. It gives you the

ability to remove logic details from behavior tests.

Page 12: Automation in Drupal

Gherkin Syntax

Page 13: Automation in Drupal

Gherkin Syntax

Feature: Banana CalculatorAs Bob the Banana merchant,I want a calculator that can add the amount of bananas so that I can know how many bananas I currently haveScenario: Will add 2 banana amounts Given I have 3 Bananas When I add 5 Bananas Then I should have 8 Banana

Page 14: Automation in Drupal
Page 15: Automation in Drupal

This is where

and come in

Page 16: Automation in Drupal

Behat is an open source behavior-driven development framework for

PHP 5.3 and 5.4.

Page 17: Automation in Drupal

The simplest way to install Behat is through

Composer.

Before you begin, ensure that you have at least PHP 5.3.1 installed.

Page 18: Automation in Drupal

Composer.json{ "require": { "behat/mink": "*", "behat/mink-goutte-driver": "*", "behat/behat": "*", "behat/mink-extension": "*", "drupal/drupal-extension": "*" }, "minimum-stability": "dev", "config": { "bin-dir": "bin/" }}

Page 19: Automation in Drupal

Composer.phar

Then download composer.phar and run install command:

$ curl http://getcomposer.org/installer | php$ php composer.phar install

Page 20: Automation in Drupal

Behat.ymldefault: extensions: Behat\MinkExtension\Extension: base_url: http://wearepropeople.com goutte: ~ selenium2: ~ paths: features: features bootstrap: features/bootstrap

Page 21: Automation in Drupal

And the last step…

php bin/behat --init

And now you have your Features folder where you can create the magic!!!

Page 22: Automation in Drupal

What are the features?

Page 23: Automation in Drupal

Let's Have Behat Analyze Our Feature

Page 24: Automation in Drupal

Behat Creates the Glue...but the rest is up to you

Page 25: Automation in Drupal

Not so fast. What about Mink?

Page 26: Automation in Drupal

Understanding Mink

One of the most important parts in the web is a browser. A browser is the window through which web application users interact with the application and other users.

Page 27: Automation in Drupal

Headless browser

emulatorsVS Browser

controllers

Page 28: Automation in Drupal

Selenium2Driver

• Control the Browser – Session• Cookies and Headers management• HTTP Authentication• Traverse the Page - Selectors• Manipulate the Page

Page 29: Automation in Drupal

Mink Context Defines Steps...for making requests

Page 30: Automation in Drupal

Mink Context Defines Steps...for interacting with forms

Page 31: Automation in Drupal

Mink Context Defines Steps...for querying the DOM

Page 32: Automation in Drupal

Mink Context Defines Steps...for examining responses

Page 33: Automation in Drupal

Now…Let’s get away from the theory and show some

action!

Page 34: Automation in Drupal

TagsTags are a great way to organize your features and scenarios:

A Scenario or Feature can have as many tags as you like, just separate them with spaces:

Page 35: Automation in Drupal

TagsHow to execute the tags?

If a tag exists on a Feature, Behat will assign that tag to all child

Scenarios and Scenario Outlines too!

Page 36: Automation in Drupal

Behat.yml

All configuration happens inside a single configuration file in the

YAML format.

Page 37: Automation in Drupal

Imports…or share your feature configurations

Page 38: Automation in Drupal

Profiles

$bin/behat –p google features/feature1

Page 39: Automation in Drupal

The Drupal extension• Overrides default behaviors:

– Snippets follow Drupal coding standards– Mink Extension steps get synonyms for readability

• Provides drivers to facilitate data setup– Blackbox– Drush– Drupal API

• Adds support for Drupal:– Regions– Node types– Users and Roles– Taxonomy– Subcontexts for Contributed Modules

Page 40: Automation in Drupal

Provides drivers for data set up

• Works with Drupal 6, 7, and 8• Connect with no privileges (local or remote)• Connect with Drush (local or remote)• Connect with the Drupal API (local only)

Page 41: Automation in Drupal

About data setup• Every scenario must be able to run

independent of other scenarios• Often work with a fresh copy of the

production database• Can’t always assume the database has specific

content• Separate architectural elements from content

elements• Insert data to get reliable checks

Page 42: Automation in Drupal

Drush: alias file

http://drush.ws/examples/example.aliases.drushrc.php

Page 43: Automation in Drupal

Drush: behat.yml

Page 44: Automation in Drupal

Drupal API: behat.yml

Page 45: Automation in Drupal

Region map: behat.yml

Page 46: Automation in Drupal

RegionsRequires a map in the behat.yml file

• label => css selector• This means regions don’t have to map directly to

Drupal theme regions

Page 47: Automation in Drupal

Structure > Blocks > (Theme) > Demonstrate block regions

Page 48: Automation in Drupal

Nodes

Page 49: Automation in Drupal

Users, roles and taxonomies

Page 50: Automation in Drupal

Relational data

Page 51: Automation in Drupal

Relational data

Page 52: Automation in Drupal
Page 53: Automation in Drupal

If you have any questions or you want access for the full installation guideline feel

free to contact me on my email address:[email protected]

Page 54: Automation in Drupal

Special thanks to:

• Nikolay Ignatov• Boyan Borisov• Miroslav Banov• Toni Kolev

Page 56: Automation in Drupal

Thank you!!!

Page 57: Automation in Drupal