SlideShare a Scribd company logo
1 of 23
Download to read offline
BETTER TESTING 
WITH PHPUNIT 
SiteCrafting, Inc. October 2014
ADVANTAGES 
● QA personnel time is EXPENSIVE. Unit tests 
will catch bugs before they hit QA. 
● Unit tests are fast and accurate. 
● Once a unit test is programmed, it can be run 
on-demand. 
● Unit tests can hook into commits and 
deployments to promote code quality.
TERMINOLOGY 
Test A block of code that tries to do 
something in your application 
Assertion A single check that always 
evaluates to true or false 
PHPUnit Testing framework for PHP 
Selenium Server that drives a local browser
TWO DIFFERENT TYPES 
BROWSER Testing 
Runs in a real web browser 
Assertions check DOM 
elements 
SOFTWARE Testing 
Runs purely in-code 
Assertions check PHP 
variables
BROWSER TESTING 
Programmed test runs in a real browser. Uses Selenium 
WebDriver functions to... 
● Target DOM elements by id or css class 
● Click elements 
● Send keystrokes 
And then… 
● Read DOM content to make assertions
BROWSER TESTING 
Baker Project 
Projects will come with 
their own tests. 
(e.g. MyTest.class.php) 
Selenium Server 
Drives browsers and 
returns assertion results 
Console 
or Jenkins 
or SVN 
or other tool
SOFTWARE TESTING 
Programmed tests run directly on encapsulated objects. 
Deep-tests software by checking every single component in 
PHP OOP code. Extremely thorough and effective.
SOFTWARE TESTING 
Baker Project 
/tests/MyTest.class.php 
Console 
or Jenkins 
or SVN 
or other tool 
Calls Assertion 
Encapsulated 
PHP Object
TEST CLASS ANATOMY 
require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php');
TEST CLASS ANATOMY 
require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); 
class MyGearboxTest extends PHPUnit_Framework_TestCase 
{}
TEST CLASS ANATOMY 
require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); 
class MyGearboxTest extends PHPUnit_Framework_TestCase 
{ 
public function setUp() 
{ 
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); 
$this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities, 1000); 
} 
}
TEST CLASS ANATOMY 
require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); 
class MyGearboxTest extends PHPUnit_Framework_TestCase 
{ 
public function setUp() 
{ 
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); 
$this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities, 1000); 
} 
public function tearDown() 
{ 
$this->webDriver->close(); 
} 
}
TEST CLASS ANATOMY 
require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); 
class MyGearboxTest extends PHPUnit_Framework_TestCase 
{ 
public function setUp() 
{ 
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); 
$this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities, 1000); 
} 
public function testOne() { … } 
public function testTwo() { … } 
public function testThree() { … } 
public function testFour() { … } 
public function tearDown() 
{ 
$this->webDriver->close(); 
} 
} 
Any function named test* will 
be detected and run by the 
PHPUnit test framework.
TEST FUNCTION ANATOMY 
public function testOne() 
{}
TEST FUNCTION ANATOMY 
public function testOne() 
{ 
// OPEN webpage 
$this->webDriver->get($this->url); 
}
TEST FUNCTION ANATOMY 
public function testOne() 
{ 
// OPEN webpage 
$this->webDriver->get($this->url); 
// GET elements 
$txtUsername = $this->webDriver->findElement(WebDriverBy::id('login_un')); 
$txtPassword = $this->webDriver->findElement(WebDriverBy::id('login_pw')); 
$btnSubmit = $this->webDriver->findElement(WebDriverBy::cssSelector('.buttons.med')); 
}
TEST FUNCTION ANATOMY 
public function testOne() 
{ 
// OPEN webpage 
$this->webDriver->get($this->url); 
// GET elements 
$txtUsername = $this->webDriver->findElement(WebDriverBy::id('login_un')); 
$txtPassword = $this->webDriver->findElement(WebDriverBy::id('login_pw')); 
$btnSubmit = $this->webDriver->findElement(WebDriverBy::cssSelector('.buttons.med')); 
// LOGIN 
$txtUsername->click(); 
$this->webDriver->getKeyboard()->sendKeys('validuser'); 
$txtPassword->click(); 
$this->webDriver->getKeyboard()->sendKeys('validpass'); 
$btnSubmit->click(); 
}
TEST FUNCTION ANATOMY 
public function testOne() 
{ 
// OPEN webpage 
$this->webDriver->get($this->url); 
// GET elements 
$txtUsername = $this->webDriver->findElement(WebDriverBy::id('login_un')); 
$txtPassword = $this->webDriver->findElement(WebDriverBy::id('login_pw')); 
$btnSubmit = $this->webDriver->findElement(WebDriverBy::cssSelector('.buttons.med')); 
// LOGIN 
$txtUsername->click(); 
$this->webDriver->getKeyboard()->sendKeys('validuser'); 
$txtPassword->click(); 
$this->webDriver->getKeyboard()->sendKeys('validpass'); 
$btnSubmit->click(); 
// ASSERT that page title contains string ‘Dashboard’ 
$this->assertContains('Dashboard', $this->webDriver->getTitle(), 'Valid user/pass failed login.'); 
}
TESTING GEARBOX 
TestingResources folder will be required on all dev servers, 
whether shared or local. This contains the 
PHPUnit+Selenium+WebDriver testing framework. 
Tests in project repository work by extending a class in 
TestingResources. 
Gearbox 1.7 will deploy with browser tests for every module.
TESTING GEARBOX 
Our system admins will set up a Selenium browser test 
server that all browser tests will connect to. Concurrent 
connections are supported. 
Today, tests are triggered through console. In near-future, 
tests will be triggered through admin center or CI process. 
Project repositories must pass all tests prior to deployment.
TESTING GEARBOX 
We are 100% responsible for the quality of our tests. All 
software is different and there is no magic bullet. GIGO. 
Standard module tests will be written by Software Architect. 
Additional tests will be written by Senior QA Engineer. 
In the future, software tests will be written by originating 
developer.
QUESTIONS?
THANKS

