selenium-rc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
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.
@@ -0,0 +1,90 @@
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
@@ -0,0 +1,57 @@
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
Binary file
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: selenium-rc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Damian Janowski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-20 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: selenium-client
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.16
24
+ version:
25
+ description: ""
26
+ email: damian.janowski@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - LICENSE
35
+ - lib/selenium/rc_server.rb
36
+ - test/rc_server_test.rb
37
+ - vendor/selenium-server.jar
38
+ has_rdoc: true
39
+ homepage:
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project: seleniumrc
62
+ rubygems_version: 1.3.4
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Selenium RC Server
66
+ test_files: []
67
+