Selenium Integration with Rails Application

1 min read

Selenium is a suite of tools to automate web browsers across many platforms. It runs in many browsers and operating systems and it can be controlled by many programming languages and testing frameworks. I have used Selenium 1 (Selenium RC) as an Integration tool to test my rails application.
The installation steps to connect Selenium server with selenium client via ruby language as follows

  1. Install the selenium client gem as
       gem install selenium-client
  2. Download seleniumRC (a standalone selenium server) from –> is a jar file)

Now, we will include selenium-client in Rspec/spec_helper.rb as
require “selenium/client”
Next step is to create a file under Rspec/integration/login_spec.rb. Now, lets add the following code in logic_spec.rb
[source language=”ruby”]
require File.expand_path(File.dirname(__FILE__) + ‘/../spec_helper’)
describe Login do
before(:all) do
@verification_errors = []
@browser =
:host => “localhost”,
:port => 4444,
:browser => “*firefox”,
:url => “http://localhost:3000”,
:timeout_in_second => 90)
it “should login with valid username and password” do “http://localhost:3000”
@browser.type “userName”, “xyz”
@browser.type “css=form > table > tbody > tr:nth(1) > td:nth(1) > #password”, “12345” “submit”, :wait_for => :page
assert @browser.is_text_present(“Hello, XYZ”)
The above is the sample code to check any login page of the application. The @browser is an instance of Selenium client which can take couple of necessary arguments. The browser type can be of any browser. I used firefox as my browser and if your firefox is installed in other drive rather than C:(default) then specify the complete location as “:browser => “*firefox <Path to your firefox>/firefox.exe”.
Finally, you need to start the selenium server as

  1. Unzip the downloaded seleniumRC
  2. Open the command prompt and type as java -jar selenium-server-standalone-2.0rc2.jar

This will start the server and instance of selenium client(@browser) will communicate with selenium server through selenium commands. The communication between server and client can be seen in the log as shown in the below image.
Selenium Client provides set of the classes(commands) that can be used to test the application. You can go through these links for further commands
Idiomatic Clasess
Extension Clasess
Other Clasess
In my next blog, I will try to cover how we can integrate Selenium with Capybara.

Related posts:

My Testing Experience with Healthcare Project

Hi Folks, I am working on a healthcare related web application. I would like to share few interesting things that I came across while...
Ashwin Sundarabaskar
5 min read

Fix for Net::OpenTimeout: execution expired When on AWS with…

If you happen to see the error “Net::OpenTimeout: execution expired” and if it originating from /home/ubuntu/.rvm/rubies/ruby-x.x.x/lib/ruby/x.x.x/net/smtp.rb and if you are running your server on...
Praveen Kumar
15 sec read

Speaking at Ruby meetups – a way of giving…

Speaking at meetups is a great way of giving back to the community and so we always encourage our mates at Spritle to be...
Spritle Bot
1 min read

Leave a Reply

Your email address will not be published. Required fields are marked *