Class: Selenium::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium/server.rb

Overview

Wraps the remote server jar

Instance Method Summary collapse

Constructor Details

#initialize(jar, opts = {}) ⇒ Server

Returns a new instance of Server.

Raises:

  • (Errno::ENOENT)


13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/selenium/server.rb', line 13

def initialize(jar, opts = {})
  raise Errno::ENOENT, jar unless File.exist?(jar)

  @jar        = jar
  @host       = "127.0.0.1"
  @port       = opts.fetch(:port, 4444)
  @timeout    = opts.fetch(:timeout, 30)
  @background = opts.fetch(:background, false)
  @log        = opts[:log]

  @additional_args = []
end

Instance Method Details

#<<(arg) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/selenium/server.rb', line 55

def <<(arg)
  if arg.kind_of?(Array)
    @additional_args += arg
  else
    @additional_args << arg.to_s
  end
end

#startObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/selenium/server.rb', line 26

def start
  process.start
  poll_for_service

  unless @background
    begin
      sleep 1 while process.alive?
    rescue Errno::ECHILD
      # no longer alive
    end
  end
end

#stopObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/selenium/server.rb', line 39

def stop
  begin
    Net::HTTP.get(@host, "/selenium-server/driver/?cmd=shutDownSeleniumServer", @port)
  rescue Errno::ECONNREFUSED
  end

  stop_process if @process
  poll_for_shutdown

  @log_file.close if @log_file
end

#webdriver_urlObject



51
52
53
# File 'lib/selenium/server.rb', line 51

def webdriver_url
  "http://#{@host}:#{@port}/wd/hub"
end