seleniumrc 0.0.1 → 0.0.2
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 +4 -0
- data/README +38 -0
- data/Rakefile +1 -1
- data/lib/seleniumrc.rb +2 -4
- data/lib/seleniumrc/dsl/selenium_dsl.rb +8 -143
- data/lib/seleniumrc/extensions/testrunnermediator.rb +2 -2
- data/lib/seleniumrc/mongrel_selenium_server_runner.rb +9 -7
- data/lib/seleniumrc/selenium_configuration.rb +233 -40
- data/lib/seleniumrc/selenium_driver.rb +193 -0
- data/lib/seleniumrc/selenium_element.rb +31 -37
- data/lib/seleniumrc/selenium_page.rb +16 -16
- data/lib/seleniumrc/selenium_server_runner.rb +1 -1
- data/lib/seleniumrc/selenium_test_case.rb +2 -4
- data/lib/seleniumrc/wait_for.rb +3 -10
- data/lib/seleniumrc/webrick_selenium_server_runner.rb +11 -11
- data/spec/seleniumrc/mongrel_selenium_server_runner_spec.rb +31 -38
- data/spec/seleniumrc/selenese_interpreter_spec.rb +12 -12
- data/spec/seleniumrc/selenium_configuration_spec.rb +350 -12
- data/spec/seleniumrc/selenium_driver_spec.rb +104 -0
- data/spec/seleniumrc/selenium_element_spec.rb +78 -76
- data/spec/seleniumrc/selenium_page_spec.rb +39 -29
- data/spec/seleniumrc/selenium_test_case_spec.rb +631 -673
- data/spec/seleniumrc/selenium_test_case_spec_helper.rb +0 -7
- data/spec/seleniumrc/webrick_selenium_server_runner_spec.rb +14 -13
- data/spec/spec_helper.rb +7 -1
- metadata +4 -7
- data/lib/seleniumrc/app_server_checker.rb +0 -43
- data/lib/seleniumrc/extensions/selenium_driver.rb +0 -33
- data/lib/seleniumrc/selenium_context.rb +0 -226
- data/spec/seleniumrc/app_server_checker_spec.rb +0 -56
- data/spec/seleniumrc/selenium_context_spec.rb +0 -362
data/CHANGES
CHANGED
data/README
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
== Introduction
|
2
|
+
|
3
|
+
Welcome to Selenium RC!
|
4
|
+
|
5
|
+
This plugin is designed to let you use Selenium RC to write Selenium tests in Ruby, using a simple series of
|
6
|
+
Rake tasks.
|
7
|
+
|
8
|
+
== Installation
|
9
|
+
|
10
|
+
The current version of this plugin can be found at: http://rubyforge.org/var/svn/pivotalrb/seleniumrc/trunk
|
11
|
+
|
12
|
+
You may install the plugin with the following command:
|
13
|
+
|
14
|
+
script/plugin install svn://rubyforge.org/var/svn/pivotalrb/seleniumrc/trunk
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
The seleniumrc plugin assumes you have a test/selenium directory with a selenium_suite.rb file in
|
18
|
+
it. A sample selenium_suite.rb and selenium_helper.rb can be copied into your test/selenium directory.
|
19
|
+
|
20
|
+
You'll get the following tasks:
|
21
|
+
- selenium:test - starts a Selenium RC server, runs selenium tests, and shuts the server down
|
22
|
+
when they're done
|
23
|
+
|
24
|
+
and lower level tasks as well:
|
25
|
+
- selenium:server starts up a Selenium RC server
|
26
|
+
- selenium:test_with_server_started runs Selenium tests off of an existing server
|
27
|
+
|
28
|
+
== Future Enhancements
|
29
|
+
|
30
|
+
There are a few things we'd like to improve, but we wanted to get this out now. Check the tracker in the pivotal.rb RubyForge project for details.
|
31
|
+
|
32
|
+
== License
|
33
|
+
|
34
|
+
Selenium RC Fu is distributed under the MIT license. Copyright © 2007 Pivotal Labs, Inc.
|
35
|
+
|
36
|
+
== Contributing
|
37
|
+
|
38
|
+
Contributions to this plugin are welcome. Contributions should be accompanied by tests. See http://pivotalrb.rubyforge.org for more details.
|
data/Rakefile
CHANGED
data/lib/seleniumrc.rb
CHANGED
@@ -10,15 +10,13 @@ require 'test/unit/testresult'
|
|
10
10
|
|
11
11
|
require "selenium"
|
12
12
|
require "seleniumrc/extensions/testrunnermediator"
|
13
|
-
require "seleniumrc/
|
14
|
-
require "seleniumrc/
|
13
|
+
require "seleniumrc/wait_for"
|
14
|
+
require "seleniumrc/selenium_driver"
|
15
15
|
require "seleniumrc/selenium_server_runner"
|
16
16
|
require "seleniumrc/mongrel_selenium_server_runner"
|
17
17
|
require "seleniumrc/webrick_selenium_server_runner"
|
18
|
-
require "seleniumrc/wait_for"
|
19
18
|
require "seleniumrc/dsl/test_unit_dsl"
|
20
19
|
require "seleniumrc/dsl/selenium_dsl"
|
21
|
-
require "seleniumrc/selenium_context"
|
22
20
|
require "seleniumrc/selenium_configuration"
|
23
21
|
require "seleniumrc/selenium_page"
|
24
22
|
require "seleniumrc/selenium_element"
|
@@ -5,21 +5,10 @@ module Seleniumrc
|
|
5
5
|
@configuration ||= SeleniumConfiguration.instance
|
6
6
|
end
|
7
7
|
attr_writer :configuration
|
8
|
+
attr_accessor :selenium_driver
|
8
9
|
include WaitFor
|
9
10
|
include TestUnitDsl
|
10
11
|
|
11
|
-
def type(locator,value)
|
12
|
-
element(locator).is_present
|
13
|
-
selenium.type(locator,value)
|
14
|
-
end
|
15
|
-
|
16
|
-
def click(locator)
|
17
|
-
element(locator).is_present
|
18
|
-
selenium.click(locator)
|
19
|
-
end
|
20
|
-
|
21
|
-
alias_method :wait_for_and_click, :click
|
22
|
-
|
23
12
|
# Download a file from the Application Server
|
24
13
|
def download(path)
|
25
14
|
uri = URI.parse(configuration.browser_url + path)
|
@@ -27,142 +16,18 @@ module Seleniumrc
|
|
27
16
|
Net::HTTP.get(uri)
|
28
17
|
end
|
29
18
|
|
30
|
-
def select(select_locator,option_locator)
|
31
|
-
element(select_locator).is_present
|
32
|
-
selenium.select(select_locator,option_locator)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Reload the current page that the browser is on.
|
36
|
-
def reload
|
37
|
-
selenium.get_eval("selenium.browserbot.getCurrentWindow().location.reload()")
|
38
|
-
end
|
39
|
-
|
40
|
-
def method_missing(name, *args)
|
41
|
-
return selenium.send(name, *args)
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
#--------- Commands
|
46
|
-
|
47
|
-
# Open a location and wait for the page to load.
|
48
|
-
def open_and_wait(url)
|
49
|
-
page.open_and_wait url
|
50
|
-
end
|
51
|
-
|
52
|
-
# Click a link and wait for the page to load.
|
53
|
-
def click_and_wait(locator, wait_for = default_timeout)
|
54
|
-
selenium.click locator
|
55
|
-
wait_for_page_to_load(wait_for)
|
56
|
-
end
|
57
|
-
alias_method :click_and_wait_for_page_to_load, :click_and_wait
|
58
|
-
|
59
|
-
# Click the back button and wait for the page to load.
|
60
|
-
def go_back_and_wait
|
61
|
-
selenium.go_back
|
62
|
-
wait_for_page_to_load
|
63
|
-
end
|
64
|
-
|
65
19
|
# Open the home page of the Application and wait for the page to load.
|
66
20
|
def open_home_page
|
67
|
-
|
68
|
-
wait_for_page_to_load
|
69
|
-
end
|
70
|
-
|
71
|
-
# Get the inner html of the located element.
|
72
|
-
def get_inner_html(locator)
|
73
|
-
element(locator).inner_html
|
21
|
+
selenium_driver.open(configuration.browser_url)
|
74
22
|
end
|
75
23
|
|
76
|
-
|
77
|
-
|
78
|
-
selenium.is_element_present(locator) && get_inner_html(locator).include?(text)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Does the element at locator not contain the text?
|
82
|
-
def element_does_not_contain_text(locator, text)
|
83
|
-
return true unless selenium.is_element_present(locator)
|
84
|
-
return !get_inner_html(locator).include?(text)
|
85
|
-
end
|
86
|
-
|
87
|
-
# Does locator element have text fragments in a certain order?
|
88
|
-
def is_text_in_order(locator, *text_fragments)
|
89
|
-
container = Hpricot(get_text(locator))
|
90
|
-
|
91
|
-
everything_found = true
|
92
|
-
wasnt_found_message = "Certain fragments weren't found:\n"
|
93
|
-
|
94
|
-
everything_in_order = true
|
95
|
-
wasnt_in_order_message = "Certain fragments were out of order:\n"
|
96
|
-
|
97
|
-
text_fragments.inject([-1, nil]) do |old_results, new_fragment|
|
98
|
-
old_index = old_results[0]
|
99
|
-
old_fragment = old_results[1]
|
100
|
-
new_index = container.inner_html.index(new_fragment)
|
101
|
-
|
102
|
-
unless new_index
|
103
|
-
everything_found = false
|
104
|
-
wasnt_found_message << "Fragment #{new_fragment} was not found\n"
|
105
|
-
end
|
106
|
-
|
107
|
-
if new_index < old_index
|
108
|
-
everything_in_order = false
|
109
|
-
wasnt_in_order_message << "Fragment #{new_fragment} out of order:\n"
|
110
|
-
wasnt_in_order_message << "\texpected '#{old_fragment}'\n"
|
111
|
-
wasnt_in_order_message << "\tto come before '#{new_fragment}'\n"
|
112
|
-
end
|
113
|
-
|
114
|
-
[new_index, new_fragment]
|
115
|
-
end
|
116
|
-
|
117
|
-
wasnt_found_message << "\n\nhtml follows:\n #{container.inner_html}\n"
|
118
|
-
wasnt_in_order_message << "\n\nhtml follows:\n #{container.inner_html}\n"
|
119
|
-
|
120
|
-
unless everything_found && everything_in_order
|
121
|
-
yield(everything_found, wasnt_found_message, everything_in_order, wasnt_in_order_message)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
#----- Waiting for conditions
|
125
|
-
|
126
|
-
def wait_for_page_to_load(timeout=default_timeout)
|
127
|
-
selenium.wait_for_page_to_load timeout
|
128
|
-
if get_title.include?("Exception caught")
|
129
|
-
flunk "We got a new page, but it was an application exception page.\n\n" + get_html_source
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
def wait_for_element_to_contain(locator, text, message=nil, timeout=default_wait_for_time)
|
134
|
-
wait_for({:message => message, :timeout => timeout}) {element_contains_text(locator, text)}
|
135
|
-
end
|
136
|
-
alias_method :wait_for_element_to_contain_text, :wait_for_element_to_contain
|
137
|
-
|
138
|
-
# Open the log window on the browser. This is useful to diagnose issues with Selenium Core.
|
139
|
-
def show_log(log_level = "debug")
|
140
|
-
get_eval "LOG.setLogLevelThreshold('#{log_level}')"
|
141
|
-
end
|
142
|
-
|
143
|
-
# Slow down each Selenese step after this method is called.
|
144
|
-
def slow_mode
|
145
|
-
get_eval "slowMode = true"
|
146
|
-
get_eval 'window.document.getElementsByName("FASTMODE")[0].checked = true'
|
147
|
-
end
|
148
|
-
|
149
|
-
# Speeds up each Selenese step to normal speed after this method is called.
|
150
|
-
def fast_mode
|
151
|
-
get_eval "slowMode = false"
|
152
|
-
get_eval 'window.document.getElementsByName("FASTMODE")[0].checked = false'
|
153
|
-
end
|
154
|
-
|
155
|
-
def page
|
156
|
-
SeleniumPage.new(@selenium)
|
157
|
-
end
|
158
|
-
|
159
|
-
def element(locator)
|
160
|
-
SeleniumElement.new(@selenium, locator)
|
24
|
+
def method_missing(name, *args)
|
25
|
+
return selenium_driver.send(name, *args)
|
161
26
|
end
|
162
27
|
|
163
28
|
protected
|
164
|
-
attr_accessor :selenium
|
165
29
|
delegate :open,
|
30
|
+
:type,
|
166
31
|
:wait_for_condition,
|
167
32
|
:get_select_options,
|
168
33
|
:get_selected_id,
|
@@ -176,11 +41,11 @@ module Seleniumrc
|
|
176
41
|
:get_selected_values,
|
177
42
|
:get_body_text,
|
178
43
|
:get_html_source,
|
179
|
-
:to => :
|
44
|
+
:to => :selenium_driver
|
180
45
|
|
181
|
-
def
|
46
|
+
def should_stop_driver?
|
182
47
|
return false unless configuration.test_browser_mode?
|
183
|
-
configuration.
|
48
|
+
configuration.stop_driver?(passed?)
|
184
49
|
end
|
185
50
|
end
|
186
51
|
end
|
@@ -8,12 +8,12 @@ class Test::Unit::UI::TestRunnerMediator
|
|
8
8
|
alias_method :initialize, :initialize_with_seleniumrc
|
9
9
|
|
10
10
|
protected
|
11
|
-
def start_app_server
|
11
|
+
def start_app_server(*args)
|
12
12
|
@app_runner = Seleniumrc::SeleniumConfiguration.instance.create_server_runner
|
13
13
|
@app_runner.start
|
14
14
|
end
|
15
15
|
|
16
|
-
def stop_app_server
|
16
|
+
def stop_app_server(*args)
|
17
17
|
@app_runner.stop
|
18
18
|
end
|
19
19
|
end
|
@@ -1,23 +1,24 @@
|
|
1
1
|
module Seleniumrc
|
2
2
|
class MongrelSeleniumServerRunner < SeleniumServerRunner
|
3
3
|
def start
|
4
|
-
|
5
|
-
initialize_server(
|
4
|
+
mongrel_configurator = configuration.create_mongrel_configurator
|
5
|
+
initialize_server(mongrel_configurator)
|
6
6
|
|
7
7
|
@thread_class.start do
|
8
|
-
start_server
|
8
|
+
start_server(mongrel_configurator)
|
9
9
|
end
|
10
10
|
@started = true
|
11
11
|
end
|
12
12
|
|
13
13
|
protected
|
14
|
-
def start_server
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def start_server(mongrel_configurator)
|
15
|
+
mongrel_configurator.run
|
16
|
+
mongrel_configurator.log "Mongrel running at #{configuration.internal_app_server_host}:#{configuration.internal_app_server_port}"
|
17
|
+
mongrel_configurator.join
|
18
18
|
end
|
19
19
|
|
20
20
|
def initialize_server(config)
|
21
|
+
configuration = self.configuration
|
21
22
|
config.listener do |*args|
|
22
23
|
mongrel = (args.first || self)
|
23
24
|
mongrel.log "Starting Rails in environment #{defaults[:environment]} ..."
|
@@ -26,6 +27,7 @@ module Seleniumrc
|
|
26
27
|
|
27
28
|
mongrel.log "Loading any Rails specific GemPlugins"
|
28
29
|
mongrel.load_plugins
|
30
|
+
configuration.app_server_initialization.call(mongrel)
|
29
31
|
end
|
30
32
|
end
|
31
33
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Seleniumrc
|
2
2
|
# The configuration interface. This SeleniumConfiguration acts as a singleton to a SeleniumContext.
|
3
|
-
# You can access the
|
4
|
-
# Seleniumrc::
|
3
|
+
# You can access the SeleniumConfiguration object by calling
|
4
|
+
# Seleniumrc::SeleniumConfiguration.instance
|
5
5
|
class SeleniumConfiguration
|
6
6
|
module BrowserMode
|
7
7
|
Suite = "suite" unless const_defined? :Suite
|
@@ -10,8 +10,8 @@ module Seleniumrc
|
|
10
10
|
FIREFOX = "firefox" unless const_defined? :FIREFOX
|
11
11
|
IEXPLORE = "iexplore" unless const_defined? :IEXPLORE
|
12
12
|
|
13
|
-
|
14
|
-
# The instance of the Singleton
|
13
|
+
class << self
|
14
|
+
# The instance of the Singleton SeleniumConfiguration. On its initial call, the initial configuration is set.
|
15
15
|
# The initial configuration is based on Environment variables and defaults.
|
16
16
|
# The environment variables are:
|
17
17
|
# * RAILS_ENV - The Rails environment (defaults: test)
|
@@ -20,59 +20,252 @@ module Seleniumrc
|
|
20
20
|
# * webrick_host - The host name that the application server will start under (default: localhost)
|
21
21
|
# * webrick_port - The port that the application server will start under (default: 4000)
|
22
22
|
# * app_server_engine - The type of server the application will be run with (webrick or mongrel)
|
23
|
-
# * browsers - A comma-delimited list of browsers that will be tested (e.g. firebox,iexplore)
|
24
23
|
# * internal_app_server_host - The host name for the Application server that the Browser will access (default: localhost)
|
25
24
|
# * internal_app_server_host - The port for the Application server that the Browser will access (default: 4000)
|
26
25
|
# * keep_browser_open_on_failure - If there is a failure in the test suite, keep the browser window open (default: true)
|
27
26
|
# * verify_remote_app_server_is_running - Raise an exception if the Application Server is not running (default: true)
|
28
27
|
def instance
|
29
|
-
return @
|
30
|
-
@
|
31
|
-
@
|
32
|
-
|
33
|
-
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
@
|
41
|
-
@
|
42
|
-
@
|
43
|
-
@
|
44
|
-
@
|
45
|
-
@context.browser_mode = BrowserMode::Suite
|
46
|
-
@context.verify_remote_app_server_is_running = true
|
28
|
+
return @instance if @instance
|
29
|
+
@instance = new
|
30
|
+
@instance.env = ENV
|
31
|
+
|
32
|
+
@instance.browser = FIREFOX
|
33
|
+
@instance.selenium_server_host = "localhost" # address of selenium RC server (java)
|
34
|
+
@instance.selenium_server_port = 4444
|
35
|
+
@instance.app_server_engine = :webrick
|
36
|
+
@instance.internal_app_server_host = "0.0.0.0" # internal address of app server (webrick or mongrel)
|
37
|
+
@instance.internal_app_server_port = 4000
|
38
|
+
@instance.external_app_server_host = "localhost" # external address of app server (webrick or mongrel)
|
39
|
+
@instance.external_app_server_port = 4000
|
40
|
+
@instance.server_engine = :webrick
|
41
|
+
@instance.keep_browser_open_on_failure = true
|
42
|
+
@instance.browser_mode = BrowserMode::Suite
|
43
|
+
@instance.verify_remote_app_server_is_running = true
|
47
44
|
|
48
45
|
establish_environment
|
49
|
-
@
|
46
|
+
@instance
|
50
47
|
end
|
48
|
+
attr_writer :instance
|
51
49
|
|
52
50
|
private
|
53
|
-
def context
|
54
|
-
@context || SeleniumContext.new
|
55
|
-
end
|
56
|
-
|
57
51
|
def establish_environment
|
58
|
-
@
|
59
|
-
@
|
60
|
-
[
|
61
|
-
'
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
52
|
+
@instance.rails_env = env['RAILS_ENV'] if env.include?('RAILS_ENV')
|
53
|
+
@instance.rails_root = Object.const_get(:RAILS_ROOT) if Object.const_defined?(:RAILS_ROOT)
|
54
|
+
[
|
55
|
+
'selenium_server_host',
|
56
|
+
'selenium_server_port',
|
57
|
+
'internal_app_server_port',
|
58
|
+
'internal_app_server_host',
|
59
|
+
'app_server_engine',
|
60
|
+
'external_app_server_host',
|
61
|
+
'external_app_server_port'
|
62
|
+
].each do |env_key|
|
63
|
+
if env.include?(env_key)
|
64
|
+
@instance.send("#{env_key}=", env[env_key])
|
65
|
+
end
|
66
66
|
end
|
67
|
-
[
|
68
|
-
|
67
|
+
[
|
68
|
+
'keep_browser_open_on_failure',
|
69
|
+
'verify_remote_app_server_is_running'
|
70
|
+
].each do |env_key|
|
71
|
+
if env.include?(env_key)
|
72
|
+
@instance.send("#{env_key}=", env[env_key].to_s != false.to_s)
|
73
|
+
end
|
69
74
|
end
|
75
|
+
@instance.browser = env['browser'] if env.include?('browser')
|
70
76
|
end
|
71
77
|
|
72
78
|
def env
|
73
|
-
@
|
79
|
+
@instance.env
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
attr_accessor :configuration,
|
84
|
+
:env,
|
85
|
+
:rails_env,
|
86
|
+
:rails_root,
|
87
|
+
:browser,
|
88
|
+
:driver,
|
89
|
+
:browser_mode,
|
90
|
+
:selenium_server_host,
|
91
|
+
:selenium_server_port,
|
92
|
+
:app_server_engine,
|
93
|
+
:internal_app_server_host,
|
94
|
+
:internal_app_server_port,
|
95
|
+
:external_app_server_host,
|
96
|
+
:external_app_server_port,
|
97
|
+
:server_engine,
|
98
|
+
:keep_browser_open_on_failure,
|
99
|
+
:verify_remote_app_server_is_running,
|
100
|
+
:app_server_initialization
|
101
|
+
|
102
|
+
def initialize
|
103
|
+
self.verify_remote_app_server_is_running = true
|
104
|
+
@after_driver_started_listeners = []
|
105
|
+
@app_server_initialization = proc {}
|
106
|
+
@failure_has_occurred = false
|
107
|
+
end
|
108
|
+
|
109
|
+
# A callback hook that gets run after the Selenese Interpreter is started.
|
110
|
+
def after_driver_started(&block)
|
111
|
+
@after_driver_started_listeners << block
|
112
|
+
end
|
113
|
+
|
114
|
+
# Notify all after_driver_started callbacks.
|
115
|
+
def notify_after_driver_started(driver)
|
116
|
+
for listener in @after_driver_started_listeners
|
117
|
+
listener.call(driver)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# The browser formatted for the Selenese driver.
|
122
|
+
def formatted_browser
|
123
|
+
return "*#{@browser}"
|
124
|
+
end
|
125
|
+
|
126
|
+
# Has a failure occurred in the tests?
|
127
|
+
def failure_has_occurred?
|
128
|
+
@failure_has_occurred = true
|
129
|
+
end
|
130
|
+
|
131
|
+
# The http host name and port to be entered into the browser address bar
|
132
|
+
def browser_url
|
133
|
+
"http://#{external_app_server_host}:#{external_app_server_port}"
|
134
|
+
end
|
135
|
+
|
136
|
+
# The root directory (public) of the Rails application
|
137
|
+
def server_root
|
138
|
+
File.expand_path("#{rails_root}/public/")
|
139
|
+
end
|
140
|
+
|
141
|
+
# Sets the Test Suite to open a new browser instance for each TestCase
|
142
|
+
def test_browser_mode
|
143
|
+
@browser_mode = SeleniumConfiguration::BrowserMode::Test
|
144
|
+
end
|
145
|
+
|
146
|
+
# Are we going to open a new browser instance for each TestCase?
|
147
|
+
def test_browser_mode?
|
148
|
+
@browser_mode == SeleniumConfiguration::BrowserMode::Test
|
149
|
+
end
|
150
|
+
|
151
|
+
# Sets the Test Suite to use one browser instance
|
152
|
+
def suite_browser_mode
|
153
|
+
@browser_mode = SeleniumConfiguration::BrowserMode::Suite
|
154
|
+
end
|
155
|
+
|
156
|
+
# Does the Test Suite to use one browser instance?
|
157
|
+
def suite_browser_mode?
|
158
|
+
@browser_mode == SeleniumConfiguration::BrowserMode::Suite
|
159
|
+
end
|
160
|
+
|
161
|
+
# The SeleniumDriver object, which sublcasses the SeleniumDriver provided by the Selenium RC (http://openqa.org/selenium-rc/) project.
|
162
|
+
def driver
|
163
|
+
return nil unless suite_browser_mode?
|
164
|
+
@driver ||= create_and_initialize_driver
|
165
|
+
end
|
166
|
+
|
167
|
+
def stop_driver_if_necessary(suite_passed) # nodoc
|
168
|
+
failure_has_occurred unless suite_passed
|
169
|
+
if @driver && stop_driver?(suite_passed)
|
170
|
+
@driver.stop
|
171
|
+
@driver = nil
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def stop_driver?(passed) # nodoc
|
176
|
+
return true if passed
|
177
|
+
return !keep_browser_open_on_failure
|
178
|
+
end
|
179
|
+
|
180
|
+
def create_and_initialize_driver # nodoc
|
181
|
+
driver = create_driver
|
182
|
+
driver.start
|
183
|
+
notify_after_driver_started(driver)
|
184
|
+
driver
|
185
|
+
end
|
186
|
+
|
187
|
+
def create_driver # nodoc
|
188
|
+
return ::Seleniumrc::SeleniumDriver.new(
|
189
|
+
selenium_server_host,
|
190
|
+
selenium_server_port,
|
191
|
+
formatted_browser,
|
192
|
+
browser_url,
|
193
|
+
15000
|
194
|
+
)
|
195
|
+
end
|
196
|
+
|
197
|
+
def create_server_runner # nodoc
|
198
|
+
case @app_server_engine.to_sym
|
199
|
+
when :mongrel
|
200
|
+
create_mongrel_runner
|
201
|
+
when :webrick
|
202
|
+
create_webrick_runner
|
203
|
+
else
|
204
|
+
raise "Invalid server type: #{selenium_configuration.app_server_type}"
|
74
205
|
end
|
75
206
|
end
|
76
|
-
|
207
|
+
|
208
|
+
def create_webrick_runner # nodoc
|
209
|
+
require 'webrick_server'
|
210
|
+
runner = WebrickSeleniumServerRunner.new
|
211
|
+
runner.configuration = self
|
212
|
+
runner.thread_class = Thread
|
213
|
+
runner.socket = Socket
|
214
|
+
runner.dispatch_servlet = DispatchServlet
|
215
|
+
runner.environment_path = File.expand_path("#{@rails_root}/config/environment")
|
216
|
+
runner
|
217
|
+
end
|
218
|
+
|
219
|
+
def create_webrick_server # nodoc
|
220
|
+
WEBrick::HTTPServer.new({
|
221
|
+
:Port => @internal_app_server_port,
|
222
|
+
:BindAddress => @internal_app_server_host,
|
223
|
+
:ServerType => WEBrick::SimpleServer,
|
224
|
+
:MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes,
|
225
|
+
:Logger => new_logger,
|
226
|
+
:AccessLog => []
|
227
|
+
})
|
228
|
+
end
|
229
|
+
|
230
|
+
def new_logger
|
231
|
+
Logger.new(StringIO.new)
|
232
|
+
end
|
233
|
+
|
234
|
+
def create_mongrel_runner # nodoc
|
235
|
+
runner = MongrelSeleniumServerRunner.new
|
236
|
+
runner.configuration = self
|
237
|
+
runner.thread_class = Thread
|
238
|
+
runner
|
239
|
+
end
|
240
|
+
|
241
|
+
def create_mongrel_configurator # nodoc
|
242
|
+
dir = File.dirname(__FILE__)
|
243
|
+
require 'mongrel/rails'
|
244
|
+
settings = {
|
245
|
+
:host => internal_app_server_host,
|
246
|
+
:port => internal_app_server_port,
|
247
|
+
:cwd => @rails_root,
|
248
|
+
:log_file => "#{@rails_root}/log/mongrel.log",
|
249
|
+
:pid_file => "#{@rails_root}/log/mongrel.pid",
|
250
|
+
:environment => @rails_env,
|
251
|
+
:docroot => "#{@rails_root}/public",
|
252
|
+
:mime_map => nil,
|
253
|
+
:daemon => false,
|
254
|
+
:debug => false,
|
255
|
+
:includes => ["mongrel"],
|
256
|
+
:config_script => nil
|
257
|
+
}
|
258
|
+
|
259
|
+
configurator = Mongrel::Rails::RailsConfigurator.new(settings) do
|
260
|
+
log "Starting Mongrel in #{defaults[:environment]} mode at #{defaults[:host]}:#{defaults[:port]}"
|
261
|
+
end
|
262
|
+
configurator
|
263
|
+
end
|
264
|
+
|
265
|
+
protected
|
266
|
+
# Sets the failure state to true
|
267
|
+
def failure_has_occurred
|
268
|
+
@failure_has_occurred = true
|
269
|
+
end
|
77
270
|
end
|
78
271
|
end
|