SlideShare a Scribd company logo
UA	
  Tes'ng	
  with
Selenium	
  and	
  PHPUnit
PHPBenelux	
  Summer	
  BBQ
2
• PHP	
  Consultant
• President	
  PHPBenelux
• Conference	
  speaker
Michelangelo	
  van	
  Dam
3
4
Thank	
  you	
  for	
  sponsoring
Today’s	
  goal
• Set	
  up	
  and	
  use	
  Selenium	
  IDE
• Record	
  UA	
  tests
• Convert	
  to	
  PHPUnit
• Run	
  con'nuously
• Mul'	
  browser	
  support
5
6
DISCLAIMER
S E L E N I U M T E S T S A R E N OT A
REPLACEMENT FOR REGULAR UNIT
TESTING. THEY ONLY PROVIDE AN
ADDITIONAL SET OF TESTS FOCUSED
ON USER ACCEPTANCE AND USER
EXPERIENCE TESTING.
For more information about unit testing, please
see my other material on www.slideshare.net and
www.speakerdeck.com. Search for “dragonbe”!
User	
  Acceptance
7
8
“Acceptance testing is a test conducted to determine if
the requirements of a specification or contract are met.”
-- source: wikipedia
Checklist	
  for	
  web	
  applica'ons
9
10
Func'onal	
  tes'ng
• Test	
  func'onal	
  requirements
-­‐ e.g.	
  no	
  access	
  to	
  profile	
  without	
  authen'ca'on
• Test	
  UI	
  elements	
  on	
  the	
  web	
  interface
-­‐ e.g.	
  buOons,	
  form	
  elements,	
  AJAX	
  controls,	
  …
A	
  word	
  of	
  cau'on!
11
• UA	
  tests	
  only	
  test	
  generated	
  output
-­‐ not	
  a	
  replacement	
  for	
  unit	
  tes'ng
• UA	
  tests	
  are	
  heavily	
  depending	
  on	
  DOM
-­‐ changes	
  to	
  the	
  DOM	
  might	
  lead	
  to	
  failing	
  UAT
Browser	
  support
12
Selenium	
  to	
  the	
  rescue
13
Plugin	
  for	
  firefox
14
Get	
  the	
  plugin	
  (demo)
15
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
Let’s	
  get	
  started
17
Pick	
  a	
  test	
  case
18
Issue	
  #7
19
Verify	
  this	
  issue	
  on	
  PROD
20
21
Fix	
  the	
  issue
22
Run	
  test	
  to	
  see	
  it’s	
  fixed
23
24
25
Save	
  your	
  test	
  as	
  .html
It’s	
  that	
  easy!
26
Automated	
  Tes'ng
27
PHPUnit	
  to	
  the	
  rescue
28
Export	
  to	
  PHPUnit
29
The	
  PHPUnit	
  TestCase
30
<?php
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://www.theialive.com/");
}
public function testMyTestCase()
{
$this->open("/");
$this->click("link=login");
$this->waitForPageToLoad("30000");
$this->type("id=email", "dragonbe+tek13@gmail.com");
$this->type("id=password", "test1234");
$this->click("id=signin");
$this->waitForPageToLoad("30000");
$this->click("link=Test demo");
$this->waitForPageToLoad("30000");
$this->assertEquals("Done", $this->getText("xpath=//th[5]"));
$this->click("link=[EDIT]");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isElementPresent("id=done"));
$this->click("link=sign off");
$this->waitForPageToLoad("30000");
}
}
?>
Change	
  class	
  name
31
<?php
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://www.theialive.com/");
}
public function testMyTestCase()
{
$this->open("/");
$this->click("link=login");
$this->waitForPageToLoad("30000");
$this->type("id=email", "dragonbe+tek13@gmail.com");
$this->type("id=password", "test1234");
$this->click("id=signin");
$this->waitForPageToLoad("30000");
$this->click("link=Test demo");
$this->waitForPageToLoad("30000");
$this->assertEquals("Done", $this->getText("xpath=//th[5]"));
$this->click("link=[EDIT]");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isElementPresent("id=done"));
$this->click("link=sign off");
$this->waitForPageToLoad("30000");
}
}
?>
class MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase
The	
  PHPUnit	
  TestCase
