Ruby WebDriver – procedure to create test scripts in RSpec

Setup of Ruby and Selenium 2:
1. Download ruby setup file from url . Install the executable file into your system and set Ruby as Environmental variable into your system.
2. Open command prompt and check “ruby  -v “ to verify ruby installation and path setup.
3. After ruby installation run below command for selenium2 installation.
gem install selenium-webdriver
4. Run below command for Rspec.
gem install rspec
5. For more detail about RSpec go to link “

Create First Test Scripts:
require "selenium-webdriver"
require "rspec"

describe "Google Search" do

  before(:each) do
    @driver = Selenium::WebDriver.for :firefox
    @base_url = ""
    @accept_next_alert = true
    @driver.manage.timeouts.implicit_wait = 30
  after(:each) do
  it "search text on google" do
    @driver.get(@base_url + "/")
    @driver.find_element(:id, "gbqfq").clear
    @driver.find_element(:id, "gbqfq").send_keys "testing"
    @driver.find_element(:id, "gbqfb").click


describe: keyword represent test class name, Test case divided in to three part as below:
1. before: before block code executed at beginning of test before executing any test
2. after: this block of code executed after test execution.

3. it: this block of code contains test scripts code. multiple block can be define for multiple test with keyword “it” in one ruby file.

Open command prompt and goto directory of your test and run below command:
rspec GoogleRSpec.rb

Note: GoogleRSpec.rb is file name of above test script.
To generate test scripts execution report, you need to use “--format html --out report.html “

After execution report is generated into “report.html” file,  you can change file name according to you.
rspec --format html --out report.html GoogleRSpec.rb


  1. provide more example like this

  2. When I run through terminal my rspec tests fails and it says 0 examples found. So when I use it keyword in my automation script that doesn't work. How should I make my test script run through terminal.

    How should I make my tests pass through terminal?
    Please provide me with an immediate response.

    PS:- My automation script works fine when I run through RubyMine.


Leave your comments, queries, suggestion I will try to provide solution