UA Testing with Selenium and PHPUnit DPC 2013

  • 666 views
Uploaded 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 …

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.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
666
On Slideshare
0
From Embeds
0
Number of Embeds
6

Actions

Shares
Downloads
5
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. UA  Tesng  withSelenium  and  PHPUnitDutch  PHP  Conference  2013,  Amsterdam
  • 2. 2• PHP  Consultant• President  PHPBenelux• Conference  speakerMichelangelo  van  Dam
  • 3. 3
  • 4. Today’s  goal• Set  up  and  use  Selenium  IDE• Record  UA  tests• Convert  to  PHPUnit• Run  connuously• Mul  browser  support4
  • 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. User  Acceptance6
  • 7. 7“Acceptance testing is a test conducted to determine ifthe requirements of a specification or contract are met.”-- source: wikipedia
  • 8. Checklist  for  web  applicaons8
  • 9. 9Funconal  tesng• Test  funconal  requirements-­‐ e.g.  no  access  to  profile  without  authencaon• Test  UI  elements  on  the  web  interface-­‐ e.g.  buQons,  form  elements,  AJAX  controls,  …
  • 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. Browser  support11
  • 12. Selenium  to  the  rescue12
  • 13. Plugin  for  firefox13
  • 14. Get  the  plugin  (demo)14
  • 15. Let’s  get  started16
  • 16. Pick  a  test  case17
  • 17. Issue  #718
  • 18. Verify  this  issue  on  PROD19
  • 19. 20
  • 20. Fix  the  issue21
  • 21. Run  test  to  see  it’s  fixed22
  • 22. 23
  • 23. 24Save  your  test  as  .html
  • 24. It’s  that  easy!25
  • 25. Automated  Tesng26
  • 26. PHPUnit  to  the  rescue27
  • 27. Export  to  PHPUnit28
  • 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. 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. 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. 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. startSeleniumStandAlone.BAT33"C:Program FilesJavajre7binjava.exe"-jar "C:Jarselenium-server-standalone-2.28.0.jar"-port 12666
  • 33. Now  run  your  tests34
  • 34. How  it  runs  on  the  node36
  • 35. Advantages38• You  can  start  tesng  immediately• Even  test  “hard  to  test”  kind  of  situaons• More  nodes  for  parallel  tesng• Tesng  different  browsers  and  placorms• Connuous  Integraon  possible
  • 36. Next  Steps39
  • 37. Mul  Browser  support40
  • 38. Base  TestCase41<?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);}}
  • 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);}}array (name => Internet Explorer 8 on Windows 7,browser => *iexplore,host => self::TEST_HUB,port => self::TEST_PORT,),
  • 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 => Firefox on Windows 7,browser => *firefox,host => self::TEST_HUB,port => self::TEST_PORT,),
  • 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 => Google Chrome on Windows 7,browser => *googlechrome,host => self::TEST_HUB,port => self::TEST_PORT,),
  • 42. 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");}}45Require the TestCaseand extend it
  • 43. Running  test46
  • 44. 47
  • 45. Benefits• run  your  tests  on  mulple  browsers• detect  flaws  in  specific  browsers  (e.g.  IE6)-­‐ adapt  your  apps  to  solve  these  flaws48
  • 46. Mulple  Node  Setup49
  • 47. The  GRID50• Procedure-­‐ centralized  server  (HUB)-­‐ commands  clients  (nodes)  registered-­‐ and  executes  the  tests• Goal-­‐ allow  for  automaon-­‐ adding  clients  as  you  go
  • 48. Selenium  Grid  Setup51Selenium 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
  • 49. Starng  the  server  [HUB]52"C:Program FilesJavajre7binjava.exe"-jar "C:Jarselenium-server-standalone-2.28.0.jar"-role hub-port 12666
  • 50. Starng  the  client  [NODE]53"C:Program FilesJavajre7binjava.exe"-jar "C:Jarselenium-server-standalone-2.28.0.jar"-role node-host 192.168.56.103-port 13666-hub http://192.168.56.101:12666/grid/register
  • 51. Mulple  nodes54
  • 52. Problem55
  • 53. Modify  Base  TestCase56<?phprequire_once PHPUnit/Extensions/SeleniumTestCase.php;class TestCase extends PHPUnit_Extensions_SeleniumTestCase{//const TEST_HUB = 217.21.179.192;const TEST_HUB_WIN = 192.168.56.101;const TEST_HUB_MAC = 192.168.56.1;const TEST_HUB_LINUX = 192.168.56.102;const TEST_PORT = 13666;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_WIN, port => self::TEST_PORT,),array (name => Firefox on Mac OS X, browser => *firefox,host => self::TEST_HUB_MAC, port => self::TEST_PORT,),array (name => Google Chrome on Linux, browser => *googlechrome,host => self::TEST_HUB_LINUX, port => self::TEST_PORT,),);protected function setUp(){$this->setBrowserUrl(self::BASURL);}}
  • 54. More  informaon57
  • 55. seleniumhq.org58
  • 56. phpunit.de59http://www.phpunit.de/manual/3.5/en/selenium.html
  • 57. Credits60• apple  store:  hQp://www.flickr.com/photos/jtjdt/3571748777• checklist:  hQp://www.flickr.com/photos/alancleaver/4439276478• flat  re:  hQp://www.flickr.com/photos/anijdam/2468493546/• first  place:  hQp://www.flickr.com/photos/evelynishere/3417340248/• gears:  hQp://www.flickr.com/photos/wwarby/4782904694• steps:  hQp://www.flickr.com/photos/ben_salter/1407168763• browsers:  hQp://www.flickr.com/photos/richoz/3791167457• informaon:  hQp://www.flickr.com/photos/twicepix/2650241408/• elephpant:  hQp://www.flickr.com/photos/drewm/3191872515
  • 58. Contact61Michelangelo 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
  • 59. 62http://joind.in/8813
  • 60. Thank  you63