pivotal-selenium-grid 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,12 +1,18 @@
1
- === 0.0.2 / 2008-10-03
1
+ === 0.0.4 / 2008-10-06
2
2
 
3
- * 1 major enhancement
3
+ * added hub:list
4
+ * added rc:list
5
+ * added hub:running
6
+ * added rc:running
4
7
 
5
- * selenium-grid path fix
8
+ === 0.0.3 / 2008-10-06
6
9
 
7
- === 0.0.1 / 2008-10-01
10
+ * add log option, and default to current directory
8
11
 
9
- * 1 major enhancement
12
+ === 0.0.2 / 2008-10-03
10
13
 
11
- * Initial development
14
+ * selenium-grid path fix
15
+
16
+ === 0.0.1 / 2008-10-01
12
17
 
18
+ * Initial development
data/bin/selenium-grid CHANGED
@@ -91,22 +91,51 @@ class RcStopOptions < SeleniumGridOptions
91
91
  end
92
92
  end
93
93
 
94
+ class RcRunningOptions < SeleniumGridOptions
95
+
96
+ protected
97
+
98
+ def initialize_options
99
+ return OptionParser.new do |opts|
100
+ opts.banner = "rc:running"
101
+
102
+ opts.on('-p', '--port <port>', "listening port to check if running?", "\tdefault:\t#{Remote::DEFAULT_PORT}") do |port|
103
+ @options[:port] = port
104
+ end
105
+ end
106
+ end
107
+ end
108
+
94
109
  case ARGV.first
95
110
  when 'hub:start':
96
111
  options = HubStartOptions.new.parse(ARGV)
97
112
  Hub.instance.start(options)
98
113
  when 'hub:stop':
99
114
  Hub.instance.stop
115
+ when 'hub:running':
116
+ puts Hub.instance.running?
117
+ when 'hub:list':
118
+ puts Hub.instance.list
100
119
  when 'rc:start':
101
120
  options = RcStartOptions.new.parse(ARGV)
102
121
  Remote.instance.start(options)
103
122
  when 'rc:stop':
104
123
  options = RcStopOptions.new.parse(ARGV)
105
124
  Remote.instance.stop(options)
125
+ when 'rc:running':
126
+ options = RcRunningOptions.new.parse(ARGV)
127
+ puts options[:port] ? Remote.instance.running?(options[:port]) : Remote.instance.running?
128
+ when 'rc:list':
129
+ puts Remote.instance.list.collect { |port, browser| "#{port}\tremote\t#{browser}"}.sort.join("\n")
106
130
  else
107
- puts "Usage: selenium-grid <hub:start|hub:stop|rc:start|rc:stop> [options]"
131
+ puts "Usage: selenium-grid <command> [options]"
132
+ puts ""
133
+ puts "commands"
134
+ puts "\t" + %w(hub:start hub:stop hub:list hub:running rc:start rc:stop rc:list rc:running).join("\n\t")
108
135
  puts ""
136
+
109
137
  HubStartOptions.new.summarize
110
138
  RcStartOptions.new.summarize
111
139
  RcStopOptions.new.summarize
140
+ RcRunningOptions.new.summarize
112
141
  end
data/config/hoe.rb CHANGED
@@ -2,7 +2,29 @@ AUTHOR = ['Ryan Dy', 'Corey Innis']
2
2
  EMAIL = "ops+rubyforge@pivotallabs.com"
3
3
  DESCRIPTION = "Selenium Grid Ruby packages Selenium Grid as a gem"
4
4
  GEM_NAME = 'selenium-grid'
5
- HOMEPATH = "https://github.com/pivotal/selenium-grid"
5
+
6
+ RUBYFORGE_PROJECT = 'selenium-grid'
7
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
8
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
9
+
10
+ @config_file = "~/.rubyforge/user-config.yml"
11
+ @config = nil
12
+ RUBYFORGE_USERNAME = "unknown"
13
+ def rubyforge_username
14
+ unless @config
15
+ begin
16
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
17
+ rescue
18
+ puts <<-EOS
19
+ ERROR: No rubyforge config file found: #{@config_file}"
20
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
21
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
22
+ EOS
23
+ exit
24
+ end
25
+ end
26
+ RUBYFORGE_USERNAME.replace @config["username"]
27
+ end
6
28
 
7
29
  RDOC_OPTS = ['--quiet', '--title', 'selenium-grid documentation',
8
30
  "--opname", "index.html",
@@ -25,6 +47,7 @@ hoe = Hoe.new(GEM_NAME, SeleniumGrid::VERSION::STRING) do |p|
25
47
  p.description = DESCRIPTION
26
48
  p.summary = DESCRIPTION
27
49
  p.url = HOMEPATH
50
+ p.rubyforge_name = RUBYFORGE_PROJECT
28
51
  p.test_globs = ["spec/**/*_spec.rb"]
29
52
  p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
30
53
  p.extra_deps = [
@@ -39,3 +62,5 @@ hoe = Hoe.new(GEM_NAME, SeleniumGrid::VERSION::STRING) do |p|
39
62
  end
40
63
 
41
64
  CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
65
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
66
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
@@ -12,7 +12,7 @@ module SeleniumGrid
12
12
 
13
13
  requirements = {
14
14
  :classpath => classpath.definition,
15
- :log => File.join(File.dirname(__FILE__), "..", "..", "log", "hub.log")
15
+ :log => ENV['LOG'] || overrides[:log] || File.join(".", "log", "hub.log")
16
16
  }
17
17
  options = {
18
18
  :background => ENV['BACKGROUND'] || false,
@@ -24,5 +24,13 @@ module SeleniumGrid
24
24
  def stop
25
25
  Lsof.kill(HUB_PORT)
26
26
  end
27
+
28
+ def list
29
+ "#{HUB_PORT}\thub" if running?
30
+ end
31
+
32
+ def running?
33
+ Lsof.running?(HUB_PORT)
34
+ end
27
35
  end
28
36
  end
@@ -3,27 +3,27 @@ require 'singleton'
3
3
  module SeleniumGrid
4
4
  class Remote
5
5
  include Singleton
6
-
6
+
7
7
  DEFAULT_BROWSER = "*chrome"
8
8
  DEFAULT_PORT = 5555
9
9
  DEFAULT_HOST = "localhost"
10
10
  DEFAULT_HUB_URL = "http://#{DEFAULT_HOST}:#{Hub::HUB_PORT}",
11
-
11
+
12
12
  def start(overrides = {})
13
13
  classpath = Java::Classpath.new(File.join(File.dirname(__FILE__), %w(.. ..)))
14
14
  classpath = classpath << "." << "lib/openqa/selenium-server-*.jar" << "lib/openqa/selenium-grid-remote-control-standalone-*.jar"
15
15
  args = arguments(overrides.reject { |key, value| key == :background })
16
-
16
+
17
17
  options = {
18
18
  :classpath => classpath.definition,
19
- :log => File.join(File.dirname(__FILE__), "..", "..", "log", "rc-#{args[:port]}.log"),
19
+ :log => ENV['LOG'] || overrides[:log] || File.join(".", "log", "rc-#{args[:port]}.log"),
20
20
  :arguments => args,
21
21
  :background => overrides[:background] || ENV['BACKGROUND'] || false,
22
22
  }
23
23
 
24
24
  Java::VM.new.run "com.thoughtworks.selenium.grid.remotecontrol.SelfRegisteringRemoteControlLauncher", options
25
25
  end
26
-
26
+
27
27
  def stop(overrides = {})
28
28
  options = {
29
29
  :port => ENV['PORT'] || DEFAULT_PORT
@@ -31,6 +31,23 @@ module SeleniumGrid
31
31
  Lsof.kill(options[:port].to_i)
32
32
  end
33
33
 
34
+ def list
35
+ return {} unless Lsof.running?(Hub::HUB_PORT)
36
+ remotes = ps.split(/\n|\r/)
37
+ return {} if remotes.empty?
38
+
39
+ remotes.inject({}) do |remotes, remote|
40
+ parts = remote.split(/\s/)
41
+ port = parts[parts.index('-port') + 1]
42
+ browser = parts[parts.index('-env') + 1]
43
+ remotes.merge({ port => browser })
44
+ end
45
+ end
46
+
47
+ def running?(port = ENV['PORT'] || DEFAULT_PORT)
48
+ Lsof.running?(port)
49
+ end
50
+
34
51
  def arguments(overrides = {})
35
52
  options = {
36
53
  :host => ENV['HOST'] || DEFAULT_HOST,
@@ -42,5 +59,9 @@ module SeleniumGrid
42
59
  options[:env] = "'#{options[:env].gsub(/["']/, '')}'"
43
60
  options
44
61
  end
62
+
63
+ def ps
64
+ %x{ ps auwx | grep com.thoughtworks.selenium.grid.remotecontrol.SelfRegisteringRemoteControlLauncher | sed '/sh -c java/d' | grep -v grep }
65
+ end
45
66
  end
46
67
  end
@@ -2,7 +2,7 @@ module SeleniumGrid #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- TINY = 2
5
+ TINY = 4
6
6
  STRING = [MAJOR, MINOR, TINY].join('.')
7
7
  end
8
8
  end
data/lib/tasks/hub.rake CHANGED
@@ -12,4 +12,14 @@ namespace :hub do
12
12
  task(:stop) do
13
13
  Hub.instance.stop
14
14
  end
15
+
16
+ desc "List details about the Hub."
17
+ task(:list) do
18
+ puts Hub.instance.list
19
+ end
20
+
21
+ desc "Check whether the Hub is running."
22
+ task(:running) do
23
+ puts Hub.instance.running?
24
+ end
15
25
  end
data/lib/tasks/rc.rake CHANGED
@@ -3,13 +3,23 @@ require 'rake'
3
3
  namespace :rc do
4
4
  include SeleniumGrid
5
5
 
6
- desc "Launch Remote Control. Usage rake rc:start [PORT=#{Remote::DEFAULT_PORT}]"
6
+ desc "Launch Remote Control (rake rc:start [PORT=#{Remote::DEFAULT_PORT}])"
7
7
  task(:start) do
8
8
  Remote.instance.start
9
9
  end
10
10
 
11
- desc "Stop Remote Control. Usage rake rc:stop [PORT=#{Remote::DEFAULT_PORT}]"
11
+ desc "Stop Remote Control (rake rc:stop [PORT=#{Remote::DEFAULT_PORT}])"
12
12
  task(:stop) do
13
13
  Remote.instance.stop
14
14
  end
15
+
16
+ desc "List details about the Remotes."
17
+ task(:list) do
18
+ puts Remote.instance.list.collect { |port, browser| "#{port}\tremote\t#{browser}"}.sort.join("\n")
19
+ end
20
+
21
+ desc "Check whether a Remote is running (rake rc:running [PORT=#{Remote::DEFAULT_PORT}])"
22
+ task(:running) do
23
+ puts Remote.instance.running?
24
+ end
15
25
  end
@@ -32,15 +32,18 @@ module SeleniumGrid
32
32
  context "when called with environment settings" do
33
33
  before do
34
34
  ENV['BACKGROUND'] = "true"
35
+ ENV['LOG'] = "/var/dummy_log/hub.log"
35
36
  end
36
37
 
37
38
  after do
38
39
  ENV.delete('BACKGROUND')
40
+ ENV.delete('LOG')
39
41
  end
40
42
 
41
43
  it "includes the environment settings as parameters" do
42
44
  mock.instance_of(Java::VM).run(anything, anything) do |class_name, options|
43
45
  options[:background].should == "true"
46
+ options[:log].should == "/var/dummy_log/hub.log"
44
47
  end
45
48
  hub.start
46
49
  end
@@ -50,8 +53,9 @@ module SeleniumGrid
50
53
  it "includes the options as parameters" do
51
54
  mock.instance_of(Java::VM).run(anything, anything) do |class_name, options|
52
55
  options[:background].should be_true
56
+ options[:log].should == "/var/dummy_log/hub.log"
53
57
  end
54
- hub.start(:background => true)
58
+ hub.start(:background => true, :log => "/var/dummy_log/hub.log")
55
59
  end
56
60
  end
57
61
  end
@@ -63,5 +67,49 @@ module SeleniumGrid
63
67
  hub.stop
64
68
  end
65
69
  end
70
+
71
+ describe "#list" do
72
+ context "when the Hub is not running" do
73
+ before do
74
+ mock(Lsof).running?(Hub::HUB_PORT) { false }
75
+ end
76
+
77
+ it "lists nothing" do
78
+ hub.list.should be_nil
79
+ end
80
+ end
81
+
82
+ context "when the Hub is running" do
83
+ before do
84
+ mock(Lsof).running?(Hub::HUB_PORT) { true }
85
+ end
86
+
87
+ it "lists details about the running Hub" do
88
+ hub.list.should == "#{Hub::HUB_PORT}\thub"
89
+ end
90
+ end
91
+ end
92
+
93
+ describe "#running?" do
94
+ context "when the Hub is not running" do
95
+ before do
96
+ mock(Lsof).running?(Hub::HUB_PORT) { false }
97
+ end
98
+
99
+ it "returns false" do
100
+ hub.running?.should be_false
101
+ end
102
+ end
103
+
104
+ context "when the Hub is running" do
105
+ before do
106
+ mock(Lsof).running?(Hub::HUB_PORT) { true }
107
+ end
108
+
109
+ it "lists returns true" do
110
+ hub.running?.should be_true
111
+ end
112
+ end
113
+ end
66
114
  end
67
115
  end
@@ -45,12 +45,14 @@ module SeleniumGrid
45
45
  before do
46
46
  ENV['BACKGROUND'] = 'true'
47
47
  ENV['PORT'] = "1234"
48
+ ENV['LOG'] = "/var/dummy_log/remote.log"
48
49
  end
49
50
 
50
51
  it "includes the environment settings as parameters" do
51
52
  mock.instance_of(Java::VM).run(anything, anything) do |class_name, options|
52
53
  options[:background].should == "true"
53
54
  options[:arguments][:port].should == "1234"
55
+ options[:log].should == "/var/dummy_log/remote.log"
54
56
  end
55
57
  remote.start
56
58
  end
@@ -61,8 +63,9 @@ module SeleniumGrid
61
63
  mock.instance_of(Java::VM).run(anything, anything) do |class_name, options|
62
64
  options[:background].should be_true
63
65
  options[:arguments][:port].should == 1234
66
+ options[:log].should == "/var/dummy_log/remote.log"
64
67
  end
65
- remote.start(:background => true, :port => 1234)
68
+ remote.start(:background => true, :port => 1234, :log => "/var/dummy_log/remote.log")
66
69
  end
67
70
  end
68
71
  end
@@ -76,18 +79,18 @@ module SeleniumGrid
76
79
  remote.stop
77
80
  end
78
81
  end
79
-
82
+
80
83
  context "when called with environment settings" do
81
84
  before do
82
85
  ENV['PORT'] = "1234"
83
86
  end
84
-
87
+
85
88
  it "uses the environment settings" do
86
89
  mock(Lsof).kill(ENV['PORT'].to_i)
87
90
  remote.stop
88
91
  end
89
92
  end
90
-
93
+
91
94
  context "when called with options" do
92
95
  it "uses the options" do
93
96
  mock(Lsof).kill(1234)
@@ -96,7 +99,92 @@ module SeleniumGrid
96
99
  end
97
100
  end
98
101
  end
99
-
102
+
103
+ describe "#list" do
104
+ context "when there is no Remote running" do
105
+ before do
106
+ mock(Lsof).running?(anything) { false }
107
+ end
108
+
109
+ it "lists nothing" do
110
+ remote.list.should be_empty
111
+ end
112
+ end
113
+
114
+ context "when a single Remote is running" do
115
+ before do
116
+ mock(Lsof).running?(Hub::HUB_PORT) { true }
117
+ mock(remote).ps { "prefix -port #{Remote::DEFAULT_PORT} -env #{Remote::DEFAULT_BROWSER} suffix" }
118
+ end
119
+
120
+ it "lists details about the running Remote" do
121
+ remote.list.should == { Remote::DEFAULT_PORT.to_s => Remote::DEFAULT_BROWSER }
122
+ end
123
+ end
124
+
125
+ context "when multiple Remotes are running" do
126
+ before do
127
+ mock(Lsof).running?(Hub::HUB_PORT) { true }
128
+ mock(remote).ps do
129
+ "prefix -port #{Remote::DEFAULT_PORT} -env #{Remote::DEFAULT_BROWSER} suffix\n" +
130
+ "prefix -port 1234 -env *safari suffix\n"
131
+ end
132
+ end
133
+
134
+ it "lists details about the running Remotes" do
135
+ list = remote.list
136
+ list[Remote::DEFAULT_PORT.to_s].should == Remote::DEFAULT_BROWSER
137
+ list["1234"].should == '*safari'
138
+ end
139
+ end
140
+ end
141
+
142
+ describe "#running?" do
143
+ context "when a port number is not provided" do
144
+ context "when a Remote is not running on the default port" do
145
+ before do
146
+ mock(Lsof).running?(Remote::DEFAULT_PORT) { false }
147
+ end
148
+
149
+ it "returns false" do
150
+ remote.running?.should be_false
151
+ end
152
+ end
153
+
154
+ context "when a Remote is running on the default port" do
155
+ before do
156
+ mock(Lsof).running?(Remote::DEFAULT_PORT) { true }
157
+ end
158
+
159
+ it "returns true" do
160
+ remote.running?.should be_true
161
+ end
162
+ end
163
+ end
164
+
165
+ context "when a port number is provided" do
166
+ context "when a Remote is not running on the provided port" do
167
+ before do
168
+ mock(Lsof).running?(1234) { false }
169
+ end
170
+
171
+ it "returns false" do
172
+ remote.running?(1234).should be_false
173
+ end
174
+ end
175
+
176
+ context "when a Remote is running on the provided port" do
177
+ before do
178
+ mock(Lsof).running?(1234) { true }
179
+ end
180
+
181
+ it "returns true" do
182
+ remote.running?(1234).should be_true
183
+ end
184
+ end
185
+ end
186
+ end
187
+
100
188
  describe "#args" do
101
189
  attr_reader :args, :defaults
102
190
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivotal-selenium-grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Dy
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-10-03 00:00:00 -07:00
13
+ date: 2008-10-06 00:00:00 -07:00
14
14
  default_executable: selenium-grid
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -96,7 +96,7 @@ files:
96
96
  - spec/spec_helper.rb
97
97
  - spec/spec_suite.rb
98
98
  has_rdoc: true
99
- homepage: https://github.com/pivotal/selenium-grid
99
+ homepage: http://selenium-grid.rubyforge.org
100
100
  post_install_message:
101
101
  rdoc_options:
102
102
  - --main