class Selenium::Rake::ServerTask

Defines rake tasks for starting, stopping and restarting the Selenium server.

Usage:

require 'selenium/rake/server_task'

Selenium::Rake::ServerTask.new do |t|
  t.jar = "/path/to/selenium-server-standalone.jar"
  t.port = 4444
  t.opts = %w[-some options]
end

Alternatively, you can have the task download a specific version of the server:

Selenium::Rake::ServerTask.new(:server) do |t|
  t.version = '2.6.0'
end

or the latest version

Selenium::Rake::ServerTask.new(:server) do |t|
  t.version = :latest
end

Tasks defined:

rake selenium:server:start
rake selenium:server:stop
rake selenium:server:restart

Attributes

background[RW]

Whether we should detach from the server process. Default: true

background?[RW]

Whether we should detach from the server process. Default: true

jar[RW]

Path to the selenium server jar

log[RW]

Configure logging. Pass a log file path or a boolean. Default: true

true - log to stdout/stderr false - no logging String - log to the specified file

opts[RW]

Add additional options passed to the server jar.

port[RW]

Port to use for the server. Default: 4444

timeout[RW]

Timeout in seconds for the server to start/stop. Default: 30

version[RW]

Specify the version of the server jar to download

Public Class Methods

new(prefix = "selenium:server") { |self| ... } click to toggle source
# File lib/selenium/rake/server_task.rb, line 99
def initialize(prefix = "selenium:server")
  @jar = nil
  @prefix = prefix
  @port = 4444
  @timeout = 30
  @background = true
  @log = true
  @opts = []
  @version = nil

  yield self if block_given?

  if @version
    @jar = Selenium::Server.download(@version)
  end

  unless @jar
    raise MissingJarFileError, "must provide path to the selenium server jar"
  end

  @server = Selenium::Server.new(@jar, :port       => @port,
                                       :timeout    => @timeout,
                                       :background => @background,
                                       :log        => @log )

  @server << @opts

  define_start_task
  define_stop_task
  define_restart_task
end

Private Instance Methods

define_restart_task() click to toggle source
# File lib/selenium/rake/server_task.rb, line 147
def define_restart_task
  desc 'Restart the Selenium server'
  task "#{@prefix}:restart" do
    @server.stop
    @server.start
  end
end
define_start_task() click to toggle source
# File lib/selenium/rake/server_task.rb, line 133
def define_start_task
  desc "Start the Selenium server"
  task "#{@prefix}:start" do
    @server.start
  end
end
define_stop_task() click to toggle source
# File lib/selenium/rake/server_task.rb, line 140
def define_stop_task
  desc 'Stop the Selenium server'
  task "#{@prefix}:stop" do
    @server.stop
  end
end