Catching regressions faster with automated acceptance tests

20
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

Transcript of 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

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• 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 = new AcceptanceTester( $scenario );$I->wantTo( 'Ensure WordPress Login Works' );

// Let's start on the login page$I->amOnPage( wp_login_url() );

// Populate the login form's user id field$I->fillField( 'input#user_login', 'YourUsername' );

// Populate the login form's password field$I->fillField( 'input#user_pass', 'YourPassword' );

// Submit the login form$I->click( 'Log In' );

// Validate the successful loading of the Dashboard$I->see( 'Dashboard' );

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 locally in a virtual machine

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. Install Varying Vagrant Vagrants (aka VVV)

2. Install 10up/wp-codeception plugin using composer

3. Install java & npm packages

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.

Step 1

• Install Virtual Box (https://www.virtualbox.org/wiki/Downloads)

• Install Vagrant (https://www.vagrantup.com/downloads.html)

• Install VVV and SSH into your new machine(https://github.com/Varying-Vagrant-Vagrants/VVV#the-first-vagrant-up)

Install Varying Vagrant Vagrants

CONFIDENTIAL. COPYRIGHT © 2016 GODADDY INC. ALL RIGHTS RESERVED.12Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Step 2 A

Create a new composer.json file in the root of your plugin/theme & run the install in your vm terminalInstall 10up/wp-codeception

{"require": {

"10up/wp-codeception": "^1.0"},"extra": {

"installer-paths": {"vendor/{$name}/": ["type:wordpress-plugin"]

}},"autoload": {

"files": ["vendor/wp-codeception/wp-codeception.php"

]}

}

$ composer install

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.

Step 3

$ sudo apt-get install openjdk-7-jre-headless –yes$ cd vendor/wp-codeception$ npm install

$ wp codeception bootstrap

Install Java & npm packages using your vm terminal.

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.15Copyright© 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.16Copyright© 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.17Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Let’s write an actual test

<?php

class UserTestCest {

public function validateHomeMenu( AcceptanceTester $I ) {

$I->wantTo( 'Validate that our home menu is at the right place.' );

$I->amOnPage( home_url() );

$I->seeElement( [ 'id' => 'my-awesome-menu' ] );

}

}

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.19Copyright© 2016 GoDaddy Inc. · 14455 N. Hayden Road Scottsdale, Arizona 85260 (480) 505-8800 · All Rights Reserved.

Running codeception in the terminal$ wp selenium start

$ wp codeception run --debug

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

Thank you! jonathanbardo