Fabrizio Branca
T3DD12
Selenium 2
for PHP(Unit)
System Developer
AOE media
Wiesbaden
TYPO3 & Magento
Twitter: @fbrnc
Blog: http://www.fabrizio-branca.de
Fabrizio Branca
• Who has any experience with automated
testing? (PHPUnit,…)
• Who has used Selenium 1?
• Who has used Selenium 2 / Webdriver?
You?!
http://www.flickr.com/photos/dieselbug2007/414348333/
• Unit testing
• Performance testing
• Load testing
• Integration testing
• Acceptance testing
Testing
What is Selenium?
• Selenium IDE
• Selenium 1
(aka. Selenium RC or Remote Control)
• Selenium 2
(aka. Selenium Webdriver)
• Selenium-Grid
Selenium’s Tool Suite
Selenium Architecture
Selenium + WebDriver
2004:
Selenium
(Jason Huggins,
ThoughtWorks)
2006:
WebDriver
(Simon Stewart,
Google)
2009:
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
Why Selenium 2?
• Firefox
• HTMLUnit
• IE
• Chrome (needs extra driver)
• iPhone / iPad
• Android
• …
Selenium 2
• Download:
http://seleniumhq.org/download/
• Launch:
start java -jar C:ProgrammeSeleniumselenium-server-standalone-2.20.0.jar
Selenium Server
• http://code.google.com/p/selenium/wiki/Js
onWireProtocol
• Json over HTTP
Rest 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
PHP Api
• „A very thin wrapper of WebDriver“
• Server API (Json over HTTP)
php-webdriver
„Menta“ – Selenium Framework
Why „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
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
Menta
• 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
Components
• PHPUnit
• default.xml + phpunit.xml
• Menta bootstrap.php
Configuration
File structure
$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');
Selecting elements
• $element->click();
• $this->getSession()->click();
• $this->getSession()->buttondown();
• $this->getSession()->buttonup();
• $this->getSession()->touch();
• $this->getSession()->moveto();
Interacting with elements
• Capabilities
• Menta_SessionManager
• ->getSession($forceNew = false);
• ->activeSessionExists()
• ->closeSession()
• Automatic closing sessions on errors and
end of tests
Session Management
• Implicitly waiting for elements that are not
available yet
Implicit Wait
• Explict screenshots
• Automatically taking screenshots on errors
and failing tests and embed them into html
report (on client side)
Screenshots
Demo
CI integration
Build
package
Unit tests
Install on
latest
Selenium
tests
Install on
deploy
QA
Load
tests
Install on
stage
Install on
production
Verbose Result Printer
HTML Result
• 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
Further reading
Questions?
Twitter: @fbrnc
Blog: http://www.fabrizio-branca.de

Selenium 2 for PHP(Unit)