Skip to content

Instantly share code, notes, and snippets.

@dperezrada
Created April 13, 2013 19:33
Show Gist options
  • Save dperezrada/5379732 to your computer and use it in GitHub Desktop.
Save dperezrada/5379732 to your computer and use it in GitHub Desktop.
require "selenium-webdriver"
require "rspec"
include RSpec::Expectations
describe "Prueba" do
before(:each) do
unless ENV["DRIVER"]
ENV["DRIVER"] = 'phantomjs'
end
case ENV["DRIVER"]
when 'phantomjs'
@driver = Selenium::WebDriver.for(:remote, :url => "http://127.0.0.1:8080")
else
@driver = Selenium::WebDriver.for ENV["DRIVER"].to_sym
end
@base_url = "http://www.imdb.com/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 1
@verification_errors = []
end
after(:each) do
@driver.quit
@verification_errors.should == []
end
it "test_prueba" do
unless ENV["MOVIE"]
ENV["MOVIE"] = "sherlock"
end
puts "DRIVER: " + ENV["DRIVER"]
puts "MOVIE: " + ENV["MOVIE"]
@driver.get(@base_url + "/")
@driver.find_element(:id, "navbar-query").clear
@driver.find_element(:id, "navbar-query").send_keys ENV["MOVIE"]
@driver.find_element(:css, "div.suggestionlabel").click
@driver.find_element(:link, "See more").click
puts "TAGS:"
@driver.find_elements(:css, ".keyword").each do |keyword|
puts "\t#{keyword.text}"
end
end
def element_present?(how, what)
@driver.find_element(how, what)
true
rescue Selenium::WebDriver::Error::NoSuchElementError
false
end
def verify(&blk)
yield
rescue ExpectationNotMetError => ex
@verification_errors << ex
end
def close_alert_and_get_its_text(how, what)
alert = @driver.switch_to().alert()
if (@accept_next_alert) then
alert.accept()
else
alert.dismiss()
end
alert.text
ensure
@accept_next_alert = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment