cheat sheet · selenium · selenium-webdriver · Selenium-webdriver

Selenium WebDriver – Cheat Sheet

Getting Started

Load the Selenium Webdriver library

require 'selenium-webdriver'

Open a browser (Ex: Internet Explorer)

driver = Selenium::WebDriver.for :ie

Go to a specified URL

driver.navigate.to 'http://www.orbitz.com/'

driver.get 'http://www.orbitz.com/'

Close the browser

driver.close

Access an Element

Type somethign in the Text box or text area

driver.find_element(:id,'airOrigin').send_keys("MAA")

To Clear the text from text field
driver.find_element(:id,'airOrigin').send_keys [:control, 'a'], :space

Button

driver.find_element(:id,'BUTTON_ID'').click

Drop down list

select_box=driver.find_element(:id,'airStartTime')

options=select_box.find_elements(:tag_name=>"option")
options.each do |option_field|
if option_field.text == '12a-9a'
option_field.click
break
end
end

Check box

driver.find_element(:id,'airNonStopsPreferred').click

Radio button

driver.find_element(:id,'htlChoice').click

To verify Flights radio button selected or not

driver.find_element(:id,'airChoice').selected?

#if it returns TRUE then radio button already selected.

Return the title of the document

puts driver.title

Return true if the specified text appears on the TAG

puts driver.find_element(:class,'welcomeText').text.include?("Welcome to Orbitz")

To Click SPAN Elements

options=driver.find_elements(:tag_name=>"span")
options.each do |span_field|
if span_field.text == 'Find Flights'
span_field.click
break
end
end

cheat · Ruby · ruby excercise

Cheat — Ruby Gem

Cheat:

Very useful to view cheat sheet of like following things….

association_methods
asunit
authorizenet
autotest
averylongnamethatwecanfind
awk

Installation:

gem install cheat

How to use:

cmd prompt> cheat sheets

It gives lot of outputs. You are able to view all those cheat sheets from command prompt

Ex.

C:\>cheat migrations
migrations:
Methods:
create_table(name, options)
drop_table(name)
rename_table(old_name, new_name)
add_column(table_name, column_name, type, options)
rename_column(table_name, column_name, new_column_name)
change_column(table_name, column_name, type, options)
remove_column(table_name, column_name)
add_index(table_name, column_name, index_type)
remove_index(table_name, column_name)

Available Column Types:
* integer
* float
* datetime
* date
* timestamp
* time
* text
* string
* binary
* boolean
* decimal :precision, :scale

Valid Column Options:
* limit
* null (i.e. “:null => false” implies NOT NULL)
* default (to specify default values)
* :decimal, :precision => 8, :scale => 3

Rake Tasks:
rake db:schema:dump: run after you create a model to capture the schema.rb
rake db:schema:import: import the schema file into the current database (on
error, check if your schema.rb has “:force => true” on the create table
statements
./script/generate migration MigrationName: generate a new migration with a
new ‘highest’ version (run ‘./script/generate migration’ for this info at
your fingertips)
rake db:migrate: migrate your current database to the most recent version
rake db:migrate VERSION=5: migrate your current database to a specific
version (in this case, version 5)
rake db:rollback: migrate down one migration
rake db:rollback STEP=3: migrate down three migrations
rake db:migrate RAILS_ENV=production: migrate your production database

SQL:
Queries can be executed directly:
execute ‘ALTER TABLE researchers ADD CONSTRAINT fk_researchers_departments
FOREIGN KEY ( department_id ) REFERENCES departments( id )’

Example Migration:
class UpdateUsersAndCreateProducts < ActiveRecord::Migration
def self.up
rename_column “users”, “password”, “hashed_password”
remove_column “users”, “email”

User.reset_column_information
User.find(:all).each{|u| #do something with u}

create_table “products”, :force => true do |t|
t.column “name”, :text
t.column “description”, :text
t.column “price”, :decimal, :precision => 9, :scale => 2
end

#the rails 2.0 way:
create_table :people do |t|
t.integer :account_id
t.string  :first_name, :last_name, :null => false
t.text    :description
t.timestamps
end
end

def self.down
rename_column “users”, “hashed_password”, “password”
add_column “users”, “email”, :string
drop_table “products”
end
end

Find Highest version:
script/runner “puts ActiveRecord::Migrator.current_version”

C:\>

For more details,

http://cheat.errtheblog.com/

http://errtheblog.com/posts/21-cheat