Skip to content

Instantly share code, notes, and snippets.

@prashanth-sams
Created November 21, 2014 14:30
Show Gist options
  • Save prashanth-sams/0fb0c0d09aa75de686f2 to your computer and use it in GitHub Desktop.
Save prashanth-sams/0fb0c0d09aa75de686f2 to your computer and use it in GitHub Desktop.
Lesson #1
require 'selenium-webdriver'
include RSpec::Expectations
def setup
ENV['HTTP_PROXY'] = ENV['http_proxy'] = nil
@driver = Selenium::WebDriver.for :chrome
@base_url = 'http://www.google.com'
end
def teardown
@driver.quit
end
def run
setup
yield
teardown
end
def wait_for(seconds=5)
Selenium::WebDriver::Wait.new(:timeout => seconds).until { yield }
end
def displayed?(how, what)
@driver.find_element(how, what).displayed?
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
run {
@driver.get(@base_url + "/")
@driver.find_element(:id, "gbqfq").clear
@driver.find_element(:id, "gbqfq").send_keys "Prashanth Sams"
@driver.find_element(:id, "gbqfb").click
wait_for {
displayed?(:css, '#rso .g')
}
@driver.find_element(:css, '#rso .g').text.should =~ /prashanth/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment