SlideShare a Scribd company logo
Automated Testing
Abhishek Anand
Technical Architect & TAM
ACQUIA
Prachi Nagpal
Drupal Developer
ACQUIA
Automation testing with Drupal 8
TEST DRIVEN DEVELOPMENT
1. Write a test
2. Run the test
3. Let the test fail
4. Write enough code for the test to pass
5. Run your test again
6. Refactor/ clean up the code
7. Run test again
8. Repeat
WHY USE TDD
1. Better understanding of what you're going to write
2. Enforces the policy of writing tests a little better
3. Speeds up development
BENEFITS OF TDD
1. Testable code
2. Clean design
3. Able to be refactored with confidence
4. The minimal code necessary to satisfy the story card
5. A living specification of how the code works
6. Able to support a sustainable pace of new features
TOOLS
WHY USE CODECEPTION
1. Powered by PHPUnit
2. Any type of test
a. Acceptance
b. Functional
c. Unit
3. Easy to extend
4. Lot of test suits already available for Drupal
5. Reusable code
6. Run all types of test from one place
INSTALLATION
INSTALLATION
GETTING STARTED
By default AcceptanceTester relies on PhpBrowser module, which is set in
tests/acceptance.suite.yml
It can also be set to use WebDriver
class_name: WebGuyTester
modules:
enabled:
- WebDriver:
url: http://drupal812
browser: chrome
wait: 2000
- HelperWebGuy
➜ php codecept.phar generate:cept acceptance Signin
Test was created in /Users/prachi.nagpal/Sites/drupal8/tests/acceptance/SigninCept.php
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('Test index page');
$I->amOnPage('/');
$I->see('Site-Install','#header #site-name');
$I->amGoingTo('login in the test app');
$I->fillField('Username','admin');
$I->fillField('Password','1234');
$I->click('Log in');
$I->see('Log out');
$I->click('Log out');
$I->see('User login');
?>
EXAMPLE
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure that frontpage works');
$I->amOnPage('/');
$I->see('Home');
?>
<?php
$I = new AcceptanceTester($scenario);
$I->amOnPage('/');
$I->click('Sign Up');
$I->submitForm('#signup', ['username' => prachi.nagpal, 'email' => 'prachi.nagpal@acquia.com']);
$I->see('Thank you for Signing Up!');
?>
EXAMPLE
Codeception can even 'naturalize' this scenario, converting it into plain English:
I WANT TO SIGN IN
I am on page '/user'
I fill field 'username', 'prachi.nagpal'
I fill field 'password', '1234'
I click 'Log in'
I see 'Welcome, prachi.nagpal!'
RUNNING TESTS
Tests can be started with the run command.
➜ php codecept.phar run
➜ php codecept.phar run acceptance
➜ php codecept.phar run acceptance SigninCept.php
➜ php codecept.phar run tests/acceptance/SigninCept.php
➜ php codecept.phar run tests/acceptance/SignInCest.php:anonymousLogin
➜ php codecept.phar run tests/acceptance/backend
SELENIUM WEBDRIVER
WAIT
<?php
$I->waitForElement('#agree_button', 30); // secs
$I->click('#agree_button');
?>
SESSION SNAPSHOTS
function test_login($I) {
// if snapshot exists - skipping login
if ($I->loadSessionSnapshot('login')) return;
// logging in
$I->amOnPage('/login');
$I->click('Login');
// saving snapshot
$I->saveSessionSnapshot('login');
}
// in test:
$I = new AcceptanceTester($scenario);
test_login($I);
MULTI SESSION TESTING
$I = new AcceptanceTester($scenario);
$I->wantTo('try multi session');
$I->amOnPage('/messages');
$nick = $I->haveFriend('nick');
$nick->does(function(AcceptanceTester $I) {
$I->amOnPage('/messages/new');
$I->fillField('body', 'Hello all!')
$I->click('Send');
$I->see('Hello all!', '.message');
});
$I->wait(3);
$I->see('Hello all!', '.message');
CLEANING UP / DB SNAPSHOTS
→ Db module
→ Load a database dump after each passed test.
→ SQL dump to be put in /tests/_data directory.
→ Set the database connection and path to the dump in the global Codeception config.
# in codeception.yml:
modules:
config:
Db:
dsn: '[set pdo dsn here]'
user: '[set user]'
password: '[set password]'
dump: tests/_data/dump.sql
DEBUGGING
➜ php codecept.phar run --debug
<?php
codecept_debug($I->grabTextFrom('#name'));
?>
REUSING TEST CODE
StepObjects
➜ php codecept.phar generate:stepobject acceptance Admin
➜ php codecept.phar generate:stepobject acceptance Admin
Add action to StepObject class (ENTER to exit): loginAsAdmin
Add action to StepObject class (ENTER to exit):
StepObject was created in /tests/acceptance/_support/Step/Acceptance/Admin.php
Step Object
<?php
namespace StepAcceptance;
class Member extends AcceptanceTester
{
public function loginAsAdmin()
{
$I = $this;
$I->amOnPage('/admin');
$I->fillField('username', 'admin');
$I->fillField('password', '123456');
$I->click('Login');
}
}
?>
Actual Test
<?php
use Step/Acceptance/Admin as AdminTester;
$I = new AdminTester($scenario);
$I->loginAsAdmin();
?>
PageObjects
$ php codecept.phar generate:pageobject Login
Defining PageObjects
<?php
namespace Page;
class Login
{
public static $URL = '/login';
public static $usernameField = '#mainForm #username';
public static $passwordField = '#mainForm input[name=password]';
public static $loginButton = '#mainForm input[type=submit]';
}
?>
Using PageObjects
<?php
use PageLogin as LoginPage;
$I = new AcceptanceTester($scenario);
$I->wantTo('login to site');
$I->amOnPage(LoginPage::$URL);
$I->fillField(LoginPage::$usernameField, 'bill evans');
$I->fillField(LoginPage::$passwordField, 'debby');
$I->click(LoginPage::$loginButton);
$I->see('Welcome, bill');
?>
PHPUNIT AND DRUPAL 8
...to be continued by Abhishek Anand
DEATH BY POWERPOINT!!!
THANK YOU!THANK YOU!
DEATH BY POWERPOINT!!!

More Related Content

PDF
Test all the things! Automated testing with Drupal 8
PPTX
Automated php unit testing in drupal 8
PPTX
CI / CD w/ Codeception
PDF
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
PDF
Automated testing in Drupal
PDF
Testing with Codeception (Webelement #30)
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
PPT
Zend Framework 2 - PHPUnit
Test all the things! Automated testing with Drupal 8
Automated php unit testing in drupal 8
CI / CD w/ Codeception
Xdebug and Drupal8 tests (PhpUnit and Simpletest)
Automated testing in Drupal
Testing with Codeception (Webelement #30)
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Zend Framework 2 - PHPUnit

What's hot (20)

PDF
Efficient JavaScript Unit Testing, May 2012
PDF
Testing PHP with Codeception
PPT
JavaScript Unit Testing
PPTX
Test-Driven JavaScript Development (JavaZone 2010)
PPT
JavaScript Unit Testing
PPTX
Php unit for drupal 8
PDF
Testing with Codeception
PDF
Acceptance testing in php with Codeception - Techmeetup Edinburgh
PPTX
Test automation with php codeception
ZIP
Five Easy Ways to QA Your Drupal Site
PDF
Codeception: introduction to php testing
PDF
PHP Unit Testing in Yii
PDF
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
PDF
Codeception introduction and use in Yii
PDF
Drupal 7 ci and testing
PDF
3 WAYS TO TEST YOUR COLDFUSION API
PDF
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
PDF
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
PDF
High Performance JavaScript 2011
PDF
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Efficient JavaScript Unit Testing, May 2012
Testing PHP with Codeception
JavaScript Unit Testing
Test-Driven JavaScript Development (JavaZone 2010)
JavaScript Unit Testing
Php unit for drupal 8
Testing with Codeception
Acceptance testing in php with Codeception - Techmeetup Edinburgh
Test automation with php codeception
Five Easy Ways to QA Your Drupal Site
Codeception: introduction to php testing
PHP Unit Testing in Yii
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Codeception introduction and use in Yii
Drupal 7 ci and testing
3 WAYS TO TEST YOUR COLDFUSION API
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
Selenium & PHPUnit made easy with Steward (Berlin, April 2017)
High Performance JavaScript 2011
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
Ad

Viewers also liked (20)

ODP
D8 configuration migration
PDF
Behat入門
PDF
[Srijan Wednesday Webinar] Mastering Drupal 8 Development with Drupal Console
PDF
Drush for humans - SANDcamp 2013
PPT
Drush and drupal. администрирование. Волчек Михаил
PDF
Getting started with Drupal 8
PDF
Drush installation guide
PDF
Drush workshop
PDF
Composer tools and frameworks for drupal.ppt
PPTX
Drupal 6 to Drupal 8 Migration
PPTX
Managing Drupal on Windows with Drush
PPTX
Drupal, Memcache and Solr on Windows
ODP
Drush Presentation
PDF
Composer Tools & Frameworks for Drupal
KEY
Depolying Drupal with Git, Drush Make and Capistrano
PPTX
Automated testing with Drupal
PDF
Drush - use full power - DrupalCamp Donetsk 2014
PDF
[drupalday2017] - DevOps: strumenti di automazione per Drupal8
PDF
PHP Codeception テスト -- 日本語
PDF
Behatで行う、E2Eテスト入門
D8 configuration migration
Behat入門
[Srijan Wednesday Webinar] Mastering Drupal 8 Development with Drupal Console
Drush for humans - SANDcamp 2013
Drush and drupal. администрирование. Волчек Михаил
Getting started with Drupal 8
Drush installation guide
Drush workshop
Composer tools and frameworks for drupal.ppt
Drupal 6 to Drupal 8 Migration
Managing Drupal on Windows with Drush
Drupal, Memcache and Solr on Windows
Drush Presentation
Composer Tools & Frameworks for Drupal
Depolying Drupal with Git, Drush Make and Capistrano
Automated testing with Drupal
Drush - use full power - DrupalCamp Donetsk 2014
[drupalday2017] - DevOps: strumenti di automazione per Drupal8
PHP Codeception テスト -- 日本語
Behatで行う、E2Eテスト入門
Ad

Similar to Automation testing with Drupal 8 (20)

PDF
Selenium IDE
PDF
Selenium IDE
PPT
Unit testing
PPT
Automated Unit Testing
PPTX
Continuous feature-development
PPTX
Autotests introduction - Codeception + PHP Basics
PDF
The PHP Way Of TDD - Think First, Code Later
PPT
Selenium
PPTX
Getting Started with Test-Driven Development at Longhorn PHP 2023
PPTX
Effective Testing with Ansible and InSpec
PPTX
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
PDF
Good practices for debugging Selenium and Appium tests
PPTX
Continuous Testing and New Tools for Automation - Presentation from StarWest ...
PDF
Selenium
PPT
Unit testing php-unit - phing - selenium_v2
PDF
Automatic testing and quality assurance for WordPress plugins and themes
PPT
Web App Testing With Selenium
PPTX
Selenium tutorial
PPTX
Automated Web Testing With Selenium
Selenium IDE
Selenium IDE
Unit testing
Automated Unit Testing
Continuous feature-development
Autotests introduction - Codeception + PHP Basics
The PHP Way Of TDD - Think First, Code Later
Selenium
Getting Started with Test-Driven Development at Longhorn PHP 2023
Effective Testing with Ansible and InSpec
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Good practices for debugging Selenium and Appium tests
Continuous Testing and New Tools for Automation - Presentation from StarWest ...
Selenium
Unit testing php-unit - phing - selenium_v2
Automatic testing and quality assurance for WordPress plugins and themes
Web App Testing With Selenium
Selenium tutorial
Automated Web Testing With Selenium

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Designing Intelligence for the Shop Floor.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
medical staffing services at VALiNTRY
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PPTX
ai tools demonstartion for schools and inter college
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
System and Network Administration Chapter 2
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
CHAPTER 2 - PM Management and IT Context
Design an Analysis of Algorithms I-SECS-1021-03
Softaken Excel to vCard Converter Software.pdf
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
How to Choose the Right IT Partner for Your Business in Malaysia
Designing Intelligence for the Shop Floor.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Digital Systems & Binary Numbers (comprehensive )
Design an Analysis of Algorithms II-SECS-1021-03
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
medical staffing services at VALiNTRY
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
ai tools demonstartion for schools and inter college
Upgrade and Innovation Strategies for SAP ERP Customers
VVF-Customer-Presentation2025-Ver1.9.pptx
System and Network Administration Chapter 2
Reimagine Home Health with the Power of Agentic AI​
Wondershare Filmora 15 Crack With Activation Key [2025
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
CHAPTER 2 - PM Management and IT Context

Automation testing with Drupal 8

  • 1. Automated Testing Abhishek Anand Technical Architect & TAM ACQUIA Prachi Nagpal Drupal Developer ACQUIA
  • 3. TEST DRIVEN DEVELOPMENT 1. Write a test 2. Run the test 3. Let the test fail 4. Write enough code for the test to pass 5. Run your test again 6. Refactor/ clean up the code 7. Run test again 8. Repeat
  • 4. WHY USE TDD 1. Better understanding of what you're going to write 2. Enforces the policy of writing tests a little better 3. Speeds up development
  • 5. BENEFITS OF TDD 1. Testable code 2. Clean design 3. Able to be refactored with confidence 4. The minimal code necessary to satisfy the story card 5. A living specification of how the code works 6. Able to support a sustainable pace of new features
  • 7. WHY USE CODECEPTION 1. Powered by PHPUnit 2. Any type of test a. Acceptance b. Functional c. Unit 3. Easy to extend 4. Lot of test suits already available for Drupal 5. Reusable code 6. Run all types of test from one place
  • 10. GETTING STARTED By default AcceptanceTester relies on PhpBrowser module, which is set in tests/acceptance.suite.yml It can also be set to use WebDriver class_name: WebGuyTester modules: enabled: - WebDriver: url: http://drupal812 browser: chrome wait: 2000 - HelperWebGuy
  • 11. ➜ php codecept.phar generate:cept acceptance Signin Test was created in /Users/prachi.nagpal/Sites/drupal8/tests/acceptance/SigninCept.php <?php $I = new AcceptanceTester($scenario); $I->wantTo('Test index page'); $I->amOnPage('/'); $I->see('Site-Install','#header #site-name'); $I->amGoingTo('login in the test app'); $I->fillField('Username','admin'); $I->fillField('Password','1234'); $I->click('Log in'); $I->see('Log out'); $I->click('Log out'); $I->see('User login'); ?>
  • 12. EXAMPLE <?php $I = new AcceptanceTester($scenario); $I->wantTo('ensure that frontpage works'); $I->amOnPage('/'); $I->see('Home'); ?> <?php $I = new AcceptanceTester($scenario); $I->amOnPage('/'); $I->click('Sign Up'); $I->submitForm('#signup', ['username' => prachi.nagpal, 'email' => '[email protected]']); $I->see('Thank you for Signing Up!'); ?>
  • 13. EXAMPLE Codeception can even 'naturalize' this scenario, converting it into plain English: I WANT TO SIGN IN I am on page '/user' I fill field 'username', 'prachi.nagpal' I fill field 'password', '1234' I click 'Log in' I see 'Welcome, prachi.nagpal!'
  • 14. RUNNING TESTS Tests can be started with the run command. ➜ php codecept.phar run ➜ php codecept.phar run acceptance ➜ php codecept.phar run acceptance SigninCept.php ➜ php codecept.phar run tests/acceptance/SigninCept.php ➜ php codecept.phar run tests/acceptance/SignInCest.php:anonymousLogin ➜ php codecept.phar run tests/acceptance/backend
  • 15. SELENIUM WEBDRIVER WAIT <?php $I->waitForElement('#agree_button', 30); // secs $I->click('#agree_button'); ?> SESSION SNAPSHOTS function test_login($I) { // if snapshot exists - skipping login if ($I->loadSessionSnapshot('login')) return; // logging in $I->amOnPage('/login'); $I->click('Login'); // saving snapshot $I->saveSessionSnapshot('login'); } // in test: $I = new AcceptanceTester($scenario); test_login($I);
  • 16. MULTI SESSION TESTING $I = new AcceptanceTester($scenario); $I->wantTo('try multi session'); $I->amOnPage('/messages'); $nick = $I->haveFriend('nick'); $nick->does(function(AcceptanceTester $I) { $I->amOnPage('/messages/new'); $I->fillField('body', 'Hello all!') $I->click('Send'); $I->see('Hello all!', '.message'); }); $I->wait(3); $I->see('Hello all!', '.message');
  • 17. CLEANING UP / DB SNAPSHOTS → Db module → Load a database dump after each passed test. → SQL dump to be put in /tests/_data directory. → Set the database connection and path to the dump in the global Codeception config. # in codeception.yml: modules: config: Db: dsn: '[set pdo dsn here]' user: '[set user]' password: '[set password]' dump: tests/_data/dump.sql
  • 18. DEBUGGING ➜ php codecept.phar run --debug <?php codecept_debug($I->grabTextFrom('#name')); ?>
  • 19. REUSING TEST CODE StepObjects ➜ php codecept.phar generate:stepobject acceptance Admin ➜ php codecept.phar generate:stepobject acceptance Admin Add action to StepObject class (ENTER to exit): loginAsAdmin Add action to StepObject class (ENTER to exit): StepObject was created in /tests/acceptance/_support/Step/Acceptance/Admin.php
  • 20. Step Object <?php namespace StepAcceptance; class Member extends AcceptanceTester { public function loginAsAdmin() { $I = $this; $I->amOnPage('/admin'); $I->fillField('username', 'admin'); $I->fillField('password', '123456'); $I->click('Login'); } } ?> Actual Test <?php use Step/Acceptance/Admin as AdminTester; $I = new AdminTester($scenario); $I->loginAsAdmin(); ?>
  • 21. PageObjects $ php codecept.phar generate:pageobject Login Defining PageObjects <?php namespace Page; class Login { public static $URL = '/login'; public static $usernameField = '#mainForm #username'; public static $passwordField = '#mainForm input[name=password]'; public static $loginButton = '#mainForm input[type=submit]'; } ?>
  • 22. Using PageObjects <?php use PageLogin as LoginPage; $I = new AcceptanceTester($scenario); $I->wantTo('login to site'); $I->amOnPage(LoginPage::$URL); $I->fillField(LoginPage::$usernameField, 'bill evans'); $I->fillField(LoginPage::$passwordField, 'debby'); $I->click(LoginPage::$loginButton); $I->see('Welcome, bill'); ?>
  • 23. PHPUNIT AND DRUPAL 8 ...to be continued by Abhishek Anand
  • 24. DEATH BY POWERPOINT!!! THANK YOU!THANK YOU! DEATH BY POWERPOINT!!!