Published on

Published in: Technology
No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Automated Web Testing with Selenium <ul><ul><li>Deepak Mittal </li></ul></ul><ul><ul><li>Dec 15, 2007 </li></ul></ul>
  2. 2. Agenda <ul><li>Introduction to Selenium </li></ul><ul><li>Quick Demo </li></ul><ul><li>Different ways of using Selenium </li></ul><ul><li>Best practices with using Selenium </li></ul><ul><li>Questions & Feedback </li></ul>
  3. 3. Quick Poll <ul><li>Do you do Web Testing? </li></ul><ul><li>Do you do automated Web Testing? </li></ul><ul><li>Do you need to support & test your web-app on multiple browsers? </li></ul><ul><li>Which automated web-testing frameworks do you use? </li></ul>
  4. 4. What is Selenium? <ul><li>A JavaScript based </li></ul><ul><li>Open Source </li></ul><ul><li>Web testing tool </li></ul><ul><li>That supports testing Web 2.0 applications </li></ul><ul><li>On multiple browsers </li></ul><ul><li>And multiple Operating Systems </li></ul>
  5. 5. What is Selenium <ul><li>Acceptance Testing tool for web-apps </li></ul><ul><li>Tests run directly in browser </li></ul><ul><li>Implemented entirely using browser technologies - </li></ul><ul><ul><ul><li>JavaScript </li></ul></ul></ul><ul><ul><ul><li>DHTML </li></ul></ul></ul><ul><ul><ul><li>Frames </li></ul></ul></ul>
  6. 6. Origins of Selenium <ul><li>Developed by ThoughtWorks to test new time and expenses system </li></ul><ul><li>Selenium is the key mineral to protect body from mercury toxicity </li></ul><ul><li> </li></ul>
  7. 7. Selenium Modes <ul><li>Test Runner Mode </li></ul><ul><ul><ul><li>test cases in HTML tables </li></ul></ul></ul><ul><li>Record-Playback mode (Selenium IDE)‏ </li></ul><ul><li>Selenium Remote Control (RC) Mode </li></ul><ul><ul><ul><li>test-cases in your language of choice </li></ul></ul></ul>
  8. 8. Selenium Modes <ul><li>Test Runner Mode </li></ul><ul><ul><ul><li>test cases in HTML tables </li></ul></ul></ul><ul><li>Record-Playback mode (Selenium IDE)‏ </li></ul><ul><li>Selenium Remote Control (RC) Mode </li></ul><ul><ul><ul><li>test-cases in your language of choice </li></ul></ul></ul>
  9. 9. Test Runner Mode
  10. 10. Selenium HTML Tests <ul><li>Selenium tests are HTML files </li></ul><ul><li>Selenium interacts with the DOM served to browser </li></ul><ul><li>Selenium is agnostic of server side technology </li></ul><ul><li>Selenium HTML language is called Selenese </li></ul>
  11. 11. Selenese <ul><li>Selenium declarative DSL : Selenese </li></ul><ul><li>Selenium understands two types of HTML files (which have simple HTML tables): </li></ul><ul><ul><ul><ul><li>Tests </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Test Suites </li></ul></ul></ul></ul><ul><li>Every test is contained within a test suite </li></ul><ul><li>Point TestRunner.html at the test suite to run it </li></ul>
  12. 12. Format of a Selenium Test <ul><li>HTML Table with 3 columns </li></ul><ul><ul><ul><ul><li>First Column: Selenium command </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Second Column: Target of command </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Third Column: Optional parameter </li></ul></ul></ul></ul>
  13. 13. Selenium Concepts <ul><li>Element Locators : specify HTML elements </li></ul><ul><li>Patterns : for pattern matching values </li></ul><ul><li>Action : manipulate app state </li></ul><ul><li>Accessors : store results in variables </li></ul><ul><li>Assertion : verify that the app is in a certain state </li></ul>
  14. 14. Test Runner Demo <ul><li>See Demo suite </li></ul><ul><li>Look at tests bundled with Selenium </li></ul><ul><li>Running selenium test in slow and fast mode </li></ul>
  15. 15. Problems with HTML Tests <ul><li>Selenium is sensitive to the format of the table </li></ul><ul><li>No separation of concern </li></ul><ul><li>Duplication is a major issue </li></ul><ul><li>Tests need to be deployed with AUT (Application under Test)‏ </li></ul>
  16. 16. Selenium Modes <ul><li>Test Runner Mode </li></ul><ul><ul><ul><li>test cases in HTML tables </li></ul></ul></ul><ul><li>Record-Playback mode (Selenium IDE)‏ </li></ul><ul><li>Selenium Remote Control (RC) Mode </li></ul><ul><ul><ul><li>test-cases in your language of choice </li></ul></ul></ul>
  17. 17. Selenium IDE <ul><li>Very useful tool for beginners </li></ul><ul><li>Firefox extension which allows record/play testing paradigm </li></ul><ul><li>Automates commands, but asserts must be entered by hand </li></ul><ul><li>Creates the simplest possible Locator </li></ul><ul><li>Based on Selenese </li></ul>
  18. 18. Selenium IDE Demo <ul><li>Look at firefox extension </li></ul><ul><li>Look at various possible commands </li></ul><ul><li>Record a test on AUT and play-back </li></ul><ul><li>Save the test at HTML file </li></ul><ul><li>Export the test as Java / Ruby </li></ul>
  19. 19. Selenium Modes <ul><li>Test Runner Mode </li></ul><ul><ul><ul><li>test cases in HTML tables </li></ul></ul></ul><ul><li>Record-Playback mode (Selenium IDE)‏ </li></ul><ul><li>Selenium Remote Control (RC) Mode </li></ul><ul><ul><ul><li>test-cases in your language of choice </li></ul></ul></ul>
  20. 20. Selenium RC Mode
  21. 21. Selenium RC Mode Demo <ul><li>Run selenium server </li></ul><ul><li>Look at sample tests </li></ul>
  22. 22. Maintaining Selenium Tests <ul><li>Test code is just like production code </li></ul><ul><li>Needs re-factoring, abstraction </li></ul><ul><li>API for the application </li></ul><ul><li>Can build tests from API building blocks </li></ul><ul><li>Try to maintain meaning – in test names, variable names, comments, and suite organization </li></ul>
  23. 23. Selenium with Continuous Integration <ul><li>Run Selenium tests as part of the build </li></ul><ul><li>Can generate HTML reports, published to entire team </li></ul><ul><li>Helps catch bugs ASAP </li></ul>
  24. 24. Ajax Support <ul><li>Selenium supports testing Web 2.0 applications </li></ul><ul><li>Monitor the DOM for completion of Async calls </li></ul><ul><li>waitForCondition(script, timeout)‏ </li></ul>
  25. 25. Useful Selenium Tools <ul><li>Chris Pederick's Web Developer toolbar </li></ul><ul><li>XPather </li></ul><ul><li>Firebug </li></ul><ul><li>Xpath Checker </li></ul>
  26. 26. Selenium Best Practices <ul><li>Use Ids wherever possible (xpaths make the tests brittle)‏ </li></ul><ul><li>Use data-driven tests. Use a JSP/PHP page to generate tests </li></ul><ul><li>In order to generate unique Ids, use timestamp </li></ul><ul><li>Use the right level of granularity </li></ul>
  27. 27. What have we not covered? <ul><li>Continuous Integration set-ups </li></ul><ul><li>Creating screencasts using Selenium </li></ul><ul><li>Testing of Ajax applications </li></ul><ul><li>Selenium Commands in detail </li></ul><ul><li>User Extensions </li></ul><ul><li>Using Python/Ruby/C# ... </li></ul>
  28. 28. Selenium Limitations <ul><li>Slow when testing all the edge cases </li></ul><ul><li>Slow for testing fine-grained features – set-up and tear-down are called for each test </li></ul>
  29. 29. Selenium Strengths <ul><li>For testing Ajax applications </li></ul><ul><li>Multiple browsers </li></ul><ul><li>Test full-stack </li></ul>
  30. 30. Interesting Possibilities <ul><li>Delivering Selenium Screencast as Documentation to end-users </li></ul><ul><li>Creating a report with screenshots </li></ul><ul><li>A Server having VMWare images of various OS/browser and each submitting a report back </li></ul>
  31. 31. Summary <ul><li>Selenium is a testing framework for Web Applications </li></ul><ul><li>Drivers allow web testing in language of choice </li></ul><ul><li>Test scripts are code: need maintenance, re-factoring </li></ul>
  32. 32. Summary <ul><li>Can be used on Developer machines </li></ul><ul><li>Most valuable when used with CI set-up </li></ul><ul><li>Can be used to make screen casts </li></ul><ul><li>Tests run on real browser – most people use it to test their JavaScript works predictably on all browsers </li></ul>
  33. 33. Summary <ul><li>Can be used for unit-testing, regression testing, smoke-testing, integration and acceptance testing </li></ul>
  34. 34. References / Attribution <ul><li>Neal Ford's presentation on Selenium </li></ul><ul><li>Selenium site </li></ul><ul><ul><li>This work is licensed under the Creative Commons Attribution-Noncommercial-Share Alike 3.0 License </li></ul></ul>
  35. 35. Feedback <ul><ul><li>[email_address] </li></ul></ul>
  1. A particular slide catching your eye?

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