===== Lauren's Ruby Cheatsheet ===== === To find out what version of Watir you are running execute the following: === Go to command prompt and type this:\\ ''ruby -e 'require "watir"; puts Watir::IE::VERSION''\\ You should get something like this:\\ ''1.5.1.1029''\\ === To find out what version of ruby you are running type: === ''ruby -v'' === To view a list of installed gems on your local system: === ''gem list -- local'' //or// ''gem list'' ===To Install/Uninstall Watir gem: === To Install type:\\ ''gem install watir-1[1].5.1.1145.gem'' //Replace watir-1[1].5.1.1145 with the version you wish to install//\\ To Uninstall:\\ ''gem uninstall watir'' === To Search the Mail Archives for answers to your questions: === Go to [[http:www.google.com|Google]] and type the following:\\ ''site:rubyforge.org "[wtr-general]" javascript''\\ //Replace the word 'javascript' with the search term you are searching for// === How to Identify an object when you have 2 or more objects with the same name: === This will click the first link that is found on the page:\\ ''ie.link(:text, 'Employees').click'' Use this syntax for the second (or more):\\ ''ie.link(:text=>'Employees', index=>2).click'' ===How to indentify all objects of the same type=== This is how you can flash all radio buttons in a form. ''ie.form(:index, 1).radios.each { |radio| radio.flash }'' ===Concurrent Tests (using parallel threads)=== ''require 'thread'\\ require 'watir'\\ \\ def test_google\\ ie = Watir::IE.start('http://www.google.com')\\ ie.text_field(:name, "q").set("pickaxe")\\ ie.button(:value, "Google Search").click\\ end''\\ \\ Run the same test three times concurrently in separate browsers\\ ''threads = []\\ 3.times do\\ threads << Thread.new {test_google}\\ end\\ threads.each {|x| x.join}''\\ In this example 3 browser connection are open. Are these 3 browser connection open at same time or one after the another.\\ Per Bret Pettichord: Concurrent threads run in parallel.\\ === Manipulating Strings === 1:#!/usr/bin/ruby -w 2:puts "Hello World!\n" 3: 4:# Print a variable 5:test = "human events" 6:puts test 7: 8:# Combining or concatenating two strings 9:puts "1: When in the course of " + test 10: 11:# Printing a value within a String. Interpolation like Perl 12:puts "2: When in the course of #{test}" 13: 14:# Create a value using a here docment 15:heredoc = < \\ def setup \\ def test_01 \\ def test_02 \\ def test_03 \\ def teardown \\ They will execute in this order (every test method is wrapped with the 'setup' and 'teardown' methods) \\ def setup \\ def test_01 \\ def teardown \\ def setup \\ def test_02 \\ def teardown \\ def setup \\ def test_03 \\ def teardown \\ //You'll want to write your testcases such that you are not launching your ie browser 66x or 180x, etc... use less methods and more assertions within your methods to prevent this...//\\ B. Keep your test cases organized by// objective// or //method// of testing. For example: If it's a simple navigation test, \\ 1. Keep all the sidebar navigation elements testing in one case.\\ 2. & the main 'div' elements in another. ===[Watir] Objects=== ^Object ^ Object Identifiers ^ Common Methods ^ | Button | :id | .attach | | Radio | :name | .back | | Checkbox | :value | .bring_to_front | | Textfield | :index | .checked? | | Hidden | :title | .clear | | SelectList | :url | .click | | Label | :class | .close | | Span | :text | .contains_text | | Div | :beforeText | .each | | P | :afterText | .enabled? | | Link | | .exists? | | Table | | .flash | | Image | | .focus | | | | .front? | | | | .isSet? | | | | .new | | | | .readonly? | | | | .screen_capture | | | | .select | | | | .set | | | | .show_all_objects | | | | .to_a | | | | .to_s | | | | .wait | | | | .wait_for_browser |