Selenium Primer


Published on

Published in: Business, Technology
1 Comment
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Selenium Primer

  1. 1. Selenium–Functional Testing Tool by ThoughtWorks February 2007
  2. 2. Agenda <ul><li>What is Selenium? </li></ul><ul><li>Implementing Selenium </li></ul><ul><li>Functional Primer on Selenium </li></ul><ul><li>Key FAQ’s </li></ul><ul><li>References and Contacts </li></ul>Selenium-Functional Testing Tool Selenium-Functional Testing Tool
  3. 3. What is Selenium? <ul><li>Selenium Overview </li></ul><ul><li>What can be done with Selenium? </li></ul><ul><li>What can’t be done with Selenium? </li></ul><ul><li>Selenium Components </li></ul><ul><li>The Selenium Testing Process </li></ul>Selenium-Functional Testing Tool
  4. 4. Selenium Overview <ul><li>Selenium is a framework for testing websites </li></ul><ul><li>Selenium tests run directly in a browser </li></ul><ul><li>A wide array of browsers supported by Selenium are Internet Explorer, Mozilla, Firefox on Windows, Linux, and Macintosh </li></ul><ul><li>Selenium uses JavaScript and I frames to embed a test automation engine in the browser </li></ul><ul><ul><li>It work with any JavaScript-enabled browser </li></ul></ul><ul><li>Selenium works with the following OS / Browser combinations: </li></ul>Selenium-Functional Testing Tool 1.3+ 0.8+, 0.9+, 1.0+ 1.6+, 1.7+ Not supported Mac OS X 10.3 0.8+, 0.9+, 1.0+ 1.6+, 1.7+ Red Hat Linux 0.8+, 0.9+, 1.0 1.6+, 1.7+ 6.0 Windows XP Safari Firefox Mozilla Internet Explorer
  5. 5. What can be done with Selenium? <ul><li>Browser compatibility testing </li></ul><ul><ul><li>Test your application to see if it works correctly on different browsers and operating systems </li></ul></ul><ul><ul><li>The same script can run on any Selenium platform </li></ul></ul><ul><li>System functional testing </li></ul><ul><ul><li>Create regression tests to verify application functionality and user acceptance </li></ul></ul><ul><li>Integration testing </li></ul><ul><li>Run tests and see results on the same page </li></ul><ul><li>Generate Defect Reports </li></ul><ul><li>Selenium can be extended using Java scripts </li></ul><ul><li>Selenium supports handling dynamically generated elements </li></ul><ul><li>Selenium supports testing applications built using Ajax </li></ul>Selenium-Functional Testing Tool
  6. 6. What can’t be done with Selenium? <ul><li>Data driven Testing </li></ul><ul><ul><li>Means that scripts read data from an external storage site, for example, from a file or database, rather than use values hard-coded in the script </li></ul></ul><ul><li>Performance Testing </li></ul><ul><li>Load Testing </li></ul><ul><li>Test drag and Drop </li></ul>Selenium-Functional Testing Tool
  7. 7. Selenium Components <ul><li>Selenium Core </li></ul><ul><li>Selenium IDE </li></ul><ul><li>Selenium RC </li></ul>Selenium-Functional Testing Tool
  8. 8. Selenium Core <ul><li>Selenium Core is a test tool for web applications </li></ul><ul><li>Selenium Core tests run directly in a browser , just as real users do </li></ul><ul><li>Selenium Core uses a unique mechanism which allows it to run on so many platforms </li></ul><ul><li>Selenium Core is written in pure JavaScript/DHTML </li></ul><ul><li>You can copy Selenium Core tests directly into their application web server, allowing the tests to run in any supported browser on the client-side </li></ul><ul><li>You must have write access to the machine their web application server is running on to install Selenium Core </li></ul><ul><li> </li></ul>Selenium-Functional Testing Tool
  9. 9. Selenium-on-Rails <ul><li>Selenium on Rails provides an easy way to test Rails application with Selenium Core </li></ul><ul><li>This plug-in does four things: </li></ul><ul><ul><li>The Selenium Core files don’t have to pollute /public, they can stay in the Selenium gem or in /vendor/selenium </li></ul></ul><ul><ul><li>No need to create suite files, they are generated on the fly — one suite per directory in /test/selenium (suites can be nested) </li></ul></ul><ul><ul><li>Instead of writing the test cases in HTML you can use a number of better formats like selenese(.sel), Rselenese(.rsel), HTML/RHTML </li></ul></ul><ul><ul><li>Loading of fixtures and wiping of session (/selenium/setup) </li></ul></ul>Selenium-Functional Testing Tool
  10. 10. Selenium IDE <ul><li>Selenium IDE is an integrated development environment for Selenium tests </li></ul><ul><li>It is implemented as a Firefox extension, and allows user to record, edit, and debug tests </li></ul><ul><li>It includes the entire Selenium Core, allowing user to easily and quickly record and play back tests in the actual environment that they will run </li></ul><ul><li>Selenium IDE is not only recording tool: it is a complete IDE </li></ul><ul><ul><li>You can choose to use its recording capability, or you may edit your scripts by hand </li></ul></ul><ul><ul><li>With autocomplete support and the ability to move commands around quickly, Selenium IDE is the ideal environment for creating Selenium tests no matter what style of tests you prefer </li></ul></ul><ul><li>Features are: </li></ul><ul><ul><li>Easy record and playback </li></ul></ul><ul><ul><li>Intelligent field selection will use IDs, names, or XPath as needed </li></ul></ul><ul><ul><li>Auto complete for all common Selenium commands </li></ul></ul><ul><ul><li>Walk through tests </li></ul></ul><ul><ul><li>Debug and set breakpoints </li></ul></ul><ul><ul><li>Save tests as HTML, Ruby scripts, or any other format </li></ul></ul><ul><ul><li>Support for Selenium user-extensions.js file </li></ul></ul><ul><ul><li>Option to automatically assert the title of every page </li></ul></ul>Selenium-Functional Testing Tool
  11. 11. Selenium IDE Selenium-Functional Testing Tool
  12. 12. Selenium Remote Control <ul><li>Selenium Remote Control is a test tool that allows you to write automated web application UI tests in any programming language against any HTTP website using any mainstream JavaScript-enabled browser </li></ul><ul><li>It provides a Selenium Server , which can automatically start/stop/control any supported browser. It works by using Selenium Core , a pure-HTML+JS library that performs automated tasks in JavaScript </li></ul><ul><li>The Selenium Server communicates directly with the browser using AJAX (XmlHttpRequest) </li></ul><ul><li>User can send commands directly to the Server using simple HTTP GET/POST requests; that means that user can use any programming language that can make HTTP requests to automate Selenium tests on the browser </li></ul><ul><li>Finally, the Selenium Server acts as a client-configured HTTP proxy, to stand in between the browser and user’s website which allows a Selenium-enabled browser to run JavaScript on arbitrary websites </li></ul><ul><li>The Selenium Server is great for testing complex AJAX-based web user interfaces under a Continuous Integration system </li></ul>Selenium-Functional Testing Tool
  13. 13. The Selenium Testing Modes <ul><li>The test management with Selenium involves: </li></ul><ul><li>Selenium Core Mode </li></ul>Selenium-Functional Testing Tool
  14. 14. Selenium Core Mode <ul><li>Selenium Core scripts, also referred to as test cases , are written in HTML using a simple table layout shown in Listing 1 </li></ul><ul><li>Listing 1. Selenium test case structure <table border=&quot;1&quot;> </li></ul><ul><li> <tr> </li></ul><ul><li><td>First command</td> </li></ul><ul><li><td>Target</td> </li></ul><ul><li><td>Value</td> </li></ul><ul><li></tr> </li></ul><ul><li><tr> </li></ul><ul><li><td>Second command</td> </li></ul><ul><li><td>Target</td> </li></ul><ul><li><td>Value</td> </li></ul><ul><li></tr> </li></ul><ul><li></table> </li></ul><ul><li>Test runner scripts are usually deployed on the same server as the application under test (AUT). This is because the browser bot uses JavaScript's to emulate user actions. These scripts run in a restricted sandbox environment. If you need to circumvent these restrictions, use a proxy </li></ul>Selenium-Functional Testing Tool
  15. 15. Installing Selenium Selenium-Functional Testing Tool
  16. 16. Installing Selenium Selenium-Functional Testing Tool <ul><li>Elementary knowledge of HTML </li></ul><ul><li>Working knowledge of JavaScript </li></ul><ul><li>Selenium configuration files </li></ul>Ramp up <ul><li> </li></ul>How to download? <ul><li>Click through Install </li></ul><ul><li>Installs Browser Bot – the automation engine of Selenium </li></ul>Setup Open Source, freeware License/Price URL
  17. 17. Browser-Based Testing Survey of Selenium with other tools Selenium-Functional Testing Tool <ul><li>Written by Rob Marchetti. Patterned after Samie </li></ul><ul><li>The author has an alpha version for VB as well </li></ul><ul><li>Active mailing list since July 2004. </li></ul>IE Python Pamie <ul><li>xUnit test framework designed for general web testing </li></ul><ul><li>Includes a GUI test runner front end </li></ul><ul><li>No mailing list </li></ul><ul><li>First release October 2002 </li></ul>IE JavaScript IeUnit <ul><li>Acceptance testing framework. Includes a new &quot;Internet Explorer bridge&quot; which likely plugs into the IE API </li></ul><ul><li>Built on top of JUnit and fixtures are written in Java </li></ul><ul><li>Seems to focus on HTTPUnit, which is not a browser-based technology </li></ul><ul><li>Some background in the Acceptance Testing HTML white paper </li></ul>IE XML Avignon Notes Browse Compatibility Test  Case Language Tool
  18. 18. Browser-Based Testing Survey of Selenium with other tools Selenium-Functional Testing Tool <ul><li>Used internally at Tapster Rock in the UK </li></ul><ul><li>Active mailing list. </li></ul>IE Java Jiffie <ul><li>Implemented in JavaScript </li></ul><ul><li>Works in several different browsers on Windows and Linux </li></ul><ul><li>Uses a FIT-like table interface and an object-based language reminiscent of Worksoft Certify and the latest release of Mercury QuickTest Pro, though it's not a complete keyword-driven framework </li></ul><ul><li>Requires extra work to avoid cross-site scripting security protections </li></ul><ul><li>Supports a variety of languages in RC mode </li></ul><ul><li>Sponsored by ThoughtWorks </li></ul>IE, Mozilla, Fire fox, Safari Table-based Selenium <ul><li>Written by Henry Wasserman </li></ul><ul><li>Also uses Win32::GUITEST </li></ul><ul><li>Mailing list is largely inactive, but the author is reachable </li></ul><ul><li>First release was February 2003. </li></ul>IE Perl Samie Notes Browse Compatibility Test  Case Language Tool
  19. 19. Selenium Vs QTP (Industry Comparison Matrix) <ul><li>Each category in the matrix is given a rating of 1 – 5 </li></ul><ul><ul><li>1 = Excellent support for this functionality </li></ul></ul><ul><ul><li>2 = Good support but lacking or another tool provides more effective support </li></ul></ul><ul><ul><li>3 = Basic/ support only </li></ul></ul><ul><ul><li>4 = This is only supported by use of an API call or third party add-in but not included in the general test tool/below average </li></ul></ul><ul><ul><li>5 = No support </li></ul></ul>Selenium-Functional Testing Tool 1 4 Object Mapping 2 3 Data functions 1 5 Database tests 1 2 Web Testing 1 3 Record & Playback QTP Selenium
  20. 20. Selenium-Functional Testing Tool Selenium Vs QTP (Industry Comparison Matrix) 25 50 Total 1 2 Object Tests 1 4 Support 2 3 Ease of use 5 1 Cost 1 3 Integration 1 3 Environment support 2 2 Extensible Language 2 2 Object Identity Tool 1 3 Object Name Map 2 5 Test/Error recovery 1 5 Image testing QTP Selenium
  21. 21. Functional Primer on Selenium <ul><li>Getting Started </li></ul><ul><li>Installing Selenium Core </li></ul><ul><li>Writing Test Case </li></ul><ul><li>Adding Test Case to Test Suite </li></ul><ul><li>Running Test Case </li></ul><ul><li>Generating Defect Reports </li></ul><ul><li>Commands </li></ul><ul><li>Demos </li></ul>Selenium-Functional Testing Tool
  22. 22. Getting Started <ul><ul><li>If this is your first time using a Selenium tool, you may not want to just use Selenium Core directly; one good way to get introduced to Selenium's features is to use Selenium IDE , which embeds Selenium Core internally </li></ul></ul><ul><ul><li>Download Selenium IDE and you'll get Selenium Core along with it </li></ul></ul>Selenium-Functional Testing Tool
  23. 23. Installing Selenium Core <ul><ul><li>To use Selenium Core, you need to make it available from the same web server as the application you want to test </li></ul></ul><ul><ul><ul><li>This is a JavaScript security requirement. If you can't/won't modify the web server you want to test, Selenium Core may not be the right tool for you; you may just want to use Selenium IDE or Selenium RC instead </li></ul></ul></ul><ul><ul><li>Extract the Selenium Core zip file into the DocumentRoot, htdocs, or webroot of your web server </li></ul></ul><ul><ul><li>Open the browser </li></ul></ul><ul><ul><li>Click Install to install the Selenium </li></ul></ul>Selenium-Functional Testing Tool
  24. 24. Writing Test Case <ul><ul><li>A test-case is represented by an HTML document written in &quot;Selenese&quot;, containing a table with 3 columns, room enough for a command and two arguments </li></ul></ul><ul><ul><li>Not all commands take two arguments; in this case either leave the column blank or use a &nbsp; to make the table look better </li></ul></ul><ul><ul><li>Example: </li></ul></ul>Selenium-Functional Testing Tool John Name verifytext True submitbutton click John nameField type /mypage open MyTest
  25. 25. Adding Test to Test Suite <ul><ul><li>Make new test case available by linking to it from the TestSuite; for example: </li></ul></ul><ul><ul><li><table id=&quot;suiteTable&quot; cellpadding=&quot;1&quot; cellspacing=&quot;1&quot; border=&quot;1&quot;> <tbody> </li></ul></ul><ul><ul><li> <tr><td><b>Test Suite </b> </td> </tr> </li></ul></ul><ul><ul><li> <tr><td><a href=&quot;MyTest.html&quot;>MyTest</a></td></tr> </li></ul></ul><ul><ul><li> ...etc... </li></ul></ul><ul><ul><li> </tbody> </li></ul></ul><ul><ul><li></table> </li></ul></ul>Selenium-Functional Testing Tool
  26. 26. Run Test Case <ul><ul><li>Open selenium Core, following screen should be displayed: </li></ul></ul>Selenium-Functional Testing Tool
  27. 27. Run Test Case (continued) <ul><ul><li>Locate the name of your test case in the Suite Panel (top left). Clicking on it should cause Selenium to load test into the Test Panel (top center). Now run the test by clicking the &quot;Selected&quot; button in the control area </li></ul></ul><ul><ul><li>Alternatively, click the &quot;All&quot; button to run the entire test suite </li></ul></ul><ul><ul><li>The Control Panel allows you to control how tests are executed </li></ul></ul>Selenium-Functional Testing Tool
  28. 28. Generating Defect Reports <ul><li>Click Show Log </li></ul><ul><li>Execute the script </li></ul>Selenium-Functional Testing Tool
  29. 29. Commands <ul><li>A command is what tells Selenium what to do </li></ul><ul><li>Selenium commands come in two 'flavors', Actions and Assertions </li></ul><ul><li>Actions are commands that generally manipulate the state of the application </li></ul><ul><li>Each command call is one line in the test table of the form: </li></ul>Selenium-Functional Testing Tool Value Target Command
  30. 30. Commands (continued) <ul><li>open ( url ) </li></ul><ul><ul><li>Opens a URL in the test frame. This accepts both relative and absolute URLs </li></ul></ul><ul><ul><li>The URL must be on the same site as Selenium due to security restrictions in the browser (Cross Site Scripting) </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>Open /mypage </li></ul></ul></ul><ul><ul><ul><li>open http://localhost/   </li></ul></ul></ul><ul><li>click ( elementLocator ) </li></ul><ul><ul><li>Clicks on a link, button, checkbox or radio button. If the click action causes a new page to load (like a link usually does), use &quot;clickAndWait&quot;. </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>Clicka Checkbox  </li></ul></ul></ul><ul><ul><ul><li>clickAndWait submitButton </li></ul></ul></ul><ul><ul><ul><li>clickAndWait anyLink  </li></ul></ul></ul>Selenium-Functional Testing Tool
  31. 31. Commands (continued) <ul><li>type ( inputLocator , value ) </li></ul><ul><ul><li>Sets the value of an input field, as though you typed it in </li></ul></ul><ul><ul><li>Can also be used to set the value of combo boxes, check boxes, etc </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>Type nameField John Smith </li></ul></ul></ul><ul><ul><ul><li>typeAndWait textBoxThatSubmitsOnChange newValue  </li></ul></ul></ul><ul><li>select ( dropDownLocator , optionSpecifier ) </li></ul><ul><ul><li>Select an option from a drop-down, based on the optionSpecifier </li></ul></ul><ul><ul><li>If more than one option matches the specifier (e.g. due to the use of globs like &quot;f*b*&quot;, or due to more than one option having the same label or value), then the first matches is selected </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>Select dropDown Australian Dollars </li></ul></ul></ul><ul><ul><ul><li>Select dropDown index=0 </li></ul></ul></ul><ul><ul><ul><li>selectAndWait currencySelector value=AUD </li></ul></ul></ul><ul><ul><ul><li>selectAndWait currencySelector label=Aus*lian D*rs </li></ul></ul></ul>Selenium-Functional Testing Tool
  32. 32. Commands (continued) <ul><li>selectWindow ( windowId ) </li></ul><ul><ul><li>Selects a popup window </li></ul></ul><ul><ul><li>Once a popup window has been selected, all commands go to that window </li></ul></ul><ul><ul><li>To select the main window again, use &quot;null&quot; as the target </li></ul></ul><ul><ul><li>target: The id of the window to select </li></ul></ul><ul><ul><li>value: ignored </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>selectWindow myPopupWindow </li></ul></ul></ul><ul><ul><ul><li>selectWindow null  </li></ul></ul></ul><ul><li>close () </li></ul><ul><ul><li>Simulates the user clicking the &quot;close&quot; button in the titlebar of a popup window </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>close   </li></ul></ul></ul><ul><li>pause ( milliseconds ) </li></ul><ul><ul><li>Pauses the execution of the test script for a specified amount of time </li></ul></ul><ul><ul><li>This is useful for debugging a script or pausing to wait for some server side action </li></ul></ul><ul><li>examples: </li></ul><ul><ul><ul><li>Pause 5000 </li></ul></ul></ul><ul><ul><ul><li>Pause 2000  </li></ul></ul></ul><ul><li>For More commands go to </li></ul><ul><ul><li> </li></ul></ul>Selenium-Functional Testing Tool
  33. 33. Demos <ul><ul><li>Demo 1 – Passing simple tests </li></ul></ul><ul><ul><ul><li>Click </li></ul></ul></ul><ul><ul><li>Demo 2 – Failing Some Tests </li></ul></ul><ul><ul><ul><li>Click </li></ul></ul></ul><ul><ul><li>Demo 3 - Ajax Testing </li></ul></ul><ul><ul><ul><li>Click </li></ul></ul></ul>Selenium-Functional Testing Tool
  34. 34. Selenium – Key FAQ’s <ul><li>How do you create test tables? </li></ul>Selenium-Functional Testing Tool
  35. 35. Key FAQ’s <ul><li>How do you create test tables? </li></ul><ul><ul><li>The developers on the Selenium project use Mozilla Composer to create plain HTML text files for their tests. By default, Mozilla Composer writes very clean HTML without any extra, unnecessary markup </li></ul></ul><ul><ul><li>You can also use Selenium IDE to write your tests scripts </li></ul></ul><ul><ul><li>Another option is any text/html editor to create test tables. Future versions of Selenium may support RST (Restructured Text), or wiki-table syntax, natively. However, you are free to use another format now, as long as you remember to generate the HTML files from your source files, either during your build process or dynamically at run-time </li></ul></ul>Selenium-Functional Testing Tool
  36. 36. References & Contacts <ul><li>References : </li></ul><ul><li>http:// /selenium </li></ul><ul><li>Contacts : </li></ul><ul><li>Sapient </li></ul><ul><ul><li>SME: Preeti Kakkar [email_address] +91-9811550015 </li></ul></ul><ul><ul><li>QA Practice Lead: Gurmeet Singh [email_address] 240 353 1762 </li></ul></ul>Selenium-Functional Testing Tool
  37. 37. What else? <ul><li>Questions </li></ul><ul><li>Next steps </li></ul><ul><li>Feedback </li></ul>Selenium-Functional Testing Tool