Share
Embed
Introduction to PHPUnit and Selenium - AAPUG
This talk gives a basic overview of the different types of tests and tools out there, and then goes into specific detail of writing your first Selenium test in PHPUnit.
For more information, go to: http://jmather.com/talks/2012-12-01/
Jacob Mather
December 02, 2012
Transcript
34 slides
-
Intro to PHP Integra,on Tes,ng A rapid guide to
ge4ng started with Selenium and PHPUnit Jacob Mather @thejmather -
Why We Don’t Test Even though we know we
should… Jacob Mather @thejmather -
Why We Don’t Test • We don’t know about
the tools • We don’t understand the philosophy • We don’t think we have the ,me Jacob Mather @thejmather -
Why We Don’t Test • We don’t know about
the tools • We don’t understand the philosophy • We don’t think we have the ,me Jacob Mather @thejmather -
Why We Don’t Test • We don’t know about
the tools • We don’t understand the philosophy • We don’t think we have the ,me Jacob Mather @thejmather -
Why We Don’t Test • We don’t know about
the tools • We don’t understand the philosophy • We don’t think we have the ,me Jacob Mather @thejmather -
Why We Don’t Test We don’t know how.
Jacob Mather @thejmather -
Picking A Test Type Unit Tests Integra,on
Tests Jacob Mather @thejmather -
Picking A Test Type Unit Tests Integra,on
Tests Jacob Mather @thejmather -
Picking A Test Type Unit Tests Integra,on
Tests Jacob Mather @thejmather -
Picking A Test Tool phpspec2 Behat
PHPUnit Jacob Mather @thejmather -
Picking A Test Tool phpspec2 Behat
PHPUnit Jacob Mather @thejmather -
Picking A Test Tool phpspec2 Behat
PHPUnit Jacob Mather @thejmather -
Picking A Test Tool phpspec2 Behat
PHPUnit Jacob Mather @thejmather -
Test Types & Tools Unit Tests Func,onal Tests
phpspec2 X X Behat X X PHPUnit X X Jacob Mather @thejmather -
Installing PHPUnit File: composer.json { “require-‐dev”: {
“phpunit/phpunit”: “3.7.*” }, “config”: { “bin-‐dir”: “bin” } } Jacob Mather @thejmather -
Installing PHPUnit + Selenium Tools File: composer.json {
“require-‐dev”: { “phpunit/phpunit-‐selenium”: “*” }, “config”: { “bin-‐dir”: “bin” } } Jacob Mather @thejmather -
Configuring PHPUnit File: phpunit.xml.dist <phpunit colors="true"
bootstrap="vendor/autoload.php"> <testsuites> <testsuite name="Unit Tests"> <directory suffix="Test.php">tests/</directory> </testsuite> </testsuites> </phpunit> Jacob Mather @thejmather -
Our First Test File: tests/ExampleTest.php <?php
class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase { } Jacob Mather @thejmather -
Our First Test File: tests/ExampleTest.php <?php
class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase { public func,on setUp() { $this-‐>setBrowser('*firefox'); $this-‐>setBrowserUrl('h_p://jmather.com/'); } } Jacob Mather @thejmather -
Our First Test File: tests/ExampleTest.php <?php
class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase { public func,on setUp() { /* … */ } public func,on testTitle() { $this-‐>url('/'); $,tle = “It’s Majax”; $this-‐>assertEquals($,tle, $this-‐>,tle()); } } Jacob Mather @thejmather -
Our First Test File: tests/ExampleTest.php <?php
class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase { public func,on setUp() { /* … */ } public func,on testTitle() { /* … */ } public func,on testSomeNaviga,on() { $this-‐>url('/'); $this-‐>byXPath('//div[@class=”widget_categories"]/a[text() = ”PHP"]')-‐>click(); $,tle = “PHP| It’s Majax”; $this-‐>assertEquals($,tle, $this-‐>,tle()); } } Jacob Mather @thejmather -
Our First Test File: tests/ExampleTest.php <?php
class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase { public $browser = '*firefox'; public func,on setUp() { $this-‐>setBrowser($this-‐>browser); $this-‐>setBrowserUrl('h_p://jmather.com/'); } public func,on testTitle() { /* … */ } public func,on testSomeNaviga,on() { /* … */ } } -
File: tests/ExampleTest.php <?php class ExampleTest extends PHPUnit_Extensions_Selenium2TestCase
{ public $browser = '*firefox'; public func,on setUp() { $this-‐>setBrowser($this-‐>browser); $this-‐>setBrowserUrl('h_p://jmather.com/'); } public func,on testTitle() { $this-‐>url('/'); $,tle = “PHP| It’s Majax”; $this-‐>assertEquals($,tle, $this-‐>,tle()); } public func,on testSomeNaviga,on() { $this-‐>url('/'); $this-‐>byXPath('//div[@class=”widget_categories"]/a[text() = ”PHP"]')-‐>click(); $,tle = “PHP| It’s Majax”; $this-‐>assertEquals($,tle, $this-‐>,tle()); } } Jacob Mather @thejmather -
Our Second Test File: tests/ChromeExampleTest.php <?php
class ChromeExampleTest extends ExampleTest { public $browser = '*chrome'; } Jacob Mather @thejmather -
Our Second Test File: tests/ChromeExampleTest.php <?php
class ChromeExampleTest extends ExampleTest { public $browser = '*chrome'; // inherited public func,on setUp() { $this-‐>setBrowser($this-‐>browser); $this-‐>setBrowserUrl('h_p://jmather.com/'); } } Jacob Mather @thejmather -
<?php exit(0); Jacob Mather @thejmather h_p://jmather.com/talks/2012-‐12-‐01/
h_ps://github.com/jmather/phpunit-‐selenium-‐first-‐test