Class: SeleniumGrid::Remote

Inherits:
Object
  • Object
show all
Includes:
Singleton, Utils
Defined in:
lib/selenium-grid/remote.rb

Constant Summary collapse

DEFAULT_BROWSER =
"*chrome"
DEFAULT_PORT =
5555
DEFAULT_HOST =
"localhost"
DEFAULT_HUB_URL =
"http://#{DEFAULT_HOST}:#{Hub::HUB_PORT}",

def start(overrides = {})
  classpath = Java::Classpath.new(File.join(File.dirname(__FILE__), %w(.. ..)))
  classpath =  classpath << "." << "lib/openqa/selenium-server-*.jar" << "lib/openqa/selenium-grid-remote-control-standalone-*.jar"
  args = arguments(overrides.reject { |key, value| key == :background })

  options = {
   :classpath => classpath.definition,
   :log => ENV['LOG'] || overrides[:log] || File.join(".", "log", "rc-#{args[:port]}.log"),
   :arguments => args,
   :background => overrides[:background] || ENV['BACKGROUND'] || false,
  }
  Java::VM.new.run "com.thoughtworks.selenium.grid.remotecontrol.SelfRegisteringRemoteControlLauncher", options
end

Instance Method Summary collapse

Instance Method Details

#arguments(overrides = {}) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/selenium-grid/remote.rb', line 53

def arguments(overrides = {})
  options = {
    :host => ENV['HOST'] || DEFAULT_HOST,
    :port => ENV['PORT'] || DEFAULT_PORT,
    :hub_url => ENV['HUB_URL'] || DEFAULT_HUB_URL,
    :env => ENV['ENV'] || DEFAULT_BROWSER,
    :selenium_args => ENV['SELENIUM_ARGS'] || ""
  }.merge(overrides)
  options[:env] = "'#{options[:env].gsub(/["']/, '')}'"
  options
end

#listObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/selenium-grid/remote.rb', line 36

def list
  return {} unless Netstat.instance.running?(Hub::HUB_PORT)
  remotes = ps.split(/\n|\r/)
  return {} if remotes.empty?
  
  remotes.inject({}) do |remotes, remote|
    parts = remote.split(/\s/)
    port = parts[parts.index('-port') + 1]
    browser = parts[parts.index('-env') + 1]
    remotes.merge({ port => browser })
  end
end

#psObject



65
66
67
# File 'lib/selenium-grid/remote.rb', line 65

def ps
  %x{ ps auwx | grep com.thoughtworks.selenium.grid.remotecontrol.SelfRegisteringRemoteControlLauncher | sed '/sh -c java/d' | grep -v grep }
end

#running?(port = ENV['PORT'] || DEFAULT_PORT) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/selenium-grid/remote.rb', line 49

def running?(port = ENV['PORT'] || DEFAULT_PORT)
  Netstat.instance.running?(port)
end

#stop(overrides = {}) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/selenium-grid/remote.rb', line 28

def stop(overrides = {})
  options = {
    :port => ENV['PORT'] || DEFAULT_PORT
  }.merge(overrides)
  
  Lsof.kill(options[:port].to_i)
end