32
<?php
class MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*chrome");
$this->setBrowserUrl("http://www.theialive.com/");
}
public function testMyTestCase()
{
$this->open("/");
$this->click("link=login");
$this->waitForPageToLoad("30000");
$this->type("id=email", "dragonbe+tek13@gmail.com");
$this->type("id=password", "test1234");
$this->click("id=signin");
$this->waitForPageToLoad("30000");
$this->click("link=Test demo");
$this->waitForPageToLoad("30000");
$this->assertEquals("Done", $this->getText("xpath=//th[5]"));
$this->click("link=[EDIT]");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isElementPresent("id=done"));
$this->click("link=sign off");
$this->waitForPageToLoad("30000");
}
}
?>
protected function setUp()
{
$this->setBrowser("*iexplore");
$this->setBrowserUrl("http://www.theialive.com/");
$this->setHost('192.168.56.101');
$this->setPort(12666);
}
Meaningful	
  method	
  name
<?php
class MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*iexplore");
$this->setBrowserUrl("http://www.theialive.com/");
$this->setHost('192.168.56.101');
$this->setPort(12666);
}
public function testMyTestCase()
{
$this->open("/");
$this->click("link=login");
$this->waitForPageToLoad("30000");
$this->type("id=email", "dragonbe+tek13@gmail.com");
$this->type("id=password", "test1234");
$this->click("id=signin");
$this->waitForPageToLoad("30000");
$this->click("link=Test demo");
$this->waitForPageToLoad("30000");
$this->assertEquals("Done", $this->getText("xpath=//th[5]"));
$this->click("link=[EDIT]");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isElementPresent("id=done"));
$this->click("link=sign off");
$this->waitForPageToLoad("30000");
}
}
?>
33
public function testMarkTestAsDone()
startSeleniumStandAlone.BAT
34
"C:Program FilesJavajre7binjava.exe" -jar "C:Usersuser
Downloadsselenium-server-standalone-2.28.0.jar" -port 12666
Now	
  run	
  your	
  tests
35
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
How	
  it	
  runs	
  on	
  the	
  node
37
UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ
Advantages
39
• You	
  can	
  start	
  tes'ng	
  immediately
• Even	
  test	
  “hard	
  to	
  test”	
  kind	
  of	
  situa'ons
• More	
  nodes	
  for	
  parallel	
  tes'ng
• Tes'ng	
  different	
  browsers	
  and	
  plaborms
• Con'nuous	
  Integra'on	
  possible
Selenium	
  Grid	
  Setup
40
Selenium Testing
CI Server Windows
"HUB"
Linux client
"NODE"
CI executes tests
Windows HUB launches
Selenium node clients
to execute tests
Windows Server collects
feedback from the Citrix
client nodes and reports
back to CI Server
Windows client
"NODE"
Mac OS X client
"NODE"
Continuous User Acceptance Testing
Next	
  Steps
41
Mul'	
  Browser	
  support
42
Base	
  TestCase