More Related Content

What's hot

Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
drewz lin
 

What's hot (19)

Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Php Unit With Zend Framework Zendcon09
Php Unit With Zend Framework   Zendcon09Php Unit With Zend Framework   Zendcon09
Php Unit With Zend Framework Zendcon09
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
 
Top100summit 谷歌-scott-improve your automated web application testing
Top100summit  谷歌-scott-improve your automated web application testingTop100summit  谷歌-scott-improve your automated web application testing
Top100summit 谷歌-scott-improve your automated web application testing
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
Night Watch with QA
Night Watch with QANight Watch with QA
Night Watch with QA
 
AngularJS for Java Developers
AngularJS for Java DevelopersAngularJS for Java Developers
AngularJS for Java Developers
 
Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8Unit testing after Zend Framework 1.8
Unit testing after Zend Framework 1.8
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Automated Testing ADF with Selenium
Automated Testing ADF with SeleniumAutomated Testing ADF with Selenium
Automated Testing ADF with Selenium
 
Redux vs Alt
Redux vs AltRedux vs Alt
Redux vs Alt
 
Automated Testing with Ruby
Automated Testing with RubyAutomated Testing with Ruby
Automated Testing with Ruby
 
Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015Polyglot automation - QA Fest - 2015
Polyglot automation - QA Fest - 2015
 
Getting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe TestingGetting to Grips with SilverStripe Testing
Getting to Grips with SilverStripe Testing
 
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
Single Page Web Apps As WordPress Admin Interfaces Using AngularJS & The Word...
 
Обзор автоматизации тестирования на JavaScript
Обзор автоматизации тестирования на JavaScriptОбзор автоматизации тестирования на JavaScript
Обзор автоматизации тестирования на JavaScript
 
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.jsDrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
 

Similar to Better Testing With PHP Unit

Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
Michelangelo van Dam
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
Enterprise PHP Center
 

Similar to Better Testing With PHP Unit (20)

UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013UA Testing with Selenium and PHPUnit - ZendCon 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013
 
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
 
Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012Quality Assurance for PHP projects - ZendCon 2012
Quality Assurance for PHP projects - ZendCon 2012
 
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur PurnamaEPHPC Webinar Slides: Unit Testing by Arthur Purnama
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
 
Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12Workshop quality assurance for php projects tek12
Workshop quality assurance for php projects tek12
 
Web driver training
Web driver trainingWeb driver training
Web driver training
 
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
Selenium-Webdriver With PHPUnit Automation test for Joomla CMS!
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQUA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
 
Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013Workshop quality assurance for php projects - ZendCon 2013
Workshop quality assurance for php projects - ZendCon 2013
 
Php unit (eng)
Php unit (eng)Php unit (eng)
Php unit (eng)
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Test automation
Test  automationTest  automation
Test automation
 
Codeception presentation
Codeception presentationCodeception presentation
Codeception presentation
 
WordPress Acceptance Testing, Solved!
WordPress Acceptance Testing, Solved!WordPress Acceptance Testing, Solved!
WordPress Acceptance Testing, Solved!
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
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,...
 
WCLA12 JavaScript
WCLA12 JavaScriptWCLA12 JavaScript
WCLA12 JavaScript
 
Unit Testing from Setup to Deployment
Unit Testing from Setup to DeploymentUnit Testing from Setup to Deployment
Unit Testing from Setup to Deployment
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Recently uploaded (20)

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
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...
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
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
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
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
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
%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
 
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...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
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
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 

