2. Nick Belhomme
International Conference Speaker
Contributor to various Open Source
Projects
Building Constructor
Software Architect / Project Lead
Loving Husband
Freelance PHP Consultant
PHP QA trainer
Your host for the upcoming hour
3. Selenium
34
Claims, Benefits:
Prevents cancer
Aging
8. Tools
● Humans
● Capture and replay
● Scripts and bots
● Selenium
9. Manual Testing
● Time-intensive
● Nerve-stretching
● Human error / understanding of the flow
● Costly
10. Capture and Replay
● Captures mouse movements and inputs
● Replays later
● Screenresolution, operating systems, window
sizes, makes this very unmaintainable
11. Scripts and Bots
● Bot makes screen-shots, analyzes them for
visual blocks
● Calculates visual blocks x-y positions and
generates mouse clicks on that location and
user input.
● Generating a test is time-intensive
● Error prone on design changes.
12. Selenium
● Records and playback browser tests
● Asserts on DOM
● Javascript is being executed and testable
● Css selectors or xpath position sensitive
● Hard to detect layout errors
13. Learning Curve
● Jump in quickly
● Steep – If you want to do it right
● Mastering it – creating readable,
understandable, maintainable and robust tests -
takes time and effort.
14. Worth it
Ask a Salary
Increase
and
own a second
modest
vacation property
15. And as an added bonus
● Better code architecture
● More functional code
● High browser compatibility
● No more regressions
● Neat cool stuff to brag about at your local pub!!!
17. Selenium IDE
Firefox Plugin:
http://release.seleniumhq.org/selenium-ide/1.10.0/selenium-ide-1.10.0.xpi
●
Easy record and playback
● Intelligent field selection will use IDs, names, or XPath as needed
●
Autocomplete for all common Selenium commands
● Walk through tests
●
Debug and set breakpoints
● Save tests as HTML, PHPUnit, or any other format
●
Support for Selenium user-extensions.js file
●
Option to automatically assert the title of every page
●
Easy customization through plugins
20. X-forwarding
run software on remote machine and display the GUI locally
● Linux and Mac OS X support X Forwarding with no extra
software
ssh -X
● Windows needs extra software
Xming
21. Xming
(X-forwarding for windows)
http://sourceforge.net/projects/xming/files/latest/download
Configure Xming
Windows Start => Xming => XLaunch
Display settings dialog box:
Multiple windows
Display number as 0
Keep clicking next then Finish.
22. Putty (windows)
● Connection => SSH => X11
● Enable X11 forwarding
● Set X display location as :0.0
25. Completely headless
(no X-forwarding)
● Install Xvfb
aptitude install Xvfb
● Update to latest java version
aptitude install sun-java6-jre
● Download the latest Selenium Server Jar
package
wget http://selenium.googlecode.com/files/selenium-
server-standalone-2.28.0.jar
26. Test driving Selenium RC
(X-forwarding)
To test-drive it is always easier to first use X-forwarding:
java -jar selenium-server-standalone-2.28.0.jar -htmlSuite
*firefox "http://www.domaintocheck.com"
“/path/to/selenium/testSuite.html”
“/path/where/selenium/should/store/results.html”
testSuite.html and related files are the files saved by Selenium IDE
27. Test driving Selenium RC
(X Virtual Frame Buffer)
● Open a connection and run Xvfb
Xvfb :99
● Open another connection and run selenium
export DISPLAY=:99 & java -jar selenium-server-
standalone-2.28.0.jar -htmlSuite *firefox
"http://www.domaintocheck.com"
“/path/to/selenium/testSuite.html”
“/path/where/selenium/should/store/results.html”
28. Integrate into
Make certain your Jenkins server is started with Xvfb run on :99
● Check with:
ps -ef | grep Xvfb
● If not running then issue a
Xvfb :99
CTRL + Z
● Log into Jenkins: manage Jenkins -> Manage Plugins
install “Hudson Seleniumhq plugin”
32. Problem
● remote control is slow at driving the browser.
● limited number of concurrent tests on the same
remote control before seriously impacting its
stability.
● Multiple Selenium Remote Controls In Jenkins
to work around the limitation on the number of
parallel tests.
33. The Grid
● Run tests against multiple browsers
● multiple versions of browser
● browsers running on different operating systems
● To reduce the time it takes for the test suite to
complete a test pass.
34.
35. The Hub
● 1 instance
● Allocating a Selenium Remote Control to a specific
test (transparently)
● Limiting the number of concurrent test runs on each
Remote Control
● Shielding the tests from the actual grid
infrastructure
36. A Node
● Remote Control
● Multiple instances (across machines preferably)
● Multiple Browsers
● Can be configured using a json file
47. The test case
<?php
class Example extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser("*iexplore");
$this->setBrowserUrl("http://www.nickbelhomme.com/");
}
public function testMyTestCase()
{
$this->open("/");
$this->assertTrue($this->isElementPresent("link=About"));
$this->assertTrue($this->isElementPresent("link=Consulting & Training"));
$this->assertTrue($this->isElementPresent("link=Blog"));
$this->assertTrue($this->isElementPresent("link=Contact"));
$name = $this->getEval(""nick"==="nick"");
}
}
?>
48. Run the test case
php phpunit.phar testcases/testMenu.php
Run the test suite
php phpunit.phar testcases
50. Use raw Html Selenese test
public function testMenu()
{
$this->runSelenese('testMenu.html')
}
Use raw Html Selenese testsuite
public static $seleneseDirectory = '/path/to/files';
56. Troubleshooting
● Firefox install dependencies
http://www.thinkplexx.com/learn/howto/linux/system/installing-
and-running-firefox-on-debian-linux-getting-missing-
dependencies-shared-libs
● Specify different ports in Jenkins for each RC when not using
the grid
● Proxy settings in Browser – use X-Forwarding to run Browser
and change settings, use profile as a RC param when needed.
57. Link to slides and other updates is
available at
http://www.facebook.com/NickBelhommeFanPage
58. The End!
THANK YOU
Please rate my talk
https://joind.in/7796
contact@nickbelhomme.com
Slideshare, Twitter, IRC: NickBelhomme
http://blog.nickbelhomme.com
59. Flickr Photo Credits
Backgrounds by Flikr
http://www.flickr.com/photos/flikr/146538982/
http://www.flickr.com/photos/flikr/147274362/
Hinweis der Redaktion
System: tests request, router, controller, view, response Black box: you do not have to be aware of the code behind the system. And thus you do not write your tests accordingly Functional: tests complete gui and behavior
System: tests request, router, controller, view, response Black box: you do not have to be aware of the code behind the system. And thus you do not write your tests accordingly Functional: tests complete gui and behavior
System: tests request, router, controller, view, response Black box: you do not have to be aware of the code behind the system. And thus you do not write your tests accordingly Functional: tests complete gui and behavior