Selenium and Selenium on Rails
Agenda <ul><li>Overview of Selenium </li></ul><ul><ul><li>Simple Selenium Tests </li></ul></ul><ul><ul><li>Selenium IDE </...
Selenium Overview <ul><li>Selenium is composed of four things: </li></ul><ul><ul><li>Selenium Core </li></ul></ul><ul><ul>...
Overview of Selenium <ul><li>Open source browser based integration test framework built originally by Thoughtworks </li></...
Overview of Selenium <ul><li>Downloads and Documentation can be found at:  www.openqa.org </li></ul><ul><li>Getting starte...
Simple Selenium Tests <ul><li>Selenium understands two types of files </li></ul><ul><ul><li>Tests </li></ul></ul><ul><ul><...
Format of Selenium Test Suite <ul><li>More complex than Selenium Tests  </li></ul><ul><li>Easiest just to copy TestSuite.h...
Format of a Selenium Test <ul><li>HTML Table with 3 columns  </li></ul><ul><ul><li>First Column: Selenium command </li></u...
Format of a Selenium Test <ul><li>Two types of Selenium Parameters </li></ul><ul><ul><li>Locators – Used to find elements ...
Gotchas in HTML Selenium Test Writing <ul><li>Selenium is sensitive to the format of the table </li></ul><ul><li>All selen...
Wow, that was hard! <ul><li>Lesson learned: Never ever write this by hand </li></ul><ul><li>There are a lot of commands - ...
Selenium IDE <ul><li>Firefox extension that allows recording and editing of tests </li></ul><ul><li>Can be download off of...
Selenium IDE <ul><li>Much easier to use  </li></ul><ul><li>Only really works with synchronous requests </li></ul><ul><li>O...
Selenium on Rails <ul><li>Plugin for Rails that allows tests to be expressed in Ruby </li></ul><ul><li>Selenium core files...
Selenium on Rails <ul><li>Each test becomes a single RSEL file which contains Ruby calls closely resembling the Selenium C...
Selenium on Rails <ul><li>RSEL files can reference fixtures and clear session state on startup </li></ul><ul><li>RSEL file...
That was still pretty hard… <ul><li>Selenium on Rails does not initially make WRITING tests any easier </li></ul><ul><li>S...
Problems with Selenium  <ul><li>The Xpath locators are basically worthless because of the poor performance in IE </li></ul...
?
Upcoming SlideShare
Loading in...5
×

Selenium and Selenium on Rails

3,144

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
3,144
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
108
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Selenium and Selenium on Rails

  1. 1. Selenium and Selenium on Rails
  2. 2. Agenda <ul><li>Overview of Selenium </li></ul><ul><ul><li>Simple Selenium Tests </li></ul></ul><ul><ul><li>Selenium IDE </li></ul></ul><ul><li>Overview of Selenium on Rails </li></ul><ul><li>Problems with Selenium </li></ul>
  3. 3. Selenium Overview <ul><li>Selenium is composed of four things: </li></ul><ul><ul><li>Selenium Core </li></ul></ul><ul><ul><li>Selenium IDE </li></ul></ul><ul><ul><li>Selenium RC </li></ul></ul><ul><ul><li>Selenium on Rails </li></ul></ul>
  4. 4. Overview of Selenium <ul><li>Open source browser based integration test framework built originally by Thoughtworks </li></ul><ul><li>100% Javascript and HTML </li></ul><ul><li>Designed to make test writing easy </li></ul><ul><li>Ability to run whole suites of tests or individual tests </li></ul><ul><li>Ability to step through individual tests </li></ul><ul><li>Cross browser – IE 6/7, Firefox .8+, Opera, Safari 2.0+ </li></ul><ul><li>Lets see an example of a selenium test suite… </li></ul>
  5. 5. Overview of Selenium <ul><li>Downloads and Documentation can be found at: www.openqa.org </li></ul><ul><li>Getting started: </li></ul><ul><ul><li>Download Selenium core off of www.openqa.org </li></ul></ul><ul><ul><li>Place the contents of the zip file on a web server in a selenium-core directory </li></ul></ul><ul><ul><li>Go to http://web-server-host/selenium-core/index.html </li></ul></ul>
  6. 6. Simple Selenium Tests <ul><li>Selenium understands two types of files </li></ul><ul><ul><li>Tests </li></ul></ul><ul><ul><li>Test Suites </li></ul></ul><ul><li>Every test must be contained within a test suite </li></ul><ul><li>Both tests and test suites are defined by using simple tables in HTML </li></ul><ul><li>To execute a test suite you must point TestRunner.html at it </li></ul>
  7. 7. Format of Selenium Test Suite <ul><li>More complex than Selenium Tests </li></ul><ul><li>Easiest just to copy TestSuite.html from the samples </li></ul><ul><li>Mostly a table that points to the tests </li></ul>
  8. 8. Format of a Selenium Test <ul><li>HTML Table with 3 columns </li></ul><ul><ul><li>First Column: Selenium command </li></ul></ul><ul><ul><li>Second Column: Required first parameter </li></ul></ul><ul><ul><li>Third Column: Optional second parameter </li></ul></ul><ul><li>Selenium commands are broken into 3 types: </li></ul><ul><ul><li>Actions – Command the browser to do something </li></ul></ul><ul><ul><li>Accessors – Store/retrieve data from selenium variables </li></ul></ul><ul><ul><li>Asserts – Verify that the browser is in a certain state </li></ul></ul>
  9. 9. Format of a Selenium Test <ul><li>Two types of Selenium Parameters </li></ul><ul><ul><li>Locators – Used to find elements in html trees </li></ul></ul><ul><ul><li>Pattern Matchers – Used to verify values </li></ul></ul><ul><li>Lots of locator types. Some examples are: Id based, xpath based, css selector based </li></ul><ul><li>Pattern matchers are typically exact matches or regular expressions </li></ul><ul><li>Lots more info at: http://www.openqa.org/selenium-core/reference.html </li></ul><ul><li>So lets try to write a simple Selenium test… </li></ul>
  10. 10. Gotchas in HTML Selenium Test Writing <ul><li>Selenium is sensitive to the format of the table </li></ul><ul><li>All selenium command rows must have three columns or they will not be recognized as commands </li></ul><ul><li>You can only test URL’s that are in the same domain as the selenium core </li></ul><ul><li>Separation of concerns is hard – Tests become very dependent on the internal structure of the HTML </li></ul>
  11. 11. Wow, that was hard! <ul><li>Lesson learned: Never ever write this by hand </li></ul><ul><li>There are a lot of commands - you can even add your own custom commands into the user-extensions.js </li></ul><ul><li>Firebug is very useful for developing your accessors </li></ul>
  12. 12. Selenium IDE <ul><li>Firefox extension that allows recording and editing of tests </li></ul><ul><li>Can be download off of www.openqa.org </li></ul><ul><li>Allows easier development of tests </li></ul><ul><li>Can even output Ruby for it’s Ruby based API </li></ul><ul><li>Lets see it in action… </li></ul>
  13. 13. Selenium IDE <ul><li>Much easier to use </li></ul><ul><li>Only really works with synchronous requests </li></ul><ul><li>Only automates commands, assert still must be entered by hand </li></ul><ul><li>Still requires lots of work to get Selenium to run it as part of a Test Suite </li></ul>
  14. 14. Selenium on Rails <ul><li>Plugin for Rails that allows tests to be expressed in Ruby </li></ul><ul><li>Selenium core files no longer go in public – they are part of the Plugin </li></ul><ul><li>Supports two kinds of files SEL files and RSEL files </li></ul><ul><ul><li>SEL files are pipe separated files that look much like Selenium HTML </li></ul></ul><ul><ul><li>RSEL files talk to a Ruby API that closely mirrors the normal commands – more info at: http://www.openqa.org/classes/SeleniumOnRails/TestBuilder.html </li></ul></ul>
  15. 15. Selenium on Rails <ul><li>Each test becomes a single RSEL file which contains Ruby calls closely resembling the Selenium Commands </li></ul><ul><li>RSEL files work much like views in Ruby and can be broken down into partials </li></ul><ul><li>Selenium on Rails takes over the /selenium/ URL space </li></ul><ul><li>RSEL files are used to automatically generate Selenium HTML table based tests </li></ul><ul><li>Selenium on Rails then generates it’s own Test Suite containing all of the tests </li></ul>
  16. 16. Selenium on Rails <ul><li>RSEL files can reference fixtures and clear session state on startup </li></ul><ul><li>RSEL files support partials </li></ul><ul><li>Test development is much more Rails like -> Edit RSEL file, hit Reload in browser, run updated test </li></ul><ul><li>Lets see it in action… </li></ul>
  17. 17. That was still pretty hard… <ul><li>Selenium on Rails does not initially make WRITING tests any easier </li></ul><ul><li>Selenium on Rails makes deploying and the development cycle of tests easier </li></ul><ul><li>Selenium on Rails makes writing tests more natural for RoR developers – it also gives your tests access to the rest of the code you have developed for your application </li></ul><ul><li>Selenium on Rails should really be seen as a starting point for developing a DSL to test YOUR application </li></ul>
  18. 18. Problems with Selenium <ul><li>The Xpath locators are basically worthless because of the poor performance in IE </li></ul><ul><li>It is not designed to do AJAX type testing </li></ul><ul><li>waitForElement and waitForCondition are the tools that Selenium provides to deal with AJAX both of which add a lot of complexity to tests </li></ul><ul><li>Custom Selenium commands added to user-extensions.js are difficult to write – Avoid doing so unless you must </li></ul><ul><li>Timeouts are unreliable – sometimes tests hang </li></ul><ul><li>Not all Javascript events are supported </li></ul>
  19. 19. ?
  1. A particular slide catching your eye?

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

×