Selenium Integration with Rails Application

Dhepthi L Narasimhan

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:

Leave a Reply

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