Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Watir Presentation Sumanth Krishna. A


Published on

Web Application Test In Ruby, is a testing framework for the web applications. Since it's built on ruby it would take the advantage of object oriented principles of ruby and makes the regression/functional testing very very simple. This presentation aims to introduce the WATIR, assists in installing and also testing with a simple test case.

Published in: Technology
  • Be the first to comment

Watir Presentation Sumanth Krishna. A

  1. 1. W eb A pplication T est I n R uby Sumanth Krishna. A
  2. 2. Agenda <ul><li>Introducing the topic </li></ul><ul><li>Discussion on Testing frameworks/tools and it’s necessity </li></ul><ul><li>Ruby </li></ul><ul><li>Installations </li></ul><ul><li>Architecture </li></ul><ul><li>Testcases </li></ul><ul><li>Scope </li></ul>
  3. 3. TAG CLOUD <ul><li>ruby Apache Nginx assertions </li></ul><ul><li>install webserver FireWatir temp- </li></ul><ul><li>user WATIR goto html DOM </li></ul><ul><li>web-applications opensource tests </li></ul><ul><li>Assertions get_string firefox-addon </li></ul><ul><li>click hudson SVN COM open-source IE gems open-QA ruby regression loadrunner mercury automatio deployment browers tools WATIR html DOM recorder telnet </li></ul>
  4. 4. Prerequisites <ul><li>Can you believe you really don’t need any special skills to implement this! </li></ul>
  5. 5. What is WATIR? <ul><li>open-source functional testing tool for web-applications </li></ul><ul><li>Simulate the user actions (filling/submitting forms…) </li></ul><ul><li>Drives Internet Explorer browser </li></ul><ul><ul><li>FireWatir – for FireFox </li></ul></ul><ul><li>Ruby based </li></ul><ul><ul><li>Various assertions (content-based) </li></ul></ul><ul><ul><li>Connects to databases </li></ul></ul><ul><ul><li>Reading data files </li></ul></ul><ul><ul><li>Exporting data (xml/html/excel…) </li></ul></ul>
  6. 6. Why use WATIR? <ul><li>Free </li></ul><ul><li>Powerful </li></ul><ul><li>Simple (easy to use and learn) </li></ul><ul><li>Excellent Support </li></ul><ul><li>Strongest Presence </li></ul><ul><ul><li>Watir/Watin/Watij [ W eb A pplication T esting I n R uby/. N ET/ J ava ] </li></ul></ul><ul><li>Huge resource of supporting tools – </li></ul><ul><ul><li>Firewatir, Watir Recorder ++, Wet, Cubictest, Visual Studio </li></ul></ul>
  7. 7. Is not? <ul><li>Watir is not a record/playback tool. </li></ul><ul><ul><li>However, there are several recorders “out there” </li></ul></ul><ul><ul><ul><li>WatirMaker </li></ul></ul></ul><ul><ul><ul><li>Watir WebRecorder </li></ul></ul></ul><ul><ul><ul><li>Webmetrics RIA Script Recorder (most recent discussion…they are considering open sourcing their application) </li></ul></ul></ul><ul><li>Watir is not a link checker </li></ul><ul><ul><li>However, you can easily write your own link checker and customize it to your specific needs. </li></ul></ul><ul><li>Watir is not a test case management tool. </li></ul><ul><ul><li>However, you can write one in Ruby if desired. </li></ul></ul><ul><li>Doesn’t test Flash or Applets.( underwork ) </li></ul>
  8. 8. IE-WATIR Web Application Automation Interface Use the OLE/COM Automation interface to Internet Explorer IE Watir/Ruby DOM
  9. 9. FF-FireWATIR Automation Interface FF FireWatir/Ruby DOM Web Application JSSh
  10. 10. Browser Support IE COM Test Script Component 1 FF JSSH Apple Events V8 Debugger Dragonfly Component 2 Component 3 Component 4 Watir API
  11. 11. Installing: Windows <ul><li>Install Ruby: Use the Ruby one-click installer for windows </li></ul><ul><li>Install the latest gem watir (ruby packages are called gems) </li></ul><ul><ul><li>gem install watir </li></ul></ul><ul><ul><li>And you find the following gems installing… </li></ul></ul><ul><ul><ul><li>Successfully installed xml-simple-1.0.11 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed s4t-utils-1.0.4 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed builder-2.1.2 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed user-choices-1.1.6 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed commonwatir-1.6.2 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed firewatir-1.6.2 ( to support Firefox ) </li></ul></ul></ul><ul><ul><ul><li>Successfully installed watir-1.6.2 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed win32-api-1.3.0-x86-mswin32-60 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed windows-api-0.3.0 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed rubyforge-1.0.2 </li></ul></ul></ul><ul><ul><ul><li>10 gems installed </li></ul></ul></ul><ul><li>Installation done… let’s move ahead </li></ul>
  12. 12. What Next? <ul><li>Since we are here to test the web-application </li></ul><ul><ul><li>Navigate the browser? </li></ul></ul><ul><ul><li>Find elements on the page? </li></ul></ul><ul><ul><li>Interact with elements on the page? </li></ul></ul><ul><ul><li>Check output on the page? </li></ul></ul><ul><ul><li>Create and use Methods? </li></ul></ul><ul><ul><li>Create formal test cases? </li></ul></ul>
  13. 13. Step by Step <ul><li>Navigate to the browser </li></ul><ul><li>#Always Load the Watir library at the top of your script </li></ul><ul><ul><li>require ‘watir’ </li></ul></ul><ul><li>Start IE and navigate to a given/different URL </li></ul><ul><ul><li>IE = Watir::IE.start(‘’) </li></ul></ul><ul><ul><li>IE.goto(“ ”) </li></ul></ul><ul><ul><li>IE.close </li></ul></ul>
  14. 14. Finding <HTML> Elements IE.frame( how, what ) Frame And many, many more (div, label, image, etc…)… IE.form( how, what ) Form how, what ) HyperLink how, what ) RadioButton IE.checkbox( how, what ) CheckBox IE.select_list( how, what ) DropDownList IE.button( how, what ) Button IE.text_field( how, what ) TextBox
  15. 15. Interacting with Elements <ul><li>#Set the text field (or text area) specified name specified value. </li></ul><ul><ul><li>ie.text_field( :name ,'name').set('value') </li></ul></ul><ul><li>#Sets the select with to the specified value </li></ul><ul><ul><li>ie.select_list( :name ,'name').select('value') </li></ul></ul><ul><li>#Click the button with the specified value (label) </li></ul><ul><ul><li>ie.button( :value ,'value').click </li></ul></ul><ul><li>#Clicks the link matching 'text' </li></ul><ul><ul><li> :text ,'text').click </li></ul></ul><ul><li>#Accessing elements in a &quot;frame&quot; or &quot;iframe&quot; </li></ul><ul><ul><li>ie.frame( :name ,&quot;someFrame&quot;).text_field( :name ,'name').set('value') </li></ul></ul>
  16. 16. Closer view browser.button( :value , &quot;Click Me&quot;).click [Variable] . [method] (: [element] , “ [unique identifier] ” . [method]
  17. 17. Checking Output <ul><li>#Get the title of the page </li></ul><ul><li>ie.title </li></ul><ul><li>#Get all the text displayed on the page </li></ul><ul><li>ie.text </li></ul><ul><li>#Get all the HTML in the body of the page </li></ul><ul><li>ie.html </li></ul><ul><li>#Return true if ‘text’ is displayed on the page </li></ul><ul><li>ie.contains_text('text') </li></ul>
  18. 19. Ruby advantage <ul><li>Since WATIR is ruby based web application testing framework, we can customize the script according to our needs. </li></ul><ul><li>Taking Ruby’s Object Oriented concepts, create more dynamic/customized scripts </li></ul><ul><li>Use classes & methods effectively </li></ul><ul><li>Access even the database to validate the data </li></ul>
  19. 20. Test::Unit Assertions
  20. 21. Methods <ul><li>#Here is an example method for logging into a web application. Its two parameters are a user and password (both of which have defaults). It returns an instance of IE </li></ul><ul><ul><li>def login(user=“test_admin”,password = “Password123”) </li></ul></ul><ul><ul><li>ie=Watir::IE.start(‘’) </li></ul></ul><ul><ul><li>ie.text_field(:name,/user/i).set(user) </li></ul></ul><ul><ul><li>ie.text_field(:name,/password/i).set(password) </li></ul></ul><ul><ul><li>ie.button(:value,/login/i).click </li></ul></ul><ul><ul><li>return ie </li></ul></ul><ul><ul><li>end </li></ul></ul><ul><li>#Now we can easily login with the default user.. </li></ul><ul><li>ie = login </li></ul><ul><li>#or with a unique user </li></ul><ul><li>ie = login(“Fred”,”flinstone”) </li></ul>
  21. 22. Full Fledge Test Case <ul><li>require 'test/unit' #includes Ruby's test case functionality </li></ul><ul><li>require ‘ util ’ #Assuming our login method is saved in util.rb </li></ul><ul><li>#Test cases are contained within classes which extend Ruby’s base test case class </li></ul><ul><li>class MyTest < Test::Unit::TestCase </li></ul><ul><li>def setup #Optional, will be run before each test method. </li></ul><ul><li>@ie = login() #call our login function. </li></ul><ul><li>end </li></ul><ul><li>def test_some_link #Test methods must begin with &quot;test_“ </li></ul><ul><li>,”some_link”).click #click on some link </li></ul><ul><li>#verify that the proper page loaded </li></ul><ul><li>assert(@ie.contains_text(“My Some Link Page”)) </li></ul><ul><li>end </li></ul><ul><li>def teardown #Optional, will be run after each test method. </li></ul><ul><li>@ie.close </li></ul><ul><li>end </li></ul><ul><li>end </li></ul>
  22. 23. Installing: Ubuntu <ul><li>Install Ruby: </li></ul><ul><ul><li>sudo apt-get install ruby </li></ul></ul><ul><li>Install the latest gem firewatir (ruby packages are called gems) </li></ul><ul><ul><li>sudo gem install firewatir </li></ul></ul><ul><ul><li>And you find the following gems installing… </li></ul></ul><ul><ul><ul><li>Successfully installed xml-simple-1.0.11 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed s4t-utils-1.0.4 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed builder-2.1.2 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed user-choices-1.1.6 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed commonwatir-1.6.2 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed firewatir-1.6.2 </li></ul></ul></ul><ul><ul><ul><li>Successfully installed rubyforge-1.0.2 </li></ul></ul></ul><ul><ul><ul><li>7 gems installed ( 3gems to support IE/Windows environment are not installed ) </li></ul></ul></ul><ul><li>Installation done… let’s move ahead </li></ul>
  23. 24. Tweaks/Tips <ul><li>While working on Linux platform need to specify </li></ul><ul><ul><li>require “rubygems” at the top of test case </li></ul></ul><ul><li>ff = </li></ul><ul><li>Start firefox in jssh mode </li></ul><ul><ul><li>For Windows: </li></ul></ul><ul><ul><ul><li>Close instances of firefox (if any) </li></ul></ul></ul><ul><ul><ul><li>Type “firefox.exe –p –jssh” in the “Run” </li></ul></ul></ul><ul><li>ie = </li></ul>
  24. 25. Scope <ul><li>Using Watir for all web applications </li></ul><ul><li>Integrate it with Automation/Building process </li></ul>
  25. 26. References <ul><li>Watir </li></ul><ul><ul><li>Wikipedia: http:// </li></ul></ul><ul><ul><li>Watir main site: http:// /display/WTR/ </li></ul></ul><ul><ul><li>Watir user guide: </li></ul></ul><ul><ul><li>Watir API: </li></ul></ul><ul><ul><li>Mailing List: -general </li></ul></ul><ul><ul><li>Project site: </li></ul></ul><ul><ul><li>User Contributions/examples: </li></ul></ul><ul><ul><li>Watir FAQ: </li></ul></ul><ul><li>Watir Recorder </li></ul><ul><ul><li> </li></ul></ul><ul><ul><li> </li></ul></ul><ul><li>FireWatir </li></ul><ul><ul><li>Source: </li></ul></ul><ul><li>Ruby </li></ul><ul><ul><li>Ruby site: </li></ul></ul><ul><ul><li>Ruby docs: </li></ul></ul><ul><ul><li>Ruby Quickstart: </li></ul></ul>
  26. 27. <ul><li>Thanks </li></ul><ul><li>[email_address] </li></ul><ul><li> </li></ul>