Class: Seleniumrc::SeleniumConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/seleniumrc/selenium_configuration.rb

Overview

The configuration interface. This SeleniumConfiguration acts as a singleton to a SeleniumContext. You can access the SeleniumConfiguration object by calling

Seleniumrc::SeleniumConfiguration.instance

Defined Under Namespace

Modules: BrowserMode

Constant Summary collapse

FIREFOX =
"firefox"
IEXPLORE =
"iexplore"

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSeleniumConfiguration

Returns a new instance of SeleniumConfiguration.



102
103
104
105
106
107
# File 'lib/seleniumrc/selenium_configuration.rb', line 102

def initialize
  self.verify_remote_app_server_is_running = true
  @after_driver_started_listeners = []
  @app_server_initialization = proc {}
  @failure_has_occurred = false
end

Class Attribute Details

.instanceObject

The instance of the Singleton SeleniumConfiguration. On its initial call, the initial configuration is set. The initial configuration is based on Environment variables and defaults. The environment variables are:

  • RAILS_ENV - The Rails environment (defaults: test)

  • selenium_server_host - The host name for the Selenium RC server (default: localhost)

  • selenium_server_port - The port for the Selenium RC server (default: 4444)

  • webrick_host - The host name that the application server will start under (default: localhost)

  • webrick_port - The port that the application server will start under (default: 4000)

  • app_server_engine - The type of server the application will be run with (webrick or mongrel)

  • internal_app_server_host - The host name for the Application server that the Browser will access (default: localhost)

  • internal_app_server_host - The port for the Application server that the Browser will access (default: 4000)

  • keep_browser_open_on_failure - If there is a failure in the test suite, keep the browser window open (default: true)

  • verify_remote_app_server_is_running - Raise an exception if the Application Server is not running (default: true)



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/seleniumrc/selenium_configuration.rb', line 27

def instance
  return @instance if @instance
  @instance = new
  @instance.env = ENV

  @instance.browser = FIREFOX
  @instance.selenium_server_host = "localhost"     # address of selenium RC server (java)
  @instance.selenium_server_port = 4444
  @instance.app_server_engine = :webrick
  @instance.internal_app_server_host = "0.0.0.0"    # internal address of app server (webrick or mongrel)
  @instance.internal_app_server_port = 4000
  @instance.external_app_server_host = "localhost"             # external address of app server (webrick or mongrel)
  @instance.external_app_server_port = 4000
  @instance.server_engine = :webrick
  @instance.keep_browser_open_on_failure = true
  @instance.browser_mode = BrowserMode::Suite
  @instance.verify_remote_app_server_is_running = true

  establish_environment
  @instance
end

Instance Attribute Details

#app_server_engineObject

Returns the value of attribute app_server_engine.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def app_server_engine
  @app_server_engine
end

#app_server_initializationObject

Returns the value of attribute app_server_initialization.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def app_server_initialization
  @app_server_initialization
end

#browserObject

Returns the value of attribute browser.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def browser
  @browser
end

#browser_modeObject

Returns the value of attribute browser_mode.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def browser_mode
  @browser_mode
end

#configurationObject

Returns the value of attribute configuration.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def configuration
  @configuration
end

#driverObject

The SeleniumDriver object, which sublcasses the SeleniumDriver provided by the Selenium RC (openqa.org/selenium-rc/) project.



162
163
164
# File 'lib/seleniumrc/selenium_configuration.rb', line 162

def driver
  @driver
end

#envObject

Returns the value of attribute env.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def env
  @env
end

#external_app_server_hostObject

Returns the value of attribute external_app_server_host.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def external_app_server_host
  @external_app_server_host
end

#external_app_server_portObject

Returns the value of attribute external_app_server_port.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def external_app_server_port
  @external_app_server_port
end

#internal_app_server_hostObject

Returns the value of attribute internal_app_server_host.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def internal_app_server_host
  @internal_app_server_host
end

#internal_app_server_portObject

Returns the value of attribute internal_app_server_port.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def internal_app_server_port
  @internal_app_server_port