Better Testing With PHP Unit

  • 1. BETTER TESTING WITH PHPUNIT SiteCrafting, Inc. October 2014
  • 2. ADVANTAGES ● QA personnel time is EXPENSIVE. Unit tests will catch bugs before they hit QA. ● Unit tests are fast and accurate. ● Once a unit test is programmed, it can be run on-demand. ● Unit tests can hook into commits and deployments to promote code quality.
  • 3. TERMINOLOGY Test A block of code that tries to do something in your application Assertion A single check that always evaluates to true or false PHPUnit Testing framework for PHP Selenium Server that drives a local browser
  • 4. TWO DIFFERENT TYPES BROWSER Testing Runs in a real web browser Assertions check DOM elements SOFTWARE Testing Runs purely in-code Assertions check PHP variables
  • 5. BROWSER TESTING Programmed test runs in a real browser. Uses Selenium WebDriver functions to... ● Target DOM elements by id or css class ● Click elements ● Send keystrokes And then… ● Read DOM content to make assertions
  • 6. BROWSER TESTING Baker Project Projects will come with their own tests. (e.g. MyTest.class.php) Selenium Server Drives browsers and returns assertion results Console or Jenkins or SVN or other tool
  • 7. SOFTWARE TESTING Programmed tests run directly on encapsulated objects. Deep-tests software by checking every single component in PHP OOP code. Extremely thorough and effective.
  • 8. SOFTWARE TESTING Baker Project /tests/MyTest.class.php Console or Jenkins or SVN or other tool Calls Assertion Encapsulated PHP Object
  • 9. TEST CLASS ANATOMY require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php');
  • 10. TEST CLASS ANATOMY require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); class MyGearboxTest extends PHPUnit_Framework_TestCase {}
  • 11. TEST CLASS ANATOMY require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); class MyGearboxTest extends PHPUnit_Framework_TestCase { public function setUp() { $capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); $this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities, 1000); } }
  • 12. TEST CLASS ANATOMY require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); class MyGearboxTest extends PHPUnit_Framework_TestCase { public function setUp() { $capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); $this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities, 1000); } public function tearDown() { $this->webDriver->close(); } }
  • 13. TEST CLASS ANATOMY require_once(TEST_RESOURCES_ROOT.'vendor/facebook/webdriver/lib/__init__.php'); class MyGearboxTest extends PHPUnit_Framework_TestCase { public function setUp() { $capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); $this->webDriver = RemoteWebDriver::create('http://localhost:4444/wd/hub', $capabilities, 1000); } public function testOne() { … } public function testTwo() { … } public function testThree() { … } public function testFour() { … } public function tearDown() { $this->webDriver->close(); } } Any function named test* will be detected and run by the PHPUnit test framework.
  • 14. TEST FUNCTION ANATOMY public function testOne() {}
  • 15. TEST FUNCTION ANATOMY public function testOne() { // OPEN webpage $this->webDriver->get($this->url); }
  • 16. TEST FUNCTION ANATOMY public function testOne() { // OPEN webpage $this->webDriver->get($this->url); // GET elements $txtUsername = $this->webDriver->findElement(WebDriverBy::id('login_un')); $txtPassword = $this->webDriver->findElement(WebDriverBy::id('login_pw')); $btnSubmit = $this->webDriver->findElement(WebDriverBy::cssSelector('.buttons.med')); }
  • 17. TEST FUNCTION ANATOMY public function testOne() { // OPEN webpage $this->webDriver->get($this->url); // GET elements $txtUsername = $this->webDriver->findElement(WebDriverBy::id('login_un')); $txtPassword = $this->webDriver->findElement(WebDriverBy::id('login_pw')); $btnSubmit = $this->webDriver->findElement(WebDriverBy::cssSelector('.buttons.med')); // LOGIN $txtUsername->click(); $this->webDriver->getKeyboard()->sendKeys('validuser'); $txtPassword->click(); $this->webDriver->getKeyboard()->sendKeys('validpass'); $btnSubmit->click(); }
  • 18. TEST FUNCTION ANATOMY public function testOne() { // OPEN webpage $this->webDriver->get($this->url); // GET elements $txtUsername = $this->webDriver->findElement(WebDriverBy::id('login_un')); $txtPassword = $this->webDriver->findElement(WebDriverBy::id('login_pw')); $btnSubmit = $this->webDriver->findElement(WebDriverBy::cssSelector('.buttons.med')); // LOGIN $txtUsername->click(); $this->webDriver->getKeyboard()->sendKeys('validuser'); $txtPassword->click(); $this->webDriver->getKeyboard()->sendKeys('validpass'); $btnSubmit->click(); // ASSERT that page title contains string ‘Dashboard’ $this->assertContains('Dashboard', $this->webDriver->getTitle(), 'Valid user/pass failed login.'); }
  • 19. TESTING GEARBOX TestingResources folder will be required on all dev servers, whether shared or local. This contains the PHPUnit+Selenium+WebDriver testing framework. Tests in project repository work by extending a class in TestingResources. Gearbox 1.7 will deploy with browser tests for every module.
  • 20. TESTING GEARBOX Our system admins will set up a Selenium browser test server that all browser tests will connect to. Concurrent connections are supported. Today, tests are triggered through console. In near-future, tests will be triggered through admin center or CI process. Project repositories must pass all tests prior to deployment.
  • 21. TESTING GEARBOX We are 100% responsible for the quality of our tests. All software is different and there is no magic bullet. GIGO. Standard module tests will be written by Software Architect. Additional tests will be written by Senior QA Engineer. In the future, software tests will be written by originating developer.