wordcamp montreal - catching regressions faster with automated acceptance tests
TRANSCRIPT
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Catching regressions faster with automated acceptance tests! Jonathan Bardo
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.2Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
About me
• Senior Product Engineer – WordPress for GoDaddy
• Currently working on• New onboarding experience for GoDaddy’s clients
• Love• PHP• JavaScript• Big Data platforms• Making WordPress plugins• Tests
• Based in Montreal
! jonathanbardo
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
What is acceptance testing?
3
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.4Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Definition
Acceptance testing is used to make sure the requirements of a specification are met.
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.5Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
ExampleUsing Codeception PHP framework
<?php
$I->wantTo( 'Log into WordPress admin' );
// Let's start on the login page$I->amOnPage( wp_login_url() );
// Populate the login form's user id field$I->fillField( [ 'id' => 'user_login' ], 'admin' );
// Populate the login form's password field$I->fillField( [ 'id' => 'user_pass' ], 'password' );
// Submit the login form$I->click( [ 'name' => 'wp-submit' ] );
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.6Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
In shortIf there’s a new WordPress release coming out soon.
😱 😎Go from this To this
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
The tools
7
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.8Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
The tools
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Installation
9
Running tests locallyjonathanbardo.com/?p=559
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.10Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Steps
1. Setup your local environment (VVV, Laravel Valet, MAMP, others)
2. Install Selenium Server
3. Install a browser driver (e.g. Chromedriver)
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.11Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Demo: My local setup
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Writing acceptance tests
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.13Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
codeception.ymlactor: Testerpaths:
tests: tests/codeceptionlog: tests/codeception/_outputdata: tests/codeception/_datahelpers: tests/codeception/_support
settings:bootstrap: _bootstrap.phpcolors: truememory_limit: 256M
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.14Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
acceptance.suite.ymltests/codeception/acceptance.suite.yml
class_name: AcceptanceTestermodules:
enabled:- WebDriver- WordPress- AcceptanceHelper
config:WebDriver:window_size: 1366x764
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.15Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Demo: Sample plugin
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.16Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
A look back
<?php
$I->wantTo( 'Log into WordPress admin' );
// Let's start on the login page$I->amOnPage( wp_login_url() );
// Populate the login form's user id field$I->fillField( [ 'id' => 'user_login' ], 'admin' );
// Populate the login form's password field$I->fillField( [ 'id' => 'user_pass' ], 'password' );
// Submit the login form$I->click( [ 'name' => 'wp-submit' ] );
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.17Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Demo: Let’s write a test
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.18Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Let’s write an actual test
/*** Validate front end site description is present** @param AcceptanceTester $I*/public function validateFrontEndSiteDescription( \AcceptanceTester $I ) {
$I->wantTo( 'Make sure the site description is "Codeception demo"' );
$I->amOnPage( home_url() );
$I->canSee( __( 'Codeception demo', 'codeception-demo' ) );
}
tests/codeception/acceptance/UserTestCest.php
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.19Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Let’s write an actual test
/*** Validate that our admin menu has the right text** @before login* @param AcceptanceTester $I*/public function validateAdminMenu( \AcceptanceTester $I ) {
$I->wantTo( 'Make sure the Dashboard admin menu text is "Codeception demo"' );
$I->amOnPage( admin_url() );
$I->canSee(__( 'Codeception demo', 'codeception-demo' ),[ 'css' => '#menu-dashboard .wp-menu-name' ]
);
}
tests/codeception/acceptance/UserTestCest.php
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Running acceptance tests
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.21Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Running codeception in the terminal$ wp codeception run --debug
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.22Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Demo
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Using Travis CI
CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.25Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Demo
Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.
Thank you! jonathanbardo