43
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class TestCase extends PHPUnit_Extensions_SeleniumTestCase
{
//const TEST_HUB = '217.21.179.192';
const TEST_HUB = '192.168.56.101';
const TEST_PORT = 12666;
const USERNAME = 'dragonbe+tek13@gmail.com';
const PASSWORD = 'test1234';
const BASURL = 'http://www.theialive.com';
public static $browsers = array (
array (
'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Firefox on Windows 7', 'browser' => '*firefox',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
);
protected function setUp()
{
$this->setBrowserUrl(self::BASURL);
}
}
Base	
  TestCase
44
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class TestCase extends PHPUnit_Extensions_SeleniumTestCase
{
//const TEST_HUB = '217.21.179.192';
const TEST_HUB = '192.168.56.101';
const TEST_PORT = 12666;
const USERNAME = 'dragonbe+tek13@gmail.com';
const PASSWORD = 'test1234';
const BASURL = 'http://www.theialive.com';
public static $browsers = array (
array (
'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Firefox on Windows 7', 'browser' => '*firefox',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
);
protected function setUp()
{
$this->setBrowserUrl(self::BASURL);
}
}
array (
'name' => 'Internet Explorer 8 on Windows 7',
'browser' => '*iexplore',
'host' => self::TEST_HUB,
'port' => self::TEST_PORT,
),
Base	
  TestCase
45
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class TestCase extends PHPUnit_Extensions_SeleniumTestCase
{
//const TEST_HUB = '217.21.179.192';
const TEST_HUB = '192.168.56.101';
const TEST_PORT = 12666;
const USERNAME = 'dragonbe+tek13@gmail.com';
const PASSWORD = 'test1234';
const BASURL = 'http://www.theialive.com';
public static $browsers = array (
array (
'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Firefox on Windows 7', 'browser' => '*firefox',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
);
protected function setUp()
{
$this->setBrowserUrl(self::BASURL);
}
}
array (
'name' => 'Firefox on Windows 7',
'browser' => '*firefox',
'host' => self::TEST_HUB,
'port' => self::TEST_PORT,
),
Base	
  TestCase
46
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class TestCase extends PHPUnit_Extensions_SeleniumTestCase
{
//const TEST_HUB = '217.21.179.192';
const TEST_HUB = '192.168.56.101';
const TEST_PORT = 12666;
const USERNAME = 'dragonbe+tek13@gmail.com';
const PASSWORD = 'test1234';
const BASURL = 'http://www.theialive.com';
public static $browsers = array (
array (
'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Firefox on Windows 7', 'browser' => '*firefox',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
array (
'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome',
'host' => self::TEST_HUB, 'port' => self::TEST_PORT,
),
);
protected function setUp()
{
$this->setBrowserUrl(self::BASURL);
}
}
array (
'name' => 'Google Chrome on Windows 7',
'browser' => '*googlechrome',
'host' => self::TEST_HUB,
'port' => self::TEST_PORT,
),
Modify	
  MarkTaskDoneTest	
  
<?php
/**
* Class MarkTaskDoneTest
*
* @group Selenium
*/
require_once 'TestCase.php';
class MarkTaskDoneTest extends TestCase
{
public function testMarkTestAsDone()
{
$this->open("/");
$this->click("link=login");
$this->waitForPageToLoad("30000");
$this->type("id=email", TestCase::USERNAME);
$this->type("id=password", TestCase::PASSWORD);
$this->click("id=signin");
$this->waitForPageToLoad("30000");
$this->click("link=Test demo");
$this->waitForPageToLoad("30000");
$this->assertEquals("Done", $this->getText("xpath=//th[5]"));
$this->click("link=[EDIT]");
$this->waitForPageToLoad("30000");
$this->assertTrue($this->isElementPresent("id=done"));
$this->click("link=sign off");
$this->waitForPageToLoad("30000");
}
}
47
Require the TestCase
and extend it
Running	
  test
48
49
Benefits
• run	
  your	
  tests	
  on	
  mul'ple	
  browsers
• detect	
  flaws	
  in	
  specific	
  browsers	
  (e.g.	
  IE6)
-­‐ adapt	
  your	
  apps	
  to	
  solve	
  these	
  flaws
50
51
Con'nuous	
  Integra'on
52
More	
  informa'on
53
seleniumhq.org
54
phpunit.de
55
http://www.phpunit.de/manual/3.5/en/selenium.html
Credits
56
• apple	
  store:	
  hOp://www.flickr.com/photos/jtjdt/3571748777
• checklist:	
  hOp://www.flickr.com/photos/alancleaver/4439276478
• flat	
  're:	
  hOp://www.flickr.com/photos/anijdam/2468493546/
• first	
  place:	
  hOp://www.flickr.com/photos/evelynishere/
3417340248/
• gears:	
  hOp://www.flickr.com/photos/wwarby/4782904694
• steps:	
  hOp://www.flickr.com/photos/ben_salter/1407168763
• browsers:	
  hOp://www.flickr.com/photos/richoz/3791167457
• gears:	
  hOp://www.flickr.com/photos/freefoto/5982549938
• danger:	
  hOp://www.flickr.com/photos/armchairbuilder/
7345497766
• informa'on:	
  hOp://www.flickr.com/photos/twicepix/2650241408/
• elephpant:	
  hOp://www.flickr.com/photos/drewm/3191872515
Contact
57
Michelangelo van Dam
Zend Certified Engineer
email: michelangelo@in2it.be
skype: michelangelovandam
twitter: @DragonBe
tel EU: +32 15 34 52 90
tel US: 202 559-7401
www.in2it.be
facebook.com/in2itvof | @in2itvof
Contact us for
Consultancy - Training - QA - Webdesign
58
https://joind.in/8985
Thank	
  you
59

More Related Content

PDF
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
PDF
UA Testing with Selenium and PHPUnit - ZendCon 2013
PDF
UA testing with Selenium and PHPUnit - PFCongres 2013
PDF
Workshop quality assurance for php projects - ZendCon 2013
PDF
QA for PHP projects
PDF
Unit testing with zend framework tek11
KEY
Unit testing with zend framework PHPBenelux
PDF
PHPUnit Episode iv.iii: Return of the tests
UA testing with Selenium and PHPUnit - TrueNorthPHP 2013
UA Testing with Selenium and PHPUnit - ZendCon 2013
UA testing with Selenium and PHPUnit - PFCongres 2013
Workshop quality assurance for php projects - ZendCon 2013
QA for PHP projects
Unit testing with zend framework tek11
Unit testing with zend framework PHPBenelux
PHPUnit Episode iv.iii: Return of the tests

What's hot (20)

KEY
Workshop quality assurance for php projects tek12
PDF
PHPunit and you
PDF
PDF
Quality Assurance for PHP projects - ZendCon 2012
PDF
JavaScript & HTML5 - Brave New World
PDF
Better Bullshit Driven Development [SeleniumCamp 2017]
PDF
Separation of concerns - DPC12
PDF
Тестирование и Django
PDF
13 PHPUnit #burningkeyboards
KEY
Unit testing zend framework apps
ODP
My app is secure... I think
PDF
PhpBB meets Symfony2
PDF
PHP Secure Programming
PDF
The symfony platform: Create your very own framework (PHP Quebec 2008)
PDF
HTML5 JavaScript APIs
PDF
Your code are my tests
PDF
Nashville Symfony Functional Testing
PDF
Top5 scalabilityissues
PDF
Symfony2 - OSIDays 2010
ODP
Engitec - Minicurso de Django
Workshop quality assurance for php projects tek12
PHPunit and you
Quality Assurance for PHP projects - ZendCon 2012
JavaScript & HTML5 - Brave New World
Better Bullshit Driven Development [SeleniumCamp 2017]
Separation of concerns - DPC12
Тестирование и Django
13 PHPUnit #burningkeyboards
Unit testing zend framework apps
My app is secure... I think
PhpBB meets Symfony2
PHP Secure Programming
The symfony platform: Create your very own framework (PHP Quebec 2008)
HTML5 JavaScript APIs
Your code are my tests
Nashville Symfony Functional Testing
Top5 scalabilityissues
Symfony2 - OSIDays 2010
Engitec - Minicurso de Django
Ad

Viewers also liked (6)

DOC
Ashish Baraiya
PPTX
Helium- web automation made awesome!
PPTX
Automation solution using jbehave, selenium and hudson
DOC
QUALITY ASSURANCE and VALIDATION ENGINEER
DOC
2+ Years of Experince in Testing resume
PPT
Android Mobile - Home Automation
Ashish Baraiya
Helium- web automation made awesome!
Automation solution using jbehave, selenium and hudson
QUALITY ASSURANCE and VALIDATION ENGINEER
2+ Years of Experince in Testing resume
Android Mobile - Home Automation
Ad

Similar to UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ (20)

PDF
symfony on action - WebTech 207
PDF
Better Testing With PHP Unit
PDF
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
PDF
Unit testing after Zend Framework 1.8
PPT
PDF
Join the darkside: Selenium testing with Nightwatch.js
PDF
Leveling Up With Unit Testing - php[tek] 2023
PDF
Browser testing with nightwatch.js - Drupal Europe
PDF
Getting started with TDD - Confoo 2014
KEY
Phpne august-2012-symfony-components-friends
PDF
関西PHP勉強会 php5.4つまみぐい
PDF
Workshop quality assurance for php projects - phpbelfast
PDF
Charla EHU Noviembre 2014 - Desarrollo Web
PDF
Refactoring using Codeception
PDF
How to build a High Performance PSGI/Plack Server
PDF
Frameworks da nova Era PHP FuelPHP
PDF
node.js Module Development
PDF
Unit Testing from Setup to Deployment
PDF
Mojolicious. Веб в коробке!
PDF
Virtual Madness @ Etsy
symfony on action - WebTech 207
Better Testing With PHP Unit
EPHPC Webinar Slides: Unit Testing by Arthur Purnama
Unit testing after Zend Framework 1.8
Join the darkside: Selenium testing with Nightwatch.js
Leveling Up With Unit Testing - php[tek] 2023
Browser testing with nightwatch.js - Drupal Europe
Getting started with TDD - Confoo 2014
Phpne august-2012-symfony-components-friends
関西PHP勉強会 php5.4つまみぐい
Workshop quality assurance for php projects - phpbelfast
Charla EHU Noviembre 2014 - Desarrollo Web
Refactoring using Codeception
How to build a High Performance PSGI/Plack Server
Frameworks da nova Era PHP FuelPHP
node.js Module Development
Unit Testing from Setup to Deployment
Mojolicious. Веб в коробке!
Virtual Madness @ Etsy

More from Michelangelo van Dam (20)

PDF
GDPR Art. 25 - Privacy by design and default
PDF
Moving from app services to azure functions
PDF
Privacy by design
PDF
DevOps or DevSecOps
PDF
Privacy by design
PDF
Continuous deployment 2.0
PDF
Let your tests drive your code
PDF
General Data Protection Regulation, a developer's story
PDF
Leveraging a distributed architecture to your advantage
PDF
The road to php 7.1
PDF
Open source for a successful business
PDF
Decouple your framework now, thank me later
PDF
Deploy to azure in less then 15 minutes
PDF
Azure and OSS, a match made in heaven
PDF
Getting hands dirty with php7
PDF
Zf2 how arrays will save your project
PDF
Create, test, secure, repeat
PDF
The Continuous PHP Pipeline
PDF
Easily extend your existing php app with an api
PDF
200K+ reasons security is a must
GDPR Art. 25 - Privacy by design and default
Moving from app services to azure functions
Privacy by design
DevOps or DevSecOps
Privacy by design
Continuous deployment 2.0
Let your tests drive your code
General Data Protection Regulation, a developer's story
Leveraging a distributed architecture to your advantage
The road to php 7.1
Open source for a successful business
Decouple your framework now, thank me later
Deploy to azure in less then 15 minutes
Azure and OSS, a match made in heaven
Getting hands dirty with php7
Zf2 how arrays will save your project
Create, test, secure, repeat
The Continuous PHP Pipeline
Easily extend your existing php app with an api
200K+ reasons security is a must

Recently uploaded (20)

PDF
Sensors and Actuators in IoT Systems using pdf
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
Cloud computing and distributed systems.
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
Empathic Computing: Creating Shared Understanding
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Sensors and Actuators in IoT Systems using pdf
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Cloud computing and distributed systems.
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Modernizing your data center with Dell and AMD
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Big Data Technologies - Introduction.pptx
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
madgavkar20181017ppt McKinsey Presentation.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Diabetes mellitus diagnosis method based random forest with bat algorithm
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows

UA testing with Selenium and PHPUnit - PHPBenelux Summer BBQ

  • 1. UA  Tes'ng  with Selenium  and  PHPUnit PHPBenelux  Summer  BBQ
  • 2. 2 • PHP  Consultant • President  PHPBenelux • Conference  speaker Michelangelo  van  Dam
  • 3. 3
  • 4. 4 Thank  you  for  sponsoring
  • 5. Today’s  goal • Set  up  and  use  Selenium  IDE • Record  UA  tests • Convert  to  PHPUnit • Run  con'nuously • Mul'  browser  support 5
  • 6. 6 DISCLAIMER S E L E N I U M T E S T S A R E N OT A REPLACEMENT FOR REGULAR UNIT TESTING. THEY ONLY PROVIDE AN ADDITIONAL SET OF TESTS FOCUSED ON USER ACCEPTANCE AND USER EXPERIENCE TESTING. For more information about unit testing, please see my other material on www.slideshare.net and www.speakerdeck.com. Search for “dragonbe”!
  • 8. 8 “Acceptance testing is a test conducted to determine if the requirements of a specification or contract are met.” -- source: wikipedia
  • 9. Checklist  for  web  applica'ons 9
  • 10. 10 Func'onal  tes'ng • Test  func'onal  requirements -­‐ e.g.  no  access  to  profile  without  authen'ca'on • Test  UI  elements  on  the  web  interface -­‐ e.g.  buOons,  form  elements,  AJAX  controls,  …
  • 11. A  word  of  cau'on! 11 • UA  tests  only  test  generated  output -­‐ not  a  replacement  for  unit  tes'ng • UA  tests  are  heavily  depending  on  DOM -­‐ changes  to  the  DOM  might  lead  to  failing  UAT
  • 13. Selenium  to  the  rescue 13
  • 15. Get  the  plugin  (demo) 15
  • 18. Pick  a  test  case 18
  • 20. Verify  this  issue  on  PROD 20
  • 21. 21
  • 23. Run  test  to  see  it’s  fixed 23
  • 24. 24
  • 25. 25 Save  your  test  as  .html
  • 28. PHPUnit  to  the  rescue 28
  • 30. The  PHPUnit  TestCase 30 <?php class Example extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://www.theialive.com/"); } public function testMyTestCase() { $this->open("/"); $this->click("link=login"); $this->waitForPageToLoad("30000"); $this->type("id=email", "[email protected]"); $this->type("id=password", "test1234"); $this->click("id=signin"); $this->waitForPageToLoad("30000"); $this->click("link=Test demo"); $this->waitForPageToLoad("30000"); $this->assertEquals("Done", $this->getText("xpath=//th[5]")); $this->click("link=[EDIT]"); $this->waitForPageToLoad("30000"); $this->assertTrue($this->isElementPresent("id=done")); $this->click("link=sign off"); $this->waitForPageToLoad("30000"); } } ?>
  • 31. Change  class  name 31 <?php class Example extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://www.theialive.com/"); } public function testMyTestCase() { $this->open("/"); $this->click("link=login"); $this->waitForPageToLoad("30000"); $this->type("id=email", "[email protected]"); $this->type("id=password", "test1234"); $this->click("id=signin"); $this->waitForPageToLoad("30000"); $this->click("link=Test demo"); $this->waitForPageToLoad("30000"); $this->assertEquals("Done", $this->getText("xpath=//th[5]")); $this->click("link=[EDIT]"); $this->waitForPageToLoad("30000"); $this->assertTrue($this->isElementPresent("id=done")); $this->click("link=sign off"); $this->waitForPageToLoad("30000"); } } ?> class MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase
  • 32. The  PHPUnit  TestCase 32 <?php class MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*chrome"); $this->setBrowserUrl("http://www.theialive.com/"); } public function testMyTestCase() { $this->open("/"); $this->click("link=login"); $this->waitForPageToLoad("30000"); $this->type("id=email", "[email protected]"); $this->type("id=password", "test1234"); $this->click("id=signin"); $this->waitForPageToLoad("30000"); $this->click("link=Test demo"); $this->waitForPageToLoad("30000"); $this->assertEquals("Done", $this->getText("xpath=//th[5]")); $this->click("link=[EDIT]"); $this->waitForPageToLoad("30000"); $this->assertTrue($this->isElementPresent("id=done")); $this->click("link=sign off"); $this->waitForPageToLoad("30000"); } } ?> protected function setUp() { $this->setBrowser("*iexplore"); $this->setBrowserUrl("http://www.theialive.com/"); $this->setHost('192.168.56.101'); $this->setPort(12666); }
  • 33. Meaningful  method  name <?php class MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase { protected function setUp() { $this->setBrowser("*iexplore"); $this->setBrowserUrl("http://www.theialive.com/"); $this->setHost('192.168.56.101'); $this->setPort(12666); } public function testMyTestCase() { $this->open("/"); $this->click("link=login"); $this->waitForPageToLoad("30000"); $this->type("id=email", "[email protected]"); $this->type("id=password", "test1234"); $this->click("id=signin"); $this->waitForPageToLoad("30000"); $this->click("link=Test demo"); $this->waitForPageToLoad("30000"); $this->assertEquals("Done", $this->getText("xpath=//th[5]")); $this->click("link=[EDIT]"); $this->waitForPageToLoad("30000"); $this->assertTrue($this->isElementPresent("id=done")); $this->click("link=sign off"); $this->waitForPageToLoad("30000"); } } ?> 33 public function testMarkTestAsDone()
  • 34. startSeleniumStandAlone.BAT 34 "C:Program FilesJavajre7binjava.exe" -jar "C:Usersuser Downloadsselenium-server-standalone-2.28.0.jar" -port 12666
  • 35. Now  run  your  tests 35
  • 37. How  it  runs  on  the  node 37
  • 39. Advantages 39 • You  can  start  tes'ng  immediately • Even  test  “hard  to  test”  kind  of  situa'ons • More  nodes  for  parallel  tes'ng • Tes'ng  different  browsers  and  plaborms • Con'nuous  Integra'on  possible
  • 40. Selenium  Grid  Setup 40 Selenium Testing CI Server Windows "HUB" Linux client "NODE" CI executes tests Windows HUB launches Selenium node clients to execute tests Windows Server collects feedback from the Citrix client nodes and reports back to CI Server Windows client "NODE" Mac OS X client "NODE" Continuous User Acceptance Testing
  • 43. Base  TestCase 43 <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class TestCase extends PHPUnit_Extensions_SeleniumTestCase { //const TEST_HUB = '217.21.179.192'; const TEST_HUB = '192.168.56.101'; const TEST_PORT = 12666; const USERNAME = '[email protected]'; const PASSWORD = 'test1234'; const BASURL = 'http://www.theialive.com'; public static $browsers = array ( array ( 'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Firefox on Windows 7', 'browser' => '*firefox', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), ); protected function setUp() { $this->setBrowserUrl(self::BASURL); } }
  • 44. Base  TestCase 44 <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class TestCase extends PHPUnit_Extensions_SeleniumTestCase { //const TEST_HUB = '217.21.179.192'; const TEST_HUB = '192.168.56.101'; const TEST_PORT = 12666; const USERNAME = '[email protected]'; const PASSWORD = 'test1234'; const BASURL = 'http://www.theialive.com'; public static $browsers = array ( array ( 'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Firefox on Windows 7', 'browser' => '*firefox', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), ); protected function setUp() { $this->setBrowserUrl(self::BASURL); } } array ( 'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ),
  • 45. Base  TestCase 45 <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class TestCase extends PHPUnit_Extensions_SeleniumTestCase { //const TEST_HUB = '217.21.179.192'; const TEST_HUB = '192.168.56.101'; const TEST_PORT = 12666; const USERNAME = '[email protected]'; const PASSWORD = 'test1234'; const BASURL = 'http://www.theialive.com'; public static $browsers = array ( array ( 'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Firefox on Windows 7', 'browser' => '*firefox', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), ); protected function setUp() { $this->setBrowserUrl(self::BASURL); } } array ( 'name' => 'Firefox on Windows 7', 'browser' => '*firefox', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ),
  • 46. Base  TestCase 46 <?php require_once 'PHPUnit/Extensions/SeleniumTestCase.php'; class TestCase extends PHPUnit_Extensions_SeleniumTestCase { //const TEST_HUB = '217.21.179.192'; const TEST_HUB = '192.168.56.101'; const TEST_PORT = 12666; const USERNAME = '[email protected]'; const PASSWORD = 'test1234'; const BASURL = 'http://www.theialive.com'; public static $browsers = array ( array ( 'name' => 'Internet Explorer 8 on Windows 7', 'browser' => '*iexplore', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Firefox on Windows 7', 'browser' => '*firefox', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), array ( 'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ), ); protected function setUp() { $this->setBrowserUrl(self::BASURL); } } array ( 'name' => 'Google Chrome on Windows 7', 'browser' => '*googlechrome', 'host' => self::TEST_HUB, 'port' => self::TEST_PORT, ),
  • 47. Modify  MarkTaskDoneTest   <?php /** * Class MarkTaskDoneTest * * @group Selenium */ require_once 'TestCase.php'; class MarkTaskDoneTest extends TestCase { public function testMarkTestAsDone() { $this->open("/"); $this->click("link=login"); $this->waitForPageToLoad("30000"); $this->type("id=email", TestCase::USERNAME); $this->type("id=password", TestCase::PASSWORD); $this->click("id=signin"); $this->waitForPageToLoad("30000"); $this->click("link=Test demo"); $this->waitForPageToLoad("30000"); $this->assertEquals("Done", $this->getText("xpath=//th[5]")); $this->click("link=[EDIT]"); $this->waitForPageToLoad("30000"); $this->assertTrue($this->isElementPresent("id=done")); $this->click("link=sign off"); $this->waitForPageToLoad("30000"); } } 47 Require the TestCase and extend it
  • 49. 49
  • 50. Benefits • run  your  tests  on  mul'ple  browsers • detect  flaws  in  specific  browsers  (e.g.  IE6) -­‐ adapt  your  apps  to  solve  these  flaws 50
  • 52. 52
  • 56. Credits 56 • apple  store:  hOp://www.flickr.com/photos/jtjdt/3571748777 • checklist:  hOp://www.flickr.com/photos/alancleaver/4439276478 • flat  're:  hOp://www.flickr.com/photos/anijdam/2468493546/ • first  place:  hOp://www.flickr.com/photos/evelynishere/ 3417340248/ • gears:  hOp://www.flickr.com/photos/wwarby/4782904694 • steps:  hOp://www.flickr.com/photos/ben_salter/1407168763 • browsers:  hOp://www.flickr.com/photos/richoz/3791167457 • gears:  hOp://www.flickr.com/photos/freefoto/5982549938 • danger:  hOp://www.flickr.com/photos/armchairbuilder/ 7345497766 • informa'on:  hOp://www.flickr.com/photos/twicepix/2650241408/ • elephpant:  hOp://www.flickr.com/photos/drewm/3191872515
  • 57. Contact 57 Michelangelo van Dam Zend Certified Engineer email: [email protected] skype: michelangelovandam twitter: @DragonBe tel EU: +32 15 34 52 90 tel US: 202 559-7401 www.in2it.be facebook.com/in2itvof | @in2itvof Contact us for Consultancy - Training - QA - Webdesign