Your SlideShare is downloading. ×
0
Selenium 2for PHP(Unit)      Fabrizio Branca               T3DD12
Fabrizio BrancaSystem DeveloperAOE mediaWiesbadenTYPO3 & MagentoTwitter: @fbrncBlog: http://www.fabrizio-branca.de
You?!• Who has any experience with automated  testing? (PHPUnit,…)• Who has used Selenium 1?• Who has used Selenium 2 / We...
http://www.flickr.com/photos/dieselbug2007/414348333/
Testing•   Unit testing•   Performance testing•   Load testing•   Integration testing•   Acceptance testing
What is Selenium?
Selenium’s Tool Suite• Selenium IDE• Selenium 1  (aka. Selenium RC or Remote Control)• Selenium 2  (aka. Selenium Webdrive...
Selenium Architecture
Selenium + WebDriver       2004:                          2006: Selenium                       WebDriver   (Jason Huggins,...
Why Selenium 2?• New possibilities  – File uploads  – Browser functions (back/forward)  – Switch between urls  – Control m...
Selenium 2•   Firefox•   HTMLUnit•   IE•   Chrome (needs extra driver)•   iPhone / iPad•   Android•   …
Selenium Server• Download:  http://seleniumhq.org/download/• Launch: start java -jar C:ProgrammeSeleniumselenium-server-st...
Rest API• http://code.google.com/p/selenium/wiki/Js  onWireProtocol• Json over HTTP
PHP Api• Selenium 1: PHPUnit_Selenium  (Sebastian Bergmann)• Selenium 2  – REST-Service (Json over HTTP)  – Implementation...
php-webdriver• „A very thin wrapper of WebDriver“• Server API (Json over HTTP)
„Menta“ – Selenium Framework
Why „Menta“?
Menta• Selenium Testing Framework• Connects to Selenium 2• Build on top of php-webdriver• Developer friendly api to raw Se...
Menta• Requires PHP 5.3 (using closures)• Session management (incl. close on CTRL+C and  fatal php errors)• Event/Observer...
Components• PageObjects• http://www.typo3-media.com/blog/window-driver-page-object-  selenium-tests.html• Other general pu...
Configuration• PHPUnit• default.xml + phpunit.xml• Menta bootstrap.php
File structure
Selecting elements$element = $this->getSession()->element(array(   using => WebDriver_Container::XPATH,   value => //ul/li...
Interacting with elements•   $element->click();•   $this->getSession()->click();•   $this->getSession()->buttondown();•   ...
Session Management•   Capabilities•   Menta_SessionManager•   ->getSession($forceNew = false);•   ->activeSessionExists()•...
Implicit Wait• Implicitly waiting for elements that are not  available yet
Screenshots• Explict screenshots• Automatically taking screenshots on errors  and failing tests and embed them into html  ...
Demo
CI integration       Build                  Install on                 Unit tests      package                   latest   ...
Verbose Result Printer
HTML Result
Further reading• http://www.qaautomation.net/?p=365• http://www.qaautomation.net/?p=498• http://css.dzone.com/articles/sel...
Questions?Twitter:   @fbrncBlog:      http://www.fabrizio-branca.de
Upcoming SlideShare
Loading in...5
×

Selenium 2 for PHP(Unit)

11,524

Published on

Transcript of "Selenium 2 for PHP(Unit)"

  1. 1. Selenium 2for PHP(Unit) Fabrizio Branca T3DD12
  2. 2. Fabrizio BrancaSystem DeveloperAOE mediaWiesbadenTYPO3 & MagentoTwitter: @fbrncBlog: http://www.fabrizio-branca.de
  3. 3. You?!• Who has any experience with automated testing? (PHPUnit,…)• Who has used Selenium 1?• Who has used Selenium 2 / Webdriver?
  4. 4. http://www.flickr.com/photos/dieselbug2007/414348333/
  5. 5. Testing• Unit testing• Performance testing• Load testing• Integration testing• Acceptance testing
  6. 6. What is Selenium?
  7. 7. Selenium’s Tool Suite• Selenium IDE• Selenium 1 (aka. Selenium RC or Remote Control)• Selenium 2 (aka. Selenium Webdriver)• Selenium-Grid
  8. 8. Selenium Architecture
  9. 9. Selenium + WebDriver 2004: 2006: Selenium WebDriver (Jason Huggins, (Simon Stewart, ThoughtWorks) Google) 2009: Selenium 2
  10. 10. Why Selenium 2?• New possibilities – File uploads – Browser functions (back/forward) – Switch between urls – Control mouse• Different behaviour – Typing into input boxes – Interacting with invisible elements – Viewport
  11. 11. Selenium 2• Firefox• HTMLUnit• IE• Chrome (needs extra driver)• iPhone / iPad• Android• …
  12. 12. Selenium Server• Download: http://seleniumhq.org/download/• Launch: start java -jar C:ProgrammeSeleniumselenium-server-standalone-2.20.0.jar
  13. 13. Rest API• http://code.google.com/p/selenium/wiki/Js onWireProtocol• Json over HTTP
  14. 14. PHP Api• Selenium 1: PHPUnit_Selenium (Sebastian Bergmann)• Selenium 2 – REST-Service (Json over HTTP) – Implementations: • PHPUnit_Selenium • https://github.com/chibimagic/WebDriver-PHP/ • http://code.google.com/p/php-webdriver-bindings/ • https://github.com/facebook/php-webdriver https://github.com/robocoder/php-webdriver https://github.com/fbrnc/php-webdriver
  15. 15. php-webdriver• „A very thin wrapper of WebDriver“• Server API (Json over HTTP)
  16. 16. „Menta“ – Selenium Framework
  17. 17. Why „Menta“?
  18. 18. Menta• Selenium Testing Framework• Connects to Selenium 2• Build on top of php-webdriver• Developer friendly api to raw Selenium commands• Drop-In replacement for PHPUnit- Selenium• https://github.com/fbrnc/Menta
  19. 19. Menta• Requires PHP 5.3 (using closures)• Session management (incl. close on CTRL+C and fatal php errors)• Event/Observer• Configuration Management• Create Suite Utility• Listeners – HTML report (incl. Screenshots) – Verbose text report• Components• Abstract PHPUnit Testcases• Selenium1 facade
  20. 20. Components• PageObjects• http://www.typo3-media.com/blog/window-driver-page-object- selenium-tests.html• Other general purpose components – WebServiceApi (Magento) – Curl – HTML/CSS/JS Validator – Imap
  21. 21. Configuration• PHPUnit• default.xml + phpunit.xml• Menta bootstrap.php
  22. 22. File structure
  23. 23. Selecting elements$element = $this->getSession()->element(array( using => WebDriver_Container::XPATH, value => //ul/li);# ... or ...$helper = Menta_ComponentManager::get( Menta_Component_Helper_Common);$element = $helper->getElement(css=#menu li.first);
  24. 24. Interacting with elements• $element->click();• $this->getSession()->click();• $this->getSession()->buttondown();• $this->getSession()->buttonup();• $this->getSession()->touch();• $this->getSession()->moveto();
  25. 25. Session Management• Capabilities• Menta_SessionManager• ->getSession($forceNew = false);• ->activeSessionExists()• ->closeSession()• Automatic closing sessions on errors and end of tests
  26. 26. Implicit Wait• Implicitly waiting for elements that are not available yet
  27. 27. Screenshots• Explict screenshots• Automatically taking screenshots on errors and failing tests and embed them into html report (on client side)
  28. 28. Demo
  29. 29. CI integration Build Install on Unit tests package latest Selenium Install on QA tests deploy Load Install on Install on tests stage production
  30. 30. Verbose Result Printer
  31. 31. HTML Result
  32. 32. Further reading• http://www.qaautomation.net/?p=365• http://www.qaautomation.net/?p=498• http://css.dzone.com/articles/selenium-2- php-code• http://rostislav- matl.blogspot.de/2011/03/moving-to- selenium-2-on-webdriver-part.html
  33. 33. Questions?Twitter: @fbrncBlog: http://www.fabrizio-branca.de
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×