26
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

WordCamp Montreal - Catching regressions faster with automated acceptance tests

Embed Size (px)

Citation preview

Page 1: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 2: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 3: WordCamp Montreal - Catching regressions faster with automated acceptance tests

Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

What is acceptance testing?

3

Page 4: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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.

Page 5: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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' ] );

Page 6: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 7: WordCamp Montreal - Catching regressions faster with automated acceptance tests

Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

The tools

7

Page 8: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 9: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 10: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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)

Page 11: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 12: WordCamp Montreal - Catching regressions faster with automated acceptance tests

Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Writing acceptance tests

Page 13: WordCamp Montreal - Catching regressions faster with automated 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

Page 14: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 15: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 16: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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' ] );

Page 17: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 18: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 19: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 20: WordCamp Montreal - Catching regressions faster with automated acceptance tests

Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Running acceptance tests

Page 21: WordCamp Montreal - Catching regressions faster with automated 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

Page 22: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 23: WordCamp Montreal - Catching regressions faster with automated acceptance tests
Page 24: WordCamp Montreal - Catching regressions faster with automated acceptance tests

Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Using Travis CI

Page 25: WordCamp Montreal - Catching regressions faster with automated acceptance tests

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

Page 26: WordCamp Montreal - Catching regressions faster with automated acceptance tests

Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Thank you! jonathanbardo