Skip to content

Instantly share code, notes, and snippets.

@prashanth-sams
Last active August 29, 2015 14:01
Show Gist options
  • Save prashanth-sams/a683213329183e510d0d to your computer and use it in GitHub Desktop.
Save prashanth-sams/a683213329183e510d0d to your computer and use it in GitHub Desktop.
Sample Selenium Test using RSpec Unit Test Framework
#!/usr/local/bin/ruby
require "selenium-webdriver"
require "rspec"
describe "Google Search" do
before(:each) do
@driver = Selenium::WebDriver.for :firefox
@base_url = "https://www.google.co.in"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
end
after(:each) do
@driver.quit
end
it "search Prashanth on google" do
@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
sleep 2
end
it "search seleniumworks on google" do
@driver.get(@base_url + "/")
@driver.find_element(:id, "gbqfq").clear
@driver.find_element(:id, "gbqfq").send_keys "Seleniumworks"
@driver.find_element(:id, "gbqfb").click
sleep 2
end
end
__________________________________________________
Run Selenium Test using RSpec
rspec filename.rb
Generate RSpec Test Report
rspec --format html --out report.html filename.rb
__________________________________________________
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment