selenium-grid 0.0.3 → 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,18 +1,18 @@
1
- === 0.0.3 / 2008-10-06
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
- * add log option, and default to current directory
8
+ === 0.0.3 / 2008-10-06
6
9
 
7
- === 0.0.2 / 2008-10-03
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
- * selenium-grid path fix
14
+ * selenium-grid path fix
12
15
 
13
16
  === 0.0.1 / 2008-10-01
14
17
 
15
- * 1 major enhancement
16
-
17
- * Initial development
18
-
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
@@ -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,17 +3,17 @@ 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
19
  :log => ENV['LOG'] || overrides[:log] || File.join(".", "log", "rc-#{args[:port]}.log"),
@@ -23,7 +23,7 @@ module SeleniumGrid
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 = 3
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
@@ -67,5 +67,49 @@ module SeleniumGrid
67
67
  hub.stop
68
68
  end
69
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
70
114
  end
71
115
  end
@@ -79,18 +79,18 @@ module SeleniumGrid
79
79
  remote.stop
80
80
  end
81
81
  end
82
-
82
+
83
83
  context "when called with environment settings" do
84
84
  before do
85
85
  ENV['PORT'] = "1234"
86
86
  end
87
-
87
+
88
88
  it "uses the environment settings" do
89
89
  mock(Lsof).kill(ENV['PORT'].to_i)
90
90
  remote.stop
91
91
  end
92
92
  end
93
-
93
+
94
94
  context "when called with options" do
95
95
  it "uses the options" do
96
96
  mock(Lsof).kill(1234)
@@ -99,7 +99,92 @@ module SeleniumGrid
99
99
  end
100
100
  end
101
101
  end
102
-
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
+
103
188
  describe "#args" do
104
189
  attr_reader :args, :defaults
105
190
  before do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-grid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Dy