UA	  Tesng	  withSelenium	  and	  PHPUnitphp[tek]	  2013	  -­‐	  Chicago
2• PHP	  Consultant• President	  PHPBenelux• Conference	  speakerMichelangelo	  van	  Dam
3
Today’s	  goal• Set	  up	  and	  use	  Selenium	  IDE• Record	  UA	  tests• Convert	  to	  PHPUnit• Run	  connuously• Mul	...
5DISCLAIMERS E L E N I U M T E S T S A R E N OT AREPLACEMENT FOR REGULAR UNITTESTING. THEY ONLY PROVIDE ANADDITIONAL SET O...
User	  Acceptance6
7“Acceptance testing is a test conducted to determine ifthe requirements of a specification or contract are met.”-- source:...
Checklist	  for	  web	  applicaons8
9Funconal	  tesng• Test	  funconal	  requirements-­‐ e.g.	  no	  access	  to	  profile	  without	  authencaon• Test	  UI	  ...
A	  word	  of	  cauon!10• UA	  tests	  only	  test	  generated	  output-­‐ not	  a	  replacement	  for	  unit	  tesng• UA	...
Browser	  support11
Selenium	  to	  the	  rescue12
Plugin	  for	  firefox13
Get	  the	  plugin	  (demo)14
Let’s	  get	  started16
Pick	  a	  test	  case17
Issue	  #718
Verify	  this	  issue	  on	  PROD19
20
Fix	  the	  issue21
Run	  test	  to	  see	  it’s	  fixed22
23
24Save	  your	  test	  as	  .html
It’s	  that	  easy!25
Automated	  Tesng26
PHPUnit	  to	  the	  rescue27
Export	  to	  PHPUnit28
The	  PHPUnit	  TestCase29<?phpclass Example extends PHPUnit_Extensions_SeleniumTestCase{protected function setUp(){$this-...
Change	  class	  name30<?phpclass Example extends PHPUnit_Extensions_SeleniumTestCase{protected function setUp(){$this->se...
The	  PHPUnit	  TestCase31<?phpclass MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase{protected function setUp...
Meaningful	  method	  name<?phpclass MarkTaskDoneTest extends PHPUnit_Extensions_SeleniumTestCase{protected function setUp...
startSeleniumStandAlone.BAT33"C:Program FilesJavajre7binjava.exe" -jar "C:UsersuserDownloadsselenium-server-standalone-2.2...
Now	  run	  your	  tests34
How	  it	  runs	  on	  the	  node36
Advantages38• You	  can	  start	  tesng	  immediately• Even	  test	  “hard	  to	  test”	  kind	  of	  situaons• More	  nod...
Selenium	  Grid	  Setup39Selenium TestingCI Server Windows"HUB"Linux client"NODE"CI executes testsWindows HUB launchesSele...
Next	  Steps40
Mul	  Browser	  support41
Base	  TestCase42<?phprequire_once PHPUnit/Extensions/SeleniumTestCase.php;class TestCase extends PHPUnit_Extensions_Selen...
Base	  TestCase43<?phprequire_once PHPUnit/Extensions/SeleniumTestCase.php;class TestCase extends PHPUnit_Extensions_Selen...
Base	  TestCase44<?phprequire_once PHPUnit/Extensions/SeleniumTestCase.php;class TestCase extends PHPUnit_Extensions_Selen...
Base	  TestCase45<?phprequire_once PHPUnit/Extensions/SeleniumTestCase.php;class TestCase extends PHPUnit_Extensions_Selen...
Modify	  MarkTaskDoneTest	  <?php/*** Class MarkTaskDoneTest** @group Selenium*/require_once TestCase.php;class MarkTaskDo...
Running	  test47
48
Benefits• run	  your	  tests	  on	  mulple	  browsers• detect	  flaws	  in	  specific	  browsers	  (e.g.	  IE6)-­‐ adapt	  yo...
More	  informaon50
seleniumhq.org51
phpunit.de52http://www.phpunit.de/manual/3.5/en/selenium.html
Credits53• apple	  store:	  hSp://www.flickr.com/photos/jtjdt/3571748777• checklist:	  hSp://www.flickr.com/photos/alancleav...
Contact54Michelangelo van DamZend Certified Engineeremail: michelangelo@in2it.beskype: michelangelovandamtwitter: @DragonBe...
55https://joind.in/8157
Thank	  you56
UA testing with selenium and php unit
UA testing with selenium and php unit
UA testing with selenium and php unit
Upcoming SlideShare
Loading in …5
×

UA testing with selenium and php unit

20,803 views

Published on

Nothing is as frustrated as deploying a new release of your web application to find out functionality you had doesn't work anymore. Of course you have all your unit tests in place and you run them through your CI environment, but nothing prepared you to a failing javascript error or a link that doesn't work anymore. Welcome to User Acceptance testing or UAT. Before you start putting real people in front of your application, create macros and export them as PHPUnit test classes. Then run them in an automated way just like your unit tests and hook them into your CI. In this talk I will show you how easy it is to create Selenium macros that can be converted into PHPUnit scripts and run automatically on different virtual machines (VM's) so you can test all different browsers on a diversity of operating systems.

Published in: Technology
2 Comments
2 Likes
Statistics
Notes
  • You can export the Selenium test to PHPUnit test and have the username stored in a config outside the test file (as shown in my examples).

    Once the database changes, chances are your interface needs to have small or larger updates. You can easily update your unit test to deal with these changes.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi
    I want to make a test for a Login. What I want to know is how I proceed if the database changes because Selenium keeps information in html and the username and password are hard coded in html.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
20,803
On SlideShare
0
From Embeds
0
Number of Embeds
14,182
Actions
Shares
0
Downloads
37
Comments
2
Likes
2
Embeds 0
No embeds

No notes for slide

UA testing with selenium and php unit

  1. 1. UA  Tesng  withSelenium  and  PHPUnitphp[tek]  2013  -­‐  Chicago
  2. 2. 2• PHP  Consultant• President  PHPBenelux• Conference  speakerMichelangelo  van  Dam
  3. 3. 3
  4. 4. Today’s  goal• Set  up  and  use  Selenium  IDE• Record  UA  tests• Convert  to  PHPUnit• Run  connuously• Mul  browser  support4
  5. 5. 5DISCLAIMERS E L E N I U M T E S T S A R E N OT AREPLACEMENT FOR REGULAR UNITTESTING. THEY ONLY PROVIDE ANADDITIONAL SET OF TESTS FOCUSEDON USER ACCEPTANCE AND USEREXPERIENCE TESTING.For more information about unit testing, pleasesee my other material on www.slideshare.net andwww.speakerdeck.com. Search for “dragonbe”!
  6. 6. User  Acceptance6
  7. 7. 7“Acceptance testing is a test conducted to determine ifthe requirements of a specification or contract are met.”-- source: wikipedia
  8. 8. Checklist  for  web  applicaons8
  9. 9. 9Funconal  tesng• Test  funconal  requirements-­‐ e.g.  no  access  to  profile  without  authencaon• Test  UI  elements  on  the  web  interface-­‐ e.g.  buSons,  form  elements,  AJAX  controls,  …
  10. 10. A  word  of  cauon!10• UA  tests  only  test  generated  output-­‐ not  a  replacement  for  unit  tesng• UA  tests  are  heavily  depending  on  DOM-­‐ changes  to  the  DOM  might  lead  to  failing  UAT
  11. 11. Browser  support11
  12. 12. Selenium  to  the  rescue12
  13. 13. Plugin  for  firefox13
  14. 14. Get  the  plugin  (demo)14
  15. 15. Let’s  get  started16
  16. 16. Pick  a  test  case17
  17. 17. Issue  #718
  18. 18. Verify  this  issue  on  PROD19
  19. 19. 20
  20. 20. Fix  the  issue21
  21. 21. Run  test  to  see  it’s  fixed22
  22. 22. 23
  23. 23. 24Save  your  test  as  .html
  24. 24. It’s  that  easy!25
  25. 25. Automated  Tesng26
  26. 26. PHPUnit  to  the  rescue27
  27. 27. Export  to  PHPUnit28
  28. 28. The  PHPUnit  TestCase29<?phpclass 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");}}?>
  29. 29. Change  class  name30<?phpclass 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
  30. 30. The  PHPUnit  TestCase31<?phpclass 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);}
  31. 31. Meaningful  method  name<?phpclass 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");}}?>32public function testMarkTestAsDone()
  32. 32. startSeleniumStandAlone.BAT33"C:Program FilesJavajre7binjava.exe" -jar "C:UsersuserDownloadsselenium-server-standalone-2.28.0.jar" -port 12666
  33. 33. Now  run  your  tests34
  34. 34. How  it  runs  on  the  node36
  35. 35. Advantages38• You  can  start  tesng  immediately• Even  test  “hard  to  test”  kind  of  situaons• More  nodes  for  parallel  tesng• Tesng  different  browsers  and  plaforms• Connuous  Integraon  possible
  36. 36. Selenium  Grid  Setup39Selenium TestingCI Server Windows"HUB"Linux client"NODE"CI executes testsWindows HUB launchesSelenium node clientsto execute testsWindows Server collectsfeedback from the Citrixclient nodes and reportsback to CI ServerWindows client"NODE"Mac OS X client"NODE"Continuous User Acceptance Testing
  37. 37. Next  Steps40
  38. 38. Mul  Browser  support41
  39. 39. Base  TestCase42<?phprequire_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);}}
  40. 40. Base  TestCase43<?phprequire_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,),
  41. 41. Base  TestCase44<?phprequire_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,),
  42. 42. Base  TestCase45<?phprequire_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,),
  43. 43. 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");}}46Require the TestCaseand extend it
  44. 44. Running  test47
  45. 45. 48
  46. 46. Benefits• run  your  tests  on  mulple  browsers• detect  flaws  in  specific  browsers  (e.g.  IE6)-­‐ adapt  your  apps  to  solve  these  flaws49
  47. 47. More  informaon50
  48. 48. seleniumhq.org51
  49. 49. phpunit.de52http://www.phpunit.de/manual/3.5/en/selenium.html
  50. 50. Credits53• apple  store:  hSp://www.flickr.com/photos/jtjdt/3571748777• checklist:  hSp://www.flickr.com/photos/alancleaver/4439276478• flat  re:  hSp://www.flickr.com/photos/anijdam/2468493546/• first  place:  hSp://www.flickr.com/photos/evelynishere/3417340248/• gears:  hSp://www.flickr.com/photos/wwarby/4782904694• steps:  hSp://www.flickr.com/photos/ben_salter/1407168763• browsers:  hSp://www.flickr.com/photos/richoz/3791167457• informaon:  hSp://www.flickr.com/photos/twicepix/2650241408/• elephpant:  hSp://www.flickr.com/photos/drewm/3191872515
  51. 51. Contact54Michelangelo van DamZend Certified Engineeremail: michelangelo@in2it.beskype: michelangelovandamtwitter: @DragonBetel EU: +32 15 34 52 90tel US: 202 559-7401www.in2it.befacebook.com/in2itvof | @in2itvofContact us forConsultancy - Training - QA - Webdesign
  52. 52. 55https://joind.in/8157
  53. 53. Thank  you56

×