seleniumrc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +2 -0
- data/README +0 -0
- data/Rakefile +68 -0
- data/lib/seleniumrc/app_server_checker.rb +43 -0
- data/lib/seleniumrc/dsl/selenium_dsl.rb +186 -0
- data/lib/seleniumrc/dsl/test_unit_dsl.rb +95 -0
- data/lib/seleniumrc/extensions/selenium_driver.rb +33 -0
- data/lib/seleniumrc/extensions/testrunnermediator.rb +19 -0
- data/lib/seleniumrc/mongrel_selenium_server_runner.rb +35 -0
- data/lib/seleniumrc/selenium_configuration.rb +78 -0
- data/lib/seleniumrc/selenium_context.rb +226 -0
- data/lib/seleniumrc/selenium_element.rb +195 -0
- data/lib/seleniumrc/selenium_helper.rb +5 -0
- data/lib/seleniumrc/selenium_page.rb +76 -0
- data/lib/seleniumrc/selenium_server_runner.rb +33 -0
- data/lib/seleniumrc/selenium_test_case.rb +95 -0
- data/lib/seleniumrc/tasks/selenium_test_task.rb +21 -0
- data/lib/seleniumrc/wait_for.rb +47 -0
- data/lib/seleniumrc/webrick_selenium_server_runner.rb +33 -0
- data/lib/seleniumrc.rb +28 -0
- data/spec/seleniumrc/app_server_checker_spec.rb +56 -0
- data/spec/seleniumrc/mongrel_selenium_server_runner_spec.rb +42 -0
- data/spec/seleniumrc/selenese_interpreter_spec.rb +25 -0
- data/spec/seleniumrc/selenium_configuration_spec.rb +21 -0
- data/spec/seleniumrc/selenium_context_spec.rb +362 -0
- data/spec/seleniumrc/selenium_element_spec.rb +530 -0
- data/spec/seleniumrc/selenium_page_spec.rb +226 -0
- data/spec/seleniumrc/selenium_server_runner_spec.rb +42 -0
- data/spec/seleniumrc/selenium_test_case_class_method_spec.rb +41 -0
- data/spec/seleniumrc/selenium_test_case_spec.rb +908 -0
- data/spec/seleniumrc/selenium_test_case_spec_helper.rb +23 -0
- data/spec/seleniumrc/webrick_selenium_server_runner_spec.rb +116 -0
- data/spec/spec_helper.rb +57 -0
- data/spec/spec_suite.rb +4 -0
- metadata +83 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
module Seleniumrc
|
2
|
+
class WebrickSeleniumServerRunner < SeleniumServerRunner
|
3
|
+
attr_accessor :socket, :dispatch_servlet, :environment_path
|
4
|
+
|
5
|
+
protected
|
6
|
+
def start_server
|
7
|
+
@socket.do_not_reverse_lookup = true # patch for OS X
|
8
|
+
|
9
|
+
@server = @context.create_webrick_server
|
10
|
+
mount_parameters = {
|
11
|
+
:port => @context.internal_app_server_port,
|
12
|
+
:ip => @context.internal_app_server_host,
|
13
|
+
:environment => @context.rails_env.dup,
|
14
|
+
:server_root => @context.server_root,
|
15
|
+
:server_type => WEBrick::SimpleServer,
|
16
|
+
:charset => "UTF-8",
|
17
|
+
:mime_types => WEBrick::HTTPUtils::DefaultMimeTypes,
|
18
|
+
:working_directory => File.expand_path(@context.rails_root.to_s)
|
19
|
+
}
|
20
|
+
@server.mount('/', @dispatch_servlet, mount_parameters)
|
21
|
+
|
22
|
+
trap("INT") { stop_server }
|
23
|
+
|
24
|
+
require @environment_path
|
25
|
+
require "dispatcher"
|
26
|
+
@server.start
|
27
|
+
end
|
28
|
+
|
29
|
+
def stop_server
|
30
|
+
@server.shutdown
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/seleniumrc.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'logger'
|
3
|
+
require "stringio"
|
4
|
+
|
5
|
+
require "active_record"
|
6
|
+
|
7
|
+
require 'net/http'
|
8
|
+
require 'test/unit'
|
9
|
+
require 'test/unit/testresult'
|
10
|
+
|
11
|
+
require "selenium"
|
12
|
+
require "seleniumrc/extensions/testrunnermediator"
|
13
|
+
require "seleniumrc/extensions/selenium_driver"
|
14
|
+
require "seleniumrc/app_server_checker"
|
15
|
+
require "seleniumrc/selenium_server_runner"
|
16
|
+
require "seleniumrc/mongrel_selenium_server_runner"
|
17
|
+
require "seleniumrc/webrick_selenium_server_runner"
|
18
|
+
require "seleniumrc/wait_for"
|
19
|
+
require "seleniumrc/dsl/test_unit_dsl"
|
20
|
+
require "seleniumrc/dsl/selenium_dsl"
|
21
|
+
require "seleniumrc/selenium_context"
|
22
|
+
require "seleniumrc/selenium_configuration"
|
23
|
+
require "seleniumrc/selenium_page"
|
24
|
+
require "seleniumrc/selenium_element"
|
25
|
+
require "seleniumrc/selenium_test_case"
|
26
|
+
require "seleniumrc/tasks/selenium_test_task"
|
27
|
+
|
28
|
+
require 'webrick_server' if self.class.const_defined? :RAILS_ROOT
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
module Seleniumrc
|
4
|
+
describe AppServerChecker, "on local host" do
|
5
|
+
before(:each) do
|
6
|
+
@context = Seleniumrc::SeleniumContext.new
|
7
|
+
@host = "0.0.0.0"
|
8
|
+
@context.internal_app_server_host = @host
|
9
|
+
@port = 4000
|
10
|
+
@context.internal_app_server_port = @port
|
11
|
+
@app_server_checker = @context.create_app_server_checker
|
12
|
+
@mock_tcp_socket_class = 'mock_tcp_socket_class'
|
13
|
+
@app_server_checker.tcp_socket_class = @mock_tcp_socket_class
|
14
|
+
@expected_translated_local_host_address = "127.0.0.1"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns true for is_server_started? if server is running" do
|
18
|
+
mock(@mock_tcp_socket_class).new(@expected_translated_local_host_address, @port)
|
19
|
+
@app_server_checker.is_server_started?.should == (true)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns false for is_server_started? if server is NOT running" do
|
23
|
+
mock(@mock_tcp_socket_class).new.with(@expected_translated_local_host_address, @port) {raise SocketError}
|
24
|
+
@app_server_checker.is_server_started?.should == (false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe AppServerChecker, "on remote host" do
|
29
|
+
before(:each) do
|
30
|
+
@context = Seleniumrc::SeleniumContext.new
|
31
|
+
@host = "some-remote-host"
|
32
|
+
@context.internal_app_server_host = @host
|
33
|
+
@port = 4000
|
34
|
+
@context.internal_app_server_port = @port
|
35
|
+
@app_server_checker = @context.create_app_server_checker
|
36
|
+
@mock_tcp_socket_class = 'mock_tcp_socket_class'
|
37
|
+
@app_server_checker.tcp_socket_class = @mock_tcp_socket_class
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns true for is_server_started? if verify_remote_app_server_is_running_flag is false" do
|
41
|
+
@context.verify_remote_app_server_is_running = false
|
42
|
+
@app_server_checker.is_server_started?.should == (true)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "returns true for is_server_started? if server is running" do
|
46
|
+
mock(@mock_tcp_socket_class).new.with(@host, @port)
|
47
|
+
@app_server_checker.is_server_started?.should == (true)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "raises exception if server is NOT running and verify_remote_app_server_is_running_flag is true" do
|
51
|
+
@context.verify_remote_app_server_is_running = true
|
52
|
+
mock(@mock_tcp_socket_class).new.with(@host, @port) {raise SocketError}
|
53
|
+
lambda {@app_server_checker.is_server_started?}.should raise_error(RuntimeError)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
context "MongrelSeleniumServerRunner instance" do
|
4
|
+
setup do
|
5
|
+
@context = Seleniumrc::SeleniumContext.new
|
6
|
+
end
|
7
|
+
|
8
|
+
specify "starts server" do
|
9
|
+
runner = create_runner_for_start_server
|
10
|
+
stub(runner).initialize_server
|
11
|
+
@runner.start
|
12
|
+
end
|
13
|
+
|
14
|
+
specify "start_server initializes server" do
|
15
|
+
@runner = create_runner_for_start_server
|
16
|
+
|
17
|
+
mock(@mock_configurator).listener.yields(@mock_configurator)
|
18
|
+
|
19
|
+
stub(@runner).defaults.returns({:environment => ""})
|
20
|
+
fake_rails = Object.new
|
21
|
+
|
22
|
+
mock(@mock_configurator).rails.once.returns(fake_rails)
|
23
|
+
mock(@mock_configurator).uri.with("/", {:handler => fake_rails})
|
24
|
+
mock(@mock_configurator).load_plugins.once
|
25
|
+
@runner.start
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_runner_for_start_server
|
29
|
+
@mock_configurator = mock_configurator = "mock_configurator"
|
30
|
+
stub(@context).create_mongrel_configurator.returns(mock_configurator)
|
31
|
+
@runner = @context.create_mongrel_runner
|
32
|
+
|
33
|
+
mock(@mock_configurator).run
|
34
|
+
stub(@mock_configurator).log
|
35
|
+
mock(@mock_configurator).join
|
36
|
+
|
37
|
+
mock_thread_class = "mock_thread_class"
|
38
|
+
@runner.thread_class = mock_thread_class
|
39
|
+
mock(mock_thread_class).start.yields
|
40
|
+
@runner
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
module Selenium
|
4
|
+
describe SeleneseInterpreter do
|
5
|
+
it "initializes with defaults" do
|
6
|
+
@interpreter = Selenium::SeleneseInterpreter.new("localhost", 4444, "*iexplore", "localhost:3000")
|
7
|
+
|
8
|
+
@interpreter.server_host.should == "localhost"
|
9
|
+
@interpreter.server_port.should == 4444
|
10
|
+
@interpreter.browser_start_command.should == "*iexplore"
|
11
|
+
@interpreter.browser_url.should == "localhost:3000"
|
12
|
+
@interpreter.timeout_in_milliseconds.should == 30000
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should start" do
|
16
|
+
@interpreter = Selenium::SeleneseInterpreter.new("localhost", 4444, "*iexplore", "localhost:3000")
|
17
|
+
|
18
|
+
mock(@interpreter).do_command.
|
19
|
+
with("getNewBrowserSession", ["*iexplore", "localhost:3000"]).returns(" 12345")
|
20
|
+
|
21
|
+
@interpreter.start
|
22
|
+
@interpreter.instance_eval {@session_id}.should == "12345"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
module Seleniumrc
|
4
|
+
describe SeleniumConfiguration do
|
5
|
+
before(:each) do
|
6
|
+
SeleniumConfiguration.instance_eval {@context = nil}
|
7
|
+
@mock_context = SeleniumContext.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should create a new context if it hasn't been called yet" do
|
11
|
+
mock(SeleniumContext).new.returns(@mock_context)
|
12
|
+
SeleniumConfiguration.instance.should == @mock_context
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should reuse the existing context if it has been called. So new/establish_environment should only be called once." do
|
16
|
+
mock(SeleniumContext).new.returns(@mock_context)
|
17
|
+
SeleniumConfiguration.instance.should == @mock_context
|
18
|
+
SeleniumConfiguration.instance.should == @mock_context
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,362 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
|
2
|
+
|
3
|
+
module Seleniumrc
|
4
|
+
describe SeleniumContext do
|
5
|
+
before(:each) do
|
6
|
+
@context = Seleniumrc::SeleniumContext.new
|
7
|
+
@old_rails_root = RAILS_ROOT if Object.const_defined? :RAILS_ROOT
|
8
|
+
silence_warnings { Object.const_set :RAILS_ROOT, "foobar" }
|
9
|
+
require 'webrick_server'
|
10
|
+
end
|
11
|
+
|
12
|
+
after(:each) do
|
13
|
+
if @old_rails_root
|
14
|
+
silence_warnings { Object.const_set :RAILS_ROOT, @old_rails_root }
|
15
|
+
else
|
16
|
+
Object.instance_eval {remove_const :RAILS_ROOT}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it "registers and notifies before_suite callbacks" do
|
21
|
+
proc1_called = false
|
22
|
+
proc1 = lambda {proc1_called = true}
|
23
|
+
proc2_called = false
|
24
|
+
proc2 = lambda {proc2_called = true}
|
25
|
+
|
26
|
+
@context.before_suite(&proc1)
|
27
|
+
@context.before_suite(&proc2)
|
28
|
+
@context.notify_before_suite
|
29
|
+
proc1_called.should == true
|
30
|
+
proc2_called.should == true
|
31
|
+
end
|
32
|
+
|
33
|
+
it "registers and notifies after_selenese_interpreter_started callbacks" do
|
34
|
+
proc1_args = nil
|
35
|
+
proc1 = lambda {|*args| proc1_args = args}
|
36
|
+
proc2_args = nil
|
37
|
+
proc2 = lambda {|*args| proc2_args = args}
|
38
|
+
|
39
|
+
@context.after_selenese_interpreter_started(&proc1)
|
40
|
+
@context.after_selenese_interpreter_started(&proc2)
|
41
|
+
|
42
|
+
expected_interpreter = Object.new
|
43
|
+
@context.notify_after_selenese_interpreter_started(expected_interpreter)
|
44
|
+
proc1_args.should == [expected_interpreter]
|
45
|
+
proc2_args.should == [expected_interpreter]
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates app server checker" do
|
49
|
+
app_server_checker = @context.create_app_server_checker
|
50
|
+
app_server_checker.context.should == @context
|
51
|
+
app_server_checker.tcp_socket_class.should == TCPSocket
|
52
|
+
end
|
53
|
+
|
54
|
+
it "defaults to true for verify_remote_app_server_is_running" do
|
55
|
+
@context.verify_remote_app_server_is_running.should == true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "creates a Selenese interpreter and notify listeners" do
|
59
|
+
@context.selenium_server_host = "selenium_server_host.com"
|
60
|
+
@context.selenium_server_port = 80
|
61
|
+
@context.current_browser = "iexplore"
|
62
|
+
@context.external_app_server_host = "browser_host.com"
|
63
|
+
@context.external_app_server_port = 80
|
64
|
+
|
65
|
+
interpreter = @context.create_interpreter
|
66
|
+
interpreter.server_host.should == "selenium_server_host.com"
|
67
|
+
interpreter.server_port.should == 80
|
68
|
+
interpreter.browser_start_command.should == "*iexplore"
|
69
|
+
interpreter.browser_url.should == "http://browser_host.com:80"
|
70
|
+
end
|
71
|
+
|
72
|
+
it "creates, initializes. and notifies listeners for a Selenese interpreter " do
|
73
|
+
passed_interpreter = nil
|
74
|
+
@context.after_selenese_interpreter_started {|interpreter| passed_interpreter = interpreter}
|
75
|
+
|
76
|
+
stub_interpreter = Object.new
|
77
|
+
start_called = false
|
78
|
+
stub(stub_interpreter).start.returns {start_called = true}
|
79
|
+
stub(@context).create_interpreter.returns {stub_interpreter}
|
80
|
+
interpreter = @context.create_and_initialize_interpreter
|
81
|
+
interpreter.should == stub_interpreter
|
82
|
+
passed_interpreter.should == interpreter
|
83
|
+
start_called.should == true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "creates a Webrick Server Runner" do
|
87
|
+
@context.selenium_server_port = 4000
|
88
|
+
@context.selenium_server_host = "localhost"
|
89
|
+
dir = File.dirname(__FILE__)
|
90
|
+
@context.rails_root = dir
|
91
|
+
@context.rails_env = "test"
|
92
|
+
|
93
|
+
runner = @context.create_webrick_runner
|
94
|
+
runner.should be_an_instance_of(Seleniumrc::WebrickSeleniumServerRunner)
|
95
|
+
runner.context.should == @context
|
96
|
+
runner.thread_class.should == Thread
|
97
|
+
runner.socket.should == Socket
|
98
|
+
runner.dispatch_servlet.should == DispatchServlet
|
99
|
+
runner.environment_path.should == File.expand_path("#{dir}/config/environment")
|
100
|
+
end
|
101
|
+
|
102
|
+
it "creates webrick http server" do
|
103
|
+
@context.internal_app_server_port = 4000
|
104
|
+
@context.internal_app_server_host = "localhost"
|
105
|
+
|
106
|
+
mock_logger = "logger"
|
107
|
+
mock(@context).new_logger.returns(mock_logger)
|
108
|
+
mock(WEBrick::HTTPServer).new.with({
|
109
|
+
:Port => 4000,
|
110
|
+
:BindAddress => "localhost",
|
111
|
+
:ServerType => WEBrick::SimpleServer,
|
112
|
+
:MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes,
|
113
|
+
:Logger => mock_logger,
|
114
|
+
:AccessLog => []
|
115
|
+
})
|
116
|
+
server = @context.create_webrick_server
|
117
|
+
end
|
118
|
+
|
119
|
+
it "creates Mongrel Server Runner" do
|
120
|
+
server = @context.create_mongrel_runner
|
121
|
+
server.should be_instance_of(Seleniumrc::MongrelSeleniumServerRunner)
|
122
|
+
server.context.should == @context
|
123
|
+
server.thread_class.should == Thread
|
124
|
+
end
|
125
|
+
|
126
|
+
it "creates Mongrel configurator" do
|
127
|
+
@context.internal_app_server_host = "localhost"
|
128
|
+
@context.internal_app_server_port = 4000
|
129
|
+
@context.rails_env = "test"
|
130
|
+
@context.rails_root = File.dirname(__FILE__)
|
131
|
+
|
132
|
+
configurator = @context.create_mongrel_configurator
|
133
|
+
configurator.defaults[:host].should == "localhost"
|
134
|
+
configurator.defaults[:port].should == 4000
|
135
|
+
configurator.defaults[:cwd].should == @context.rails_root
|
136
|
+
configurator.defaults[:log_file].should == "#{@context.rails_root}/log/mongrel.log"
|
137
|
+
configurator.defaults[:pid_file].should == "#{@context.rails_root}/log/mongrel.pid"
|
138
|
+
configurator.defaults[:environment].should == "test"
|
139
|
+
configurator.defaults[:docroot].should == "public"
|
140
|
+
configurator.defaults[:mime_map].should be_nil
|
141
|
+
configurator.defaults[:daemon].should == false
|
142
|
+
configurator.defaults[:debug].should == false
|
143
|
+
configurator.defaults[:includes].should == ["mongrel"]
|
144
|
+
configurator.defaults[:config_script].should be_nil
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context SeleniumConfiguration, "#establish_environment" do
|
149
|
+
before(:each) do
|
150
|
+
Seleniumrc::SeleniumConfiguration.instance_eval {@context = nil}
|
151
|
+
@configuration = Seleniumrc::SeleniumConfiguration.instance
|
152
|
+
@context = @configuration
|
153
|
+
end
|
154
|
+
|
155
|
+
it "establish_environment__webrick_host" do
|
156
|
+
should_establish_environment( 'internal_app_server_host', '192.168.10.1', :internal_app_server_host )
|
157
|
+
end
|
158
|
+
|
159
|
+
it "initializes webrick_port" do
|
160
|
+
should_establish_environment( 'internal_app_server_port', 1337, :internal_app_server_port )
|
161
|
+
end
|
162
|
+
|
163
|
+
it "initializes internal_app_server_port" do
|
164
|
+
should_establish_environment( 'external_app_server_port', 1337, :external_app_server_port )
|
165
|
+
end
|
166
|
+
|
167
|
+
it "initializes internal_app_server_host" do
|
168
|
+
should_establish_environment( 'external_app_server_host', 'sammich.com', :external_app_server_host)
|
169
|
+
end
|
170
|
+
|
171
|
+
it "initializes selenium_server_host" do
|
172
|
+
should_establish_environment( 'selenium_server_host', 'sammich.com')
|
173
|
+
end
|
174
|
+
|
175
|
+
it "initializes selenium_server_host" do
|
176
|
+
should_establish_environment( 'selenium_server_port', 1337)
|
177
|
+
end
|
178
|
+
|
179
|
+
it "initializes app_server_engine" do
|
180
|
+
should_establish_environment( 'app_server_engine', :webrick, :app_server_engine)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "initializes browsers" do
|
184
|
+
@context.env = stub_env
|
185
|
+
env_var = "browsers"
|
186
|
+
expected_value = 'konqueror'
|
187
|
+
stub_env[env_var] = expected_value
|
188
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
189
|
+
@configuration.browsers.should == [expected_value]
|
190
|
+
end
|
191
|
+
|
192
|
+
it "initializes keep_browser_open_on_failure" do
|
193
|
+
@context.env = stub_env
|
194
|
+
env_var = 'keep_browser_open_on_failure'
|
195
|
+
stub_env[env_var] = 'false'
|
196
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
197
|
+
@configuration.send(env_var).should == false
|
198
|
+
@configuration.send(env_var).should == false
|
199
|
+
|
200
|
+
stub_env[env_var] = 'true'
|
201
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
202
|
+
@configuration.send(env_var).should == true
|
203
|
+
@configuration.send(env_var).should == true
|
204
|
+
|
205
|
+
stub_env[env_var] = 'blah'
|
206
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
207
|
+
@configuration.send(env_var).should == true
|
208
|
+
@configuration.send(env_var).should == true
|
209
|
+
end
|
210
|
+
|
211
|
+
it "initializes verify_remote_app_server_is_running" do
|
212
|
+
@context.env = stub_env
|
213
|
+
env_var = 'verify_remote_app_server_is_running'
|
214
|
+
stub_env[env_var] = 'false'
|
215
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
216
|
+
@configuration.send(env_var).should == false
|
217
|
+
@configuration.send(env_var).should == false
|
218
|
+
|
219
|
+
stub_env[env_var] = 'true'
|
220
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
221
|
+
@configuration.send(env_var).should == true
|
222
|
+
@configuration.send(env_var).should == true
|
223
|
+
|
224
|
+
stub_env[env_var] = 'blah'
|
225
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
226
|
+
@configuration.send(env_var).should == true
|
227
|
+
@configuration.send(env_var).should == true
|
228
|
+
end
|
229
|
+
|
230
|
+
it "internal_app_server_host" do
|
231
|
+
should_lazily_load @configuration, :internal_app_server_host, "0.0.0.0"
|
232
|
+
end
|
233
|
+
|
234
|
+
it "internal_app_server_port" do
|
235
|
+
should_lazily_load @configuration, :internal_app_server_port, 4000
|
236
|
+
end
|
237
|
+
|
238
|
+
it "external_app_server_host" do
|
239
|
+
should_lazily_load @configuration, :external_app_server_host, "localhost"
|
240
|
+
end
|
241
|
+
|
242
|
+
it "external_app_server_port" do
|
243
|
+
should_lazily_load @configuration, :external_app_server_port, 4000
|
244
|
+
end
|
245
|
+
|
246
|
+
it "browsers__lazy_loaded" do
|
247
|
+
should_lazily_load @configuration, :browsers, [Seleniumrc::SeleniumConfiguration::FIREFOX]
|
248
|
+
end
|
249
|
+
|
250
|
+
it "keep_browser_open_on_failure" do
|
251
|
+
should_lazily_load @configuration, :keep_browser_open_on_failure, true
|
252
|
+
end
|
253
|
+
|
254
|
+
it "formatted_browser" do
|
255
|
+
@configuration.current_browser = Seleniumrc::SeleniumConfiguration::IEXPLORE
|
256
|
+
@configuration.formatted_browser.should == "*iexplore"
|
257
|
+
end
|
258
|
+
|
259
|
+
it "browser_url" do
|
260
|
+
@configuration.external_app_server_host = "test.com"
|
261
|
+
@configuration.external_app_server_port = 101
|
262
|
+
@configuration.browser_url.should == "http://test.com:101"
|
263
|
+
end
|
264
|
+
|
265
|
+
it "run_each_browser_within_the_browsers" do
|
266
|
+
expected_browsers = ["iexplore", "firefox", "custom"]
|
267
|
+
@configuration.browsers = expected_browsers
|
268
|
+
|
269
|
+
index = 0
|
270
|
+
@configuration.run_each_browser do
|
271
|
+
@configuration.current_browser.should == expected_browsers[index]
|
272
|
+
index += 1
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
it "selenese_interpreter__when_in_test_browser_mode__should_be_nil" do
|
277
|
+
@configuration.test_browser_mode!
|
278
|
+
@configuration.selenese_interpreter.should be_nil
|
279
|
+
end
|
280
|
+
|
281
|
+
protected
|
282
|
+
def should_establish_environment( env_var, expected_value, method_name=nil )
|
283
|
+
method_name = env_var unless method_name
|
284
|
+
@context.env = stub_env
|
285
|
+
stub_env[env_var] = expected_value
|
286
|
+
Seleniumrc::SeleniumConfiguration.send :establish_environment
|
287
|
+
Seleniumrc::SeleniumConfiguration.instance.send(method_name).should == expected_value
|
288
|
+
end
|
289
|
+
|
290
|
+
def stub_env
|
291
|
+
@stub_env ||= {}
|
292
|
+
end
|
293
|
+
|
294
|
+
def should_lazily_load(object, method_name, default_value)
|
295
|
+
object.send(method_name).should == default_value
|
296
|
+
test_object = Object.new
|
297
|
+
object.send(method_name.to_s + "=", test_object)
|
298
|
+
object.send(method_name).should == test_object
|
299
|
+
end
|
300
|
+
|
301
|
+
end
|
302
|
+
|
303
|
+
describe SeleniumContext, "#stop_interpreter_if_necessary" do
|
304
|
+
before(:each) do
|
305
|
+
@context = Seleniumrc::SeleniumContext.new
|
306
|
+
end
|
307
|
+
|
308
|
+
it "when suite passes, should stop interpreter" do
|
309
|
+
mock_interpreter = "mock_interpreter"
|
310
|
+
mock(mock_interpreter).stop.once
|
311
|
+
@context.interpreter = mock_interpreter
|
312
|
+
|
313
|
+
@context.stop_interpreter_if_necessary true
|
314
|
+
end
|
315
|
+
|
316
|
+
it "when suite fails and keep browser open on failure, should not stop interpreter" do
|
317
|
+
mock_interpreter = "mock_interpreter"
|
318
|
+
mock(mock_interpreter).stop.never
|
319
|
+
@context.interpreter = mock_interpreter
|
320
|
+
@context.keep_browser_open_on_failure = true
|
321
|
+
|
322
|
+
@context.stop_interpreter_if_necessary false
|
323
|
+
end
|
324
|
+
|
325
|
+
it "when suite fails and not keep browser open on failure, should stop interpreter" do
|
326
|
+
mock_interpreter = "mock_interpreter"
|
327
|
+
mock(mock_interpreter).stop
|
328
|
+
@context.interpreter = mock_interpreter
|
329
|
+
@context.keep_browser_open_on_failure = false
|
330
|
+
|
331
|
+
@context.stop_interpreter_if_necessary false
|
332
|
+
end
|
333
|
+
|
334
|
+
end
|
335
|
+
|
336
|
+
describe SeleniumContext, "#create_server_runner where application server engine is mongrel" do
|
337
|
+
it "creates a mongrel server runner" do
|
338
|
+
context = Seleniumrc::SeleniumContext.new
|
339
|
+
context.app_server_engine = :mongrel
|
340
|
+
runner = context.create_server_runner
|
341
|
+
runner.should be_instance_of(MongrelSeleniumServerRunner)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
context SeleniumContext, "#create_server_runner where application server engine is webrick" do
|
346
|
+
before do
|
347
|
+
Object.const_set :RAILS_ROOT, "foobar"
|
348
|
+
require 'webrick_server'
|
349
|
+
end
|
350
|
+
|
351
|
+
after do
|
352
|
+
Object.instance_eval {remove_const :RAILS_ROOT}
|
353
|
+
end
|
354
|
+
|
355
|
+
it "creates a webrick server runner" do
|
356
|
+
context = Seleniumrc::SeleniumContext.new
|
357
|
+
context.app_server_engine = :webrick
|
358
|
+
runner = context.create_server_runner
|
359
|
+
runner.should be_instance_of(WebrickSeleniumServerRunner)
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|