end

#keep_browser_open_on_failureObject

Returns the value of attribute keep_browser_open_on_failure.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def keep_browser_open_on_failure
  @keep_browser_open_on_failure
end

#rails_envObject

Returns the value of attribute rails_env.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def rails_env
  @rails_env
end

#rails_rootObject

Returns the value of attribute rails_root.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def rails_root
  @rails_root
end

#selenium_server_hostObject

Returns the value of attribute selenium_server_host.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def selenium_server_host
  @selenium_server_host
end

#selenium_server_portObject

Returns the value of attribute selenium_server_port.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def selenium_server_port
  @selenium_server_port
end

#server_engineObject

Returns the value of attribute server_engine.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def server_engine
  @server_engine
end

#verify_remote_app_server_is_runningObject

Returns the value of attribute verify_remote_app_server_is_running.



83
84
85
# File 'lib/seleniumrc/selenium_configuration.rb', line 83

def verify_remote_app_server_is_running
  @verify_remote_app_server_is_running
end

Instance Method Details

#after_driver_started(&block) ⇒ Object

A callback hook that gets run after the Selenese Interpreter is started.



110
111
112
# File 'lib/seleniumrc/selenium_configuration.rb', line 110

def after_driver_started(&block)
  @after_driver_started_listeners << block
end

#browser_urlObject

The http host name and port to be entered into the browser address bar



132
133
134
# File 'lib/seleniumrc/selenium_configuration.rb', line 132

def browser_url
  "http://#{external_app_server_host}:#{external_app_server_port}"
end

#create_and_initialize_driverObject

nodoc



180
181
182
183
184
185
# File 'lib/seleniumrc/selenium_configuration.rb', line 180

def create_and_initialize_driver # nodoc
  driver = create_driver
  driver.start
  notify_after_driver_started(driver)
  driver
end

#create_driverObject

nodoc



187
188
189
190
191
192
193
194
195
# File 'lib/seleniumrc/selenium_configuration.rb', line 187

def create_driver # nodoc
  return ::Seleniumrc::SeleniumDriver.new(
    selenium_server_host,
    selenium_server_port,
    formatted_browser,
    browser_url,
    15000
  )
end

#create_mongrel_configuratorObject

nodoc



241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
# File 'lib/seleniumrc/selenium_configuration.rb', line 241

def create_mongrel_configurator # nodoc
  dir = File.dirname(__FILE__)
  require 'mongrel/rails'
  settings = {
    :host => internal_app_server_host,
    :port => internal_app_server_port,
    :cwd => @rails_root,
    :log_file => "#{@rails_root}/log/mongrel.log",
    :pid_file => "#{@rails_root}/log/mongrel.pid",
    :environment => @rails_env,
    :docroot => "#{@rails_root}/public",
    :mime_map => nil,
    :daemon => false,
    :debug => false,
    :includes => ["mongrel"],
    :config_script => nil
  }

  configurator = Mongrel::Rails::RailsConfigurator.new(settings) do
    log "Starting Mongrel in #{defaults[:environment]} mode at #{defaults[:host]}:#{defaults[:port]}"
  end
  configurator
end

#create_mongrel_runnerObject

nodoc



234
235
236
237
238
239
# File 'lib/seleniumrc/selenium_configuration.rb', line 234

def create_mongrel_runner # nodoc
  runner = MongrelSeleniumServerRunner.new
  runner.configuration = self
  runner.thread_class = Thread
  runner
end

#create_server_runnerObject

nodoc



197
198
199
200
201
202
203
204
205
206
# File 'lib/seleniumrc/selenium_configuration.rb', line 197

def create_server_runner # nodoc
  case @app_server_engine.to_sym
  when :mongrel
    create_mongrel_runner
  when :webrick
    create_webrick_runner
  else
    raise "Invalid server type: #{selenium_configuration.app_server_type}"
  end
end

#create_webrick_runnerObject

nodoc



