Home > selenium > Run your RC server via Rakefile

Run your RC server via Rakefile

Gone tired of starting your selenium server by typing,

java -jar selenium-server.jar"

from your console or if you’re luckier create a batch file then run it to start your server...

Here’s a more powerful tool to do it. Utilizing the selenium-client ruby gem, first you need to create a rakefile and define the tasks that you want to do. For instance we want to tell our rake to do the following tasks:

1. Start selenium server,

2. Stop selenium server, and

3. Restart selenium server


require 'rubygems'
require 'selenium/rake/tasks' # use selenium rc rake tasks that are bundled with the selenium-client gem

SELENIUM_RC_JAR = Dir[File.dirname(__FILE__) + "/selenium-server*.jar"].first

# Start selenium server task
Selenium::Rake::RemoteControlStartTask.new(:'rc:start') do |rc|
 rc.port = 4444
 rc.timeout_in_seconds = 3 * 60
 rc.background = true
 rc.wait_until_up_and_running = true
 rc.jar_file = SELENIUM_RC_JAR
 rc.additional_args << " -multiWindow -firefoxProfileTemplate FirefoxProfile"

end

# Stop selenium server task
Selenium::Rake::RemoteControlStopTask.new(:'rc:stop') do |rc|
 rc.host = "localhost"
 rc.port = 4444
 rc.timeout_in_seconds = 3 * 60
end

# Restart selenium server task
desc "Restart Selenium Remote Control"
task :'rc:restart' do
 Rake::Task[:"rc:stop"].execute [] rescue nil
 Rake::Task[:"rc:start"].execute []
end

In your console go to the root folder where your rake file is saved, type
“rake -T” or “rake –task”

D:\Projects>rake -T

Console will list all available tasks defined in the rake:

(in D:/Projects)
rake rc:restart  # Restart Selenium Remote Control
rake rc:start    # Launch Selenium Remote Control
rake rc:stop     # Stop Selenium Remote Control running

From this list you can restart/start/close the server by simply invoking the commands  e.g. rake rc:start

About these ads
Categories: selenium Tags: ,
  1. February 9, 2011 at 8:17 pm

    thanks, helped me a lot :)

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: