Advanced techniques for Web functional testing
Julien Phalip
Definitions
- Unit testing
- Ensure that small parts work in isolation
- Integration testing
- Ensure those poarts work well together
- Functional Testing
- ensure applcation functions well, especially from the user's perspective
Selenium
- Uses WebDriver API: soon to become W3C standard
- Works across multip browsers
- Client libraries in many languages
- easy install
Testing responsive sites
self.driver.set_window_size(600, 600)
self.driver.set_window_size(1280, 800)
Testing visuals with Needle
- bfirsh/needle
- based on selenium
- catch regressions with styles, typography, SVG, images etc. by coparing screenshots
self.assertScreenshot(
'.banner', # CSS selector
'banner' # filename (PNG)
)
- First time you run the test, pass a flag to tell Needle to save the screen shot
$ nosetests tests:BannerTest --with-save-baseline
- Helps you check for CSS changes
- creates a visual diff image... cooooool!
Tips
- Baseline screenshots == Fixtures
- ensure consistency between environments to avoid false positives
- browser version, fonts, etc.
- Use configuration management!
Continuous Integration
Headless browsers
- Xvfb
$ xvfb --run # run next command in the virtual framebuffer
- PyVirtualDisplay
- PhantomJS
Sauce Labs
- run remotely in the cloud
- gives access to multiple browsers and multiple platforms
- parallel tests
- video recording of all sessions
Speed and Robustness
Optimizing for speed
- use PhantomJS (headless mode)
- Use parallelization
Optimizing for robustness
- Pin down versions for your whole software stack, including the browser
- Master the use of explicit waits, esp. with heavy JS/Ajax apps
Resources
- The Selenium Guidebook
- Selenium Testing Tools Cookbook
A Word of Caution
- Integration & Functional tests are slow; use them with moderation
- use selenium only for what a dummy test client may not already achieve
Integration frontend/backend
- ensure that the user interface rworks
- have fun in the process and functional test are important
- increase confidence
- increase test coverage