Save 37% off PRO during our Black Friday Sale! »

UA Testing with Selenium and PHPUnit - SunshinePHP 2014

8fc45f4725efe8e8bc8d6c1f92224b65?s=47 Michelangelo
February 08, 2014

UA Testing with Selenium and PHPUnit - SunshinePHP 2014

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 (VMs) so you can test all different browsers on a diversity of operating systems.

8fc45f4725efe8e8bc8d6c1f92224b65?s=128

Michelangelo

February 08, 2014
Tweet

Transcript

  1. UA  Tes'ng  with Selenium  and  PHPUnit

  2. None
  3. None
  4. Today’s  goal • Set  up  and  use  Selenium  IDE  

    • Record  UA  tests   • Convert  to  PHPUnit   • Run  con'nuously   • Mul'  browser  support
  5. None
  6. User  Acceptance

  7. None
  8. Checklist  for  web  applica'ons

  9. None
  10. A  word  of  cau'on!

  11. Browser  support

  12. Selenium  to  the  rescue

  13. Plugin  for  firefox

  14. Get  the  plugin  (demo)

  15. None
  16. Let’s  get  started

  17. Pick  a  test  case

  18. Issue  #7

  19. Verify  this  issue  on  PROD

  20. None
  21. Fix  the  issue

  22. Run  test  to  see  it’s  fixed

  23. None
  24. None
  25. It’s  that  easy!

  26. Automated  Tes'ng

  27. PHPUnit  to  the  rescue

  28. Export  to  PHPUnit

  29. The  PHPUnit  TestCase

  30. Change  class  name

  31. The  PHPUnit  TestCase

  32. 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. startSeleniumStandAlone.BAT

  34. Now  run  your  tests

  35. None
  36. How  it  runs  on  the  node

  37. None
  38. Advantages

  39. Next  Steps

  40. Mul'  Browser  support

  41. Base  TestCase

  42. Base  TestCase

  43. Base  TestCase

  44. Base  TestCase

  45. 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"); } }
  46. Running  test

  47. None
  48. Benefits • run  your  tests  on  mul'ple  browsers   •

    detect  flaws  in  specific  browsers  (e.g.  IE6)   -­‐ adapt  your  apps  to  solve  these  flaws
  49. Mul'ple  Node  Setup

  50. The  GRID

  51. Selenium  Grid  Setup

  52. Star'ng  the  server  [HUB]

  53. Star'ng  the  client  [NODE]

  54. Mul'ple  nodes

  55. Problem

  56. Modify  Base  TestCase

  57. More  informa'on

  58. seleniumhq.org

  59. phpunit.de

  60. Credits

  61. Contact

  62. None
  63. Thank  you