Selenium
Web Application Testing System
Chris Roberts
Data Directions, Inc.
Selenium: What It Is
- "Web Application Testing System" (from seleniumhq.org)
- "[...] a suite of tools specifically for testing web applications" (also from seleniumhq.org)
- can be used for unit, functional, and integration testing
- useful whenever you need to test a web UI
Selenium: How Is It Different? (1/3)
- Java developers already have Canoo WebTest, JWebUnit, WebDriver
- These are all built on HTMLUnit, "GUI-less browser for Java programs" (htmlunit.sourceforge.net)
- But these tools just mimic browsers, which means...
Selenium: How Is It Different? (2/3)
- JavaScript support must always play catch-up with real browsers
- AJAX behavior can't always be tested effectively
- Browser bugs might not appear in the testing tool
Selenium: How Is It Different? (3/3)
- Selenium runs in actual browsers (IE, Firefox, Opera, Chrome, Safari)
- The JavaScript it runs uses the JavaScript engine in the browser
- AJAX is testable, in-browser
- Browser bugs show up just like they would in production
- Trade-off: Certain kinds of tests run slower (more later)
Selenium is sweet! a "Suite of Tools..."
- Selenium Core (client-side, tests written in HTML)
- Selenium IDE (Firefox plug-in for easier test creation)
- Selenium RC (Remote Control -- server-based, tests written in Java, Python, Ruby, .Net)
- Selenium Grid (distributed Selenium RC instances)
Selenium Core
- Controlled through a browser interface
- Top left: Test Suites, which are made of...
- Top center: Test Cases, which are run by...
- Top right: Test Runner
- Bottom: Application Under Test (AUT) (i.e., the site you're testing)
Selenium Core: The Good
- Write tests in HTML
- See how the browser responds (good for catching browser bugs)
- Makes for great demos
- Control test playback (speed, step debugging, pause)
Selenium Core: The Bad
- Tedious to write large number of tests
- Browsers' "Same Origin Policy" prevents cross-domain testing
- Browsers' security controls prevent HTTP-to-HTTPS navigation (sorry, eCommerce sites!)
- Possibly soon-to-be-deprecated because of above limitations and others :-(
Selenium Core: The Ugly
- Did I mention the HTTPS thing?
- And not being able to cross domains?
- (Sorry, this slide was mandatory -- you can't have a good and a bad without an ugly.)
Selenium IDE
- Firefox plug-in
- Records tests for you (into HTML, Java, Groovy, Perl, Python, Ruby, &c.)
- Lower-level plug-in code gets around security and domain policy restrictions
- Records in Firefox only, but tests can play back in any supported browser using Core or RC
Selenium RC
- Write tests in Java, Groovy, Perl, Ruby...
- ...which means you have flow control, branching, data-driven tests (unlike Selenium Core)...
- ...but still get the benefits of in-browser testing.
Selenium RC: How? (1/4)
- Run Selenium server (distributed as a JAR)
- Your code connects to the server and issues Selenium commands (Selenese)
- Server starts up the browser for you and forwards the commands to browser-based client
Selenium RC: How? (2/4)
- Server acts as a proxy; configures browser to send all request through it
- Browser thinks all requests come from the same domain, so no cross-domain or HTTPS issues
- Server also runs browser with heightened privileges (using HTA files in IE, e.g.) to skirt restrictions
- Server acts as intermediary between your client code and the Selenium browser "driver"
Selenium RC: How? (3/4)
Selenium RC: How? (4/4)
Selenium Grid
- Selenium RC uses HTTP for messages, so no need to run server locally
- "distributed grid of Selenium RCs [...shareable] across builds, applications, projects"
(http://selenium-grid.seleniumhq.org/how_it_works.html)
- Selenium Hub allocates RCs to tests, transparently routes requests to various RCs
- Configurable routing for specific (but arbitrary) environments ("Firefox on Ubuntu", "IE6 on WinXP with low memory")
Selenium: Conclusion
- Great for demos
- Great for JavaScript/AJAX testing
- Slower than HTMLUnit for basic pages
- Plenty of options (client- and server-side tests, Firefox plug-in, testing on a grid)
Selenium: More Info
- Selenium HQ - http://seleniumhq.org/
- DZone RefCard - http://refcardz.dzone.com/refcardz/getting-started-selenium
- Open QA - http://openqa.org/
- Writing your own Selenium extensions - http://release.seleniumhq.org/selenium-core/1.0/reference.html
- Tellurium (Groovy + Selenium + more!) - http://code.google.com/p/aost/
- [Simple Standards-Based Slide Show System - http://meyerweb.com/eric/tools/s5/]
- [CWDKids - dressing kids like kids - http://www.cwdkids.com]