208
209
210
211
212
213
214
215
216
217
# File 'lib/seleniumrc/selenium_configuration.rb', line 208

def create_webrick_runner # nodoc
  require 'webrick_server'
  runner = WebrickSeleniumServerRunner.new
  runner.configuration = self
  runner.thread_class = Thread
  runner.socket = Socket
  runner.dispatch_servlet = DispatchServlet
  runner.environment_path = File.expand_path("#{@rails_root}/config/environment")
  runner
end

#create_webrick_serverObject

nodoc



219
220
221
222
223
224
225
226
227
228
# File 'lib/seleniumrc/selenium_configuration.rb', line 219

def create_webrick_server # nodoc
  WEBrick::HTTPServer.new({
    :Port => @internal_app_server_port,
    :BindAddress => @internal_app_server_host,
    :ServerType  => WEBrick::SimpleServer,
    :MimeTypes => WEBrick::HTTPUtils::DefaultMimeTypes,
    :Logger => new_logger,
    :AccessLog => []
  })
end

#failure_has_occurred?Boolean

Has a failure occurred in the tests?

Returns:

  • (Boolean)


127
128
129
# File 'lib/seleniumrc/selenium_configuration.rb', line 127

def failure_has_occurred?
  @failure_has_occurred = true
end

#formatted_browserObject

The browser formatted for the Selenese driver.



122
123
124
# File 'lib/seleniumrc/selenium_configuration.rb', line 122

def formatted_browser
  return "*#{@browser}"
end

#new_loggerObject



230
231
232
# File 'lib/seleniumrc/selenium_configuration.rb', line 230

def new_logger
  Logger.new(StringIO.new)
end

#notify_after_driver_started(driver) ⇒ Object

Notify all after_driver_started callbacks.



115
116
117
118
119
# File 'lib/seleniumrc/selenium_configuration.rb', line 115

def notify_after_driver_started(driver)
  for listener in @after_driver_started_listeners
    listener.call(driver)
  end
end

#server_rootObject

The root directory (public) of the Rails application



137
138
139
# File 'lib/seleniumrc/selenium_configuration.rb', line 137

def server_root
  File.expand_path("#{rails_root}/public/")
end

#stop_driver?(passed) ⇒ Boolean

nodoc

Returns:

  • (Boolean)


175
176
177
178
# File 'lib/seleniumrc/selenium_configuration.rb', line 175

def stop_driver?(passed) # nodoc
  return true if passed
  return !keep_browser_open_on_failure
end

#stop_driver_if_necessary(suite_passed) ⇒ Object

nodoc



167
168
169
170
171
172
173
# File 'lib/seleniumrc/selenium_configuration.rb', line 167

def stop_driver_if_necessary(suite_passed) # nodoc
  failure_has_occurred unless suite_passed
  if @driver && stop_driver?(suite_passed)
    @driver.stop
    @driver = nil
  end
end

#suite_browser_modeObject

Sets the Test Suite to use one browser instance



152
153
154
# File 'lib/seleniumrc/selenium_configuration.rb', line 152

def suite_browser_mode
  @browser_mode = SeleniumConfiguration::BrowserMode::Suite
end

#suite_browser_mode?Boolean

Does the Test Suite to use one browser instance?

Returns:

  • (Boolean)


157
158
159
# File 'lib/seleniumrc/selenium_configuration.rb', line 157

def suite_browser_mode?
  @browser_mode == SeleniumConfiguration::BrowserMode::Suite
end

#test_browser_modeObject

Sets the Test Suite to open a new browser instance for each TestCase



142
143
144
# File 'lib/seleniumrc/selenium_configuration.rb', line 142

def test_browser_mode
  @browser_mode = SeleniumConfiguration::BrowserMode::Test
end

#test_browser_mode?Boolean

Are we going to open a new browser instance for each TestCase?

Returns:

  • (Boolean)


147
148
149
# File 'lib/seleniumrc/selenium_configuration.rb', line 147

def test_browser_mode?
  @browser_mode == SeleniumConfiguration::BrowserMode::Test
end