Skip to content

Instantly share code, notes, and snippets.

View alisterscott's full-sized avatar

Alister Scott alisterscott

View GitHub Profile
require 'rubygems'
require 'highline/import'
require 'watir-webdriver'
begin
username = ask("What is your twitter username?")
password = ask("and your password?") { |q| q.echo = false }
browser= Watir::Browser.start "twitter.com", :firefox
browser.span(:text => "Sign in").click
browser.text_field(:id => "username").set username
require 'rubygems'
require 'watir-webdriver' # gem install watir-webdriver
require 'rspec' # gem install rspec
class BrowserContainer
attr_reader :browser
def initialize(browser)
@browser = browser
end
@alisterscott
alisterscott / helper.rb
Created August 3, 2011 10:39
methods to locate elements are okay
require 'watir-webdriver'
def search_field browser
browser.text_field(:name => "q")
end
browser = Watir::Browser.new :firefox
begin
@alisterscott
alisterscott / output.txt
Created August 4, 2011 11:58
watirspec output
WatirSpec guards for this implementation:
not_compliant : {:file=>"/Users/alscott/Projects/watir-webdriver/spec/watirspec/browser_spec.rb:53:in `block (2 levels) in <top (required)>'"}
bug : {:file=>"/Users/alscott/Projects/watir-webdriver/spec/watirspec/element_spec.rb:104:in `block (2 levels) in <top (required)>'", :key=>"http://code.google.com/p/selenium/issues/detail?id=157"}
not_compliant : {:file=>"/Users/alscott/Projects/watir-webdriver/spec/watirspec/browser_spec.rb:84:in `block (2 levels) in <top (required)>'"}
deviates : {:file=>"/Users/alscott/Projects/watir-webdriver/spec/watirspec/browser_spec.rb:95:in `block (2 levels) in <top (required)>'"}
not_compliant : {:file=>"/Users/alscott/Projects/watir-webdriver/spec/watirspec/div_spec.rb:185:in `block in <top (required)>'"}
not_compliant : {:file=>"/Users/alscott/Projects/watir-webdriver/spec/watirspec/image_spec.rb:127:in `block in <top (required)>'"}
not_compliant : {:file=>"/Users/als
@alisterscott
alisterscott / bench.rb
Created September 15, 2011 10:08 — forked from jarib/bench.rb
require 'selenium-webdriver'
require "benchmark"
d = Selenium::WebDriver.for :firefox
d.navigate.to "file:///#{Dir.pwd}/test.html"
e = d.find_element(:id => "q")
TESTS = 30
Benchmark.bmbm do |results|
results.report("clear + send_keys:") { TESTS.times {
@alisterscott
alisterscott / bench.rb
Created September 15, 2011 20:00 — forked from jarib/bench.rb
require 'selenium-webdriver'
require "benchmark"
profile = Selenium::WebDriver::Firefox::Profile.new
profile.native_events = false
d = Selenium::WebDriver.for :firefox, :profile => profile
d.navigate.to "file:///#{Dir.pwd}/test.html"
e = d.find_element(:id => "q")
@alisterscott
alisterscott / thread.rb
Created September 20, 2011 23:50
simple watir-webdriver threading example for load testing
require 'thread'
require 'watir-webdriver'
def test_google
3.times do
browser = Watir::Browser.start 'http://www.etsy.com', :chrome
browser.text_field(:name, 'search_query').set 'hat'
start_time = Time.now
browser.button(:text, 'Search').click
end_time = Time.now
@alisterscott
alisterscott / results.txt
Created October 6, 2011 23:05
Benchmark of three ruby testing APIS
user system total real
selenium-webdriver 1.820000 0.830000 24.010000 ( 67.492727)
watir-webdriver 1.850000 0.840000 24.200000 ( 64.550630)
capybara 1.810000 0.830000 25.160000 ( 69.461563)
@alisterscott
alisterscott / retrieve_prices.rb
Created March 23, 2012 21:37
retrieve prices in divs
require 'watir-webdriver'
require 'nokogiri'
require 'bench'
Watir::always_locate = false
b = Watir::Browser.start "http://www.expedia.com/Flights-Search?trip=oneway&leg1=from:SEA,to:SFO,departure:11%2F11%2F2012TANYT&passengers=children:0,adults:1,seniors:0,infantinlap:Y&options=cabinclass:coach,nopenalty:N,sortby:price&mode=search"
prices = []
benchmark 'code' do
@alisterscott
alisterscott / rspec_watir.rb
Created May 23, 2012 03:07
A watir-webdriver rspec example
require 'rspec'
require 'watir-webdriver'
browser = Watir::Browser.new
RSpec.configure do |config|
config.before(:each) { @browser = browser }
config.after(:suite) { browser.close unless browser.nil? }
end