SlideShare una empresa de Scribd logo
1 de 24
Automated Testing
Abhishek Anand
Technical Architect & TAM
ACQUIA
Prachi Nagpal
Drupal Developer
ACQUIA
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!!!

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

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

Destacado

D8 configuration migration
D8 configuration migrationD8 configuration migration
D8 configuration migration
Viktor Likin
 
Drush and drupal. администрирование. Волчек Михаил
Drush and drupal. администрирование. Волчек МихаилDrush and drupal. администрирование. Волчек Михаил
Drush and drupal. администрирование. Волчек Михаил
PVasili
 
Drush installation guide
Drush installation guideDrush installation guide
Drush installation guide
Thierno Fall
 
Depolying Drupal with Git, Drush Make and Capistrano
Depolying Drupal with Git, Drush Make and CapistranoDepolying Drupal with Git, Drush Make and Capistrano
Depolying Drupal with Git, Drush Make and Capistrano
libsys
 

Destacado (20)

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

Similar a Automation testing with Drupal 8

Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
Tricode (part of Dept)
 
Web App Testing With Selenium
Web App Testing With SeleniumWeb App Testing With Selenium
Web App Testing With Selenium
joaopmaia
 

Similar a Automation testing with Drupal 8 (20)

Selenium IDE
Selenium IDESelenium IDE
Selenium IDE
 
Selenium IDE
Selenium IDESelenium IDE
Selenium IDE
 
Unit testing
Unit testingUnit testing
Unit testing
 
Automated Unit Testing
Automated Unit TestingAutomated Unit Testing
Automated Unit Testing
 
Continuous feature-development
Continuous feature-developmentContinuous feature-development
Continuous feature-development
 
Autotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP BasicsAutotests introduction - Codeception + PHP Basics
Autotests introduction - Codeception + PHP Basics
 
The PHP Way Of TDD - Think First, Code Later
The PHP Way Of TDD - Think First, Code LaterThe PHP Way Of TDD - Think First, Code Later
The PHP Way Of TDD - Think First, Code Later
 
Selenium
SeleniumSelenium
Selenium
 
PHPUnit
PHPUnitPHPUnit
PHPUnit
 
Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023Getting Started with Test-Driven Development at Longhorn PHP 2023
Getting Started with Test-Driven Development at Longhorn PHP 2023
 
Effective Testing with Ansible and InSpec
Effective Testing with Ansible and InSpecEffective Testing with Ansible and InSpec
Effective Testing with Ansible and InSpec
 
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven PignataroJoomla! Day Chicago 2011 Presentation - Steven Pignataro
Joomla! Day Chicago 2011 Presentation - Steven Pignataro
 
Good practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium testsGood practices for debugging Selenium and Appium tests
Good practices for debugging Selenium and Appium tests
 
Continuous Testing and New Tools for Automation - Presentation from StarWest ...
Continuous Testing and New Tools for Automation - Presentation from StarWest ...Continuous Testing and New Tools for Automation - Presentation from StarWest ...
Continuous Testing and New Tools for Automation - Presentation from StarWest ...
 
Selenium
SeleniumSelenium
Selenium
 
Unit testing php-unit - phing - selenium_v2
Unit testing   php-unit - phing - selenium_v2Unit testing   php-unit - phing - selenium_v2
Unit testing php-unit - phing - selenium_v2
 
Automatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themesAutomatic testing and quality assurance for WordPress plugins and themes
Automatic testing and quality assurance for WordPress plugins and themes
 
Web App Testing With Selenium
Web App Testing With SeleniumWeb App Testing With Selenium
Web App Testing With Selenium
 
Selenium tutorial
Selenium tutorialSelenium tutorial
Selenium tutorial
 
Automated Web Testing With Selenium
Automated Web Testing With SeleniumAutomated Web Testing With Selenium
Automated Web Testing With Selenium
 

Último

Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Último (20)

WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare%in Harare+277-882-255-28 abortion pills for sale in Harare
%in Harare+277-882-255-28 abortion pills for sale in Harare
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
WSO2CON 2024 - Cloud Native Middleware: Domain-Driven Design, Cell-Based Arch...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 

Automation testing with Drupal 8

  • 1. Automated Testing Abhishek Anand Technical Architect & TAM ACQUIA Prachi Nagpal Drupal Developer ACQUIA
  • 2.
  • 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' => 'prachi.nagpal@acquia.com']); $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!!!