selenium-rc 0.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGES ADDED
@@ -0,0 +1,9 @@
1
+ 1.8.20090512
2
+ Fixed bug where bin/selenium-rc did not stay open
3
+
4
+ 1.7.20090512
5
+ Properly handling Errno::EADDRNOTAVAIL when starting on windows.
6
+
7
+ 1.6.20090512
8
+ Properly terminate server when the process exits.
9
+ Fixed server blocking the process issue.
data/README.markdown ADDED
@@ -0,0 +1,5 @@
1
+ # selenium-rc #
2
+
3
+ Ruby wrapper for the Selenium RC jar. Bundles the jar and provides a binary and Rake tasks to manage them.
4
+
5
+ Selenium RC Home Page: [http://seleniumhq.org/projects/remote-control](http://seleniumhq.org/projects/remote-control)
data/RELEASING ADDED
@@ -0,0 +1,14 @@
1
+ In order to build the gem you need to have Joe installed.
2
+ The full README is located at http://github.com/djanowski/joe,
3
+ but if you're in a rush this is the list of things to do:
4
+
5
+ $ sudo gem install rubyforge
6
+ $ rubyforge setup
7
+ $ rubyforge config
8
+
9
+ $ sudo gem install thor
10
+ $ thor install http://dimaion.com/joe/joe.thor
11
+
12
+ And finally,
13
+
14
+ $ thor joe:release
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "spec"
2
+ require "spec/rake/spectask"
3
+
4
+ task :default => :spec
5
+
6
+ desc "Run all examples"
7
+ Spec::Rake::SpecTask.new("spec") do |t|
8
+ t.spec_files = FileList["spec/**/*_spec.rb"]
9
+ end
data/Thorfile ADDED
@@ -0,0 +1,25 @@
1
+ require "zip/zip"
2
+
3
+ class Joe < Thor
4
+ alias_method :joe_build, :build
5
+ def build
6
+ fetch_jar
7
+ joe_build
8
+ end
9
+
10
+ def fetch_jar
11
+ url = "http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip"
12
+ file = File.join("tmp", File.basename(url))
13
+
14
+ FileUtils.mkdir_p("tmp")
15
+
16
+ system "wget #{url} -O #{file}" unless File.exist?(file)
17
+
18
+ Zip::ZipFile.open(file) do |zipfile|
19
+ jar_file_entry = zipfile.entries.find {|file| file.name =~ /selenium-server\.jar$/}
20
+ destination = "vendor/selenium-server.jar"
21
+ FileUtils.rm_rf(destination)
22
+ zipfile.extract(jar_file_entry, destination)
23
+ end
24
+ end
25
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :major: 2
3
+ :minor: 0
4
+ :patch: 20090610
5
+ :jar_url: http://release.seleniumhq.org/selenium-remote-control/1.0.1/selenium-remote-control-1.0.1-dist.zip
data/bin/selenium-rc ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "..", "lib", "selenium_rc"))
4
+
5
+ SeleniumRC::Server.boot(
6
+ ENV["SELENIUM_SERVER_HOST"] || "0.0.0.0",
7
+ ENV["SELENIUM_SERVER_PORT"],
8
+ :args => ARGV
9
+ )
10
+
11
+ sleep
@@ -0,0 +1,101 @@
1
+ module SeleniumRC
2
+
3
+ class Server
4
+ attr_accessor :host
5
+ attr_accessor :port
6
+ attr_accessor :args
7
+ attr_accessor :timeout
8
+
9
+ def self.boot(*args)
10
+ new(*args).boot
11
+ end
12
+
13
+ def initialize(host, port = nil, options = {})
14
+ @host = host
15
+ @port = port || 4444
16
+ @args = options[:args] || []
17
+ @timeout = options[:timeout]
18
+ end
19
+
20
+ def boot
21
+ start
22
+ wait
23
+ stop_at_exit
24
+ self
25
+ end
26
+
27
+ def log(string)
28
+ puts string
29
+ end
30
+
31
+ def start
32
+ command = "java -jar \"#{jar_path}\""
33
+ command << " -port #{port}"
34
+ command << " #{args.join(' ')}" unless args.empty?
35
+ log "Running: #{command}"
36
+ begin
37
+ fork do
38
+ system(command)
39
+ end
40
+ rescue NotImplementedError
41
+ Thread.start do
42
+ system(command)
43
+ end
44
+ end
45
+ end
46
+
47
+ def stop_at_exit
48
+ at_exit do
49
+ stop
50
+ end
51
+ end
52
+
53
+ def jar_path
54
+ File.expand_path("#{File.dirname(__FILE__)}/../../vendor/selenium-server.jar")
55
+ end
56
+
57
+ def wait
58
+ $stderr.print "==> Waiting for Selenium RC server on port #{port}... "
59
+ wait_for_service_with_timeout
60
+ $stderr.print "Ready!\n"
61
+ rescue SocketError
62
+ fail
63
+ end
64
+
65
+ def fail
66
+ $stderr.puts
67
+ $stderr.puts
68
+ $stderr.puts "==> Failed to boot the Selenium RC server... exiting!"
69
+ exit
70
+ end
71
+
72
+ def stop
73
+ Net::HTTP.get(host, '/selenium-server/driver/?cmd=shutDownSeleniumServer', port)
74
+ end
75
+
76
+ def service_is_running?
77
+ begin
78
+ socket = TCPSocket.new(host, port)
79
+ socket.close unless socket.nil?
80
+ true
81
+ rescue Errno::ECONNREFUSED,
82
+ Errno::EBADF, # Windows
83
+ Errno::EADDRNOTAVAIL # Windows
84
+ false
85
+ end
86
+ end
87
+
88
+ protected
89
+ def wait_for_service_with_timeout
90
+ start_time = Time.now
91
+ timeout = 15
92
+
93
+ until service_is_running?
94
+ if timeout && (Time.now > (start_time + timeout))
95
+ raise SocketError.new("Socket did not open within #{timeout} seconds")
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,4 @@
1
+ dir = File.dirname(__FILE__)
2
+ require "socket"
3
+ require "#{dir}/selenium_rc/server"
4
+ require "net/http"
@@ -0,0 +1,38 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/spec_helper")
2
+
3
+ describe "bin/selenium-rc" do
4
+ attr_reader :root_dir
5
+ before do
6
+ dir = File.dirname(__FILE__)
7
+ @root_dir = File.expand_path("#{dir}/..")
8
+ unless File.exists?("#{root_dir}/vendor/selenium-server.jar")
9
+ raise "vendor/selenium-server.jar does not exist. Try running `rake download_jar_file` to install the jar file."
10
+ end
11
+ end
12
+
13
+ it "starts the SeleniumRC server from the downloaded jar file and terminates it when finished" do
14
+ thread = nil
15
+ Dir.chdir(root_dir) do
16
+ thread = Thread.start do
17
+ system("bin/selenium-rc") || raise("bin/selenium-server failed")
18
+ end
19
+ end
20
+
21
+ server = SeleniumRC::Server.new("0.0.0.0")
22
+
23
+ timeout {server.service_is_running?}
24
+ thread.kill
25
+ Lsof.kill(4444)
26
+ timeout {!server.service_is_running?}
27
+ end
28
+
29
+ def timeout
30
+ start_time = Time.now
31
+ timeout_length = 15
32
+ until yield
33
+ if Time.now > (start_time + timeout_length)
34
+ raise SocketError.new("Socket did not open within #{timeout_length} seconds")
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,34 @@
1
+ require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper")
2
+
3
+ module SeleniumRC
4
+ describe Server do
5
+
6
+ def new_server(*args)
7
+ server = Server.new(*args)
8
+ stub(server).log
9
+ stub(server).fork.yields
10
+ server
11
+ end
12
+
13
+ describe "#start" do
14
+ it "launches java with the jar file and port" do
15
+ @server = new_server("0.0.0.0", 5555)
16
+
17
+ expected_command = %Q{java -jar "/path/to/the.jar" -port 5555}
18
+ mock(@server).system(expected_command)
19
+ mock(@server).jar_path {"/path/to/the.jar"}
20
+ @server.start
21
+ end
22
+
23
+ context "when passed additional arguments" do
24
+ it "adds the additional arguments to the selenium start command" do
25
+ @server = new_server("0.0.0.0", 4444, :args => ["-browserSideLog", "-suppressStupidness"])
26
+ expected_command = %Q{java -jar "/path/to/the.jar" -port 4444 -browserSideLog -suppressStupidness}
27
+ mock(@server).system(expected_command)
28
+ mock(@server).jar_path {"/path/to/the.jar"}
29
+ @server.start
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ require "rubygems"
2
+ require "spec"
3
+ require "spec/autorun"
4
+ require "fileutils"
5
+ require "timeout"
6
+ require "tcp_socket_extension"
7
+ require "rr"
8
+ require "lsof"
9
+
10
+ dir = File.dirname(__FILE__)
11
+ $:.unshift(File.expand_path("#{dir}/../lib"))
12
+ require "selenium_rc"
13
+
14
+ Spec::Runner.configure do |config|
15
+ config.mock_with :rr
16
+ end
@@ -0,0 +1,3 @@
1
+ Dir["#{File.dirname(__FILE__)}/**/*_spec.rb"].each do |file|
2
+ require file
3
+ end
data/vendor/empty.txt ADDED
File without changes
metadata CHANGED
@@ -1,15 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selenium-rc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Damian Janowski
7
+ - Pivotal Labs
8
+ - Nate Clark
9
+ - Brian Takita
10
+ - Chad Woolley
8
11
  autorequire:
9
12
  bindir: bin
10
13
  cert_chain: []
11
14
 
12
- date: 2009-07-20 00:00:00 -03:00
15
+ date: 2009-07-23 00:00:00 -03:00
13
16
  default_executable:
14
17
  dependencies:
15
18
  - !ruby/object:Gem::Dependency
@@ -22,26 +25,37 @@ dependencies:
22
25
  - !ruby/object:Gem::Version
23
26
  version: 1.2.16
24
27
  version:
25
- description: ""
26
- email: damian.janowski@gmail.com
27
- executables: []
28
-
28
+ description: The Selenium RC Server packaged as a gem
29
+ email: pivotallabsopensource@googlegroups.com
30
+ executables:
31
+ - selenium-rc
29
32
  extensions: []
30
33
 
31
- extra_rdoc_files: []
32
-
34
+ extra_rdoc_files:
35
+ - README.markdown
33
36
  files:
34
- - LICENSE
35
- - lib/selenium/rc_server.rb
36
- - test/rc_server_test.rb
37
+ - CHANGES
38
+ - Rakefile
39
+ - README.markdown
40
+ - RELEASING
41
+ - Thorfile
42
+ - VERSION.yml
43
+ - bin/selenium-rc
44
+ - lib/selenium_rc/server.rb
45
+ - lib/selenium_rc.rb
46
+ - spec/bin_selenium_rc_spec.rb
47
+ - spec/selenium_rc/server_spec.rb
48
+ - spec/spec_helper.rb
49
+ - spec/spec_suite.rb
50
+ - vendor/empty.txt
37
51
  - vendor/selenium-server.jar
38
52
  has_rdoc: true
39
- homepage:
53
+ homepage: http://github.com/pivotal/selenium-rc
40
54
  licenses: []
41
55
 
42
56
  post_install_message:
43
- rdoc_options: []
44
-
57
+ rdoc_options:
58
+ - --charset=UTF-8
45
59
  require_paths:
46
60
  - lib
47
61
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -62,6 +76,9 @@ rubyforge_project: seleniumrc
62
76
  rubygems_version: 1.3.4
63
77
  signing_key:
64
78
  specification_version: 3
65
- summary: Selenium RC Server
66
- test_files: []
67
-
79
+ summary: The Selenium RC Server packaged as a gem.
80
+ test_files:
81
+ - spec/bin_selenium_rc_spec.rb
82
+ - spec/selenium_rc/server_spec.rb
83
+ - spec/spec_helper.rb
84
+ - spec/spec_suite.rb
data/LICENSE DELETED
@@ -1,20 +0,0 @@
1
- Permission is hereby granted, free of charge, to any person
2
- obtaining a copy of this software and associated documentation
3
- files (the "Software"), to deal in the Software without
4
- restriction, including without limitation the rights to use,
5
- copy, modify, merge, publish, distribute, sublicense, and/or sell
6
- copies of the Software, and to permit persons to whom the
7
- Software is furnished to do so, subject to the following
8
- conditions:
9
-
10
- The above copyright notice and this permission notice shall be
11
- included in all copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
- OTHER DEALINGS IN THE SOFTWARE.
@@ -1,90 +0,0 @@
1
- require "selenium/client"
2
-
3
- module Selenium
4
- class RCServer
5
- attr :host
6
- attr :port
7
- attr :options
8
-
9
- def initialize(host, port, options = {})
10
- @host, @port, @options = host, port, options
11
- end
12
-
13
- def boot
14
- return if selenium_grid?
15
-
16
- start
17
- wait
18
- stop_at_exit
19
- end
20
-
21
- def start
22
- silence_stream($stdout) do
23
- remote_control.start :background => true
24
- end
25
- end
26
-
27
- def stop_at_exit
28
- at_exit do
29
- stop
30
- end
31
- end
32
-
33
- def remote_control
34
- @remote_control ||= begin
35
- rc = ::Selenium::RemoteControl::RemoteControl.new(host, port, options)
36
- rc.jar_file = jar_path
37
- rc
38
- end
39
- end
40
-
41
- def jar_path
42
- File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "vendor", "selenium-server.jar"))
43
- end
44
-
45
- def selenium_grid?
46
- !! host
47
- end
48
-
49
- def wait
50
- $stderr.print "==> Waiting for Selenium RC server on port #{port}... "
51
- wait_for_socket
52
- $stderr.print "Ready!\n"
53
- rescue SocketError
54
- fail
55
- end
56
-
57
- def wait_for_socket
58
- silence_stream($stdout) do
59
- TCPSocket.wait_for_service_with_timeout \
60
- :host => host || "0.0.0.0",
61
- :port => port,
62
- :timeout => 15 # seconds
63
- end
64
- end
65
-
66
- def fail
67
- $stderr.puts
68
- $stderr.puts
69
- $stderr.puts "==> Failed to boot the Selenium RC server... exiting!"
70
- exit
71
- end
72
-
73
- def stop
74
- silence_stream($stdout) do
75
- remote_control.stop
76
- end
77
- end
78
-
79
- protected
80
-
81
- def silence_stream(stream)
82
- old_stream = stream.dup
83
- stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
84
- stream.sync = true
85
- yield
86
- ensure
87
- stream.reopen(old_stream)
88
- end
89
- end
90
- end
@@ -1,57 +0,0 @@
1
- require "rubygems"
2
-
3
- require File.join(File.dirname(__FILE__), "..", "lib", "selenium", "rc_server")
4
-
5
- require "contest"
6
- require "override"
7
-
8
- # Make sure we're not trying to start or stop.
9
- Selenium::RemoteControl::RemoteControl = Class.new(Selenium::RemoteControl::RemoteControl) do
10
- def start(*args)
11
- raise "Can't actually call #start in tests."
12
- end
13
-
14
- def stop(*args)
15
- raise "Can't actually call #stop in tests."
16
- end
17
- end
18
-
19
- class RCServerTest < Test::Unit::TestCase
20
- include Override
21
-
22
- setup do
23
- @server = Selenium::RCServer.new(nil, "1234", :timeout => 10)
24
- @rc = @server.remote_control
25
- end
26
-
27
- should "have a remote control instance" do
28
- assert_nil @rc.host
29
- assert_equal "1234", @rc.port
30
- assert_equal 10, @rc.timeout_in_seconds
31
- assert_equal File.expand_path(File.join(File.dirname(__FILE__), "..", "vendor", "selenium-server.jar")), @rc.jar_file
32
- end
33
-
34
- should "start" do
35
- expect(@rc, :start, :with => [{:background => true}])
36
- @server.start
37
- end
38
-
39
- should "stop" do
40
- expect(@rc, :stop, :with => [])
41
- @server.stop
42
- end
43
-
44
- should "boot" do
45
- expect(@rc, :start, :with => [{:background => true}])
46
- expect(TCPSocket, :wait_for_service_with_timeout, :with => [{:host => "0.0.0.0", :port => "1234", :timeout => 15}])
47
- expect(@rc, :stop, :with => [])
48
-
49
- @server.boot
50
- end
51
-
52
- should "not boot if it's a grid" do
53
- server = Selenium::RCServer.new("127.0.0.1", "1234", :timeout => 10)
54
-
55
- assert_nil server.boot
56
- end
57
- end