Class: Lebowski::Foundation::MainApplication

Inherits:
WindowApplication show all
Defined in:
lib/lebowski/foundation/application.rb

Overview

This class represents a SproutCore-based main application. In order to interact with the actual application you must create an instance of this class and start it. Once started, you are then free to access any object or view that has been created by the application within the web browser.

Constant Summary

SAFARI =
'*safari'
FIREFOX =
'*firefox'
CHROME =
'*chrome'
DEFAULT_BROWSER =
FIREFOX
DEFAULT_SELENIUM_SERVER_HOST =
'localhost'
DEFAULT_SELENIUM_SERVER_PORT =
4444
DEFAULT_APP_SERVER_HOST =
'localhost'
DEFAULT_APP_SERVER_PORT =
4020
DEFAULT_TIMEOUT_IN_SECONDS =
240

Constants included from Lebowski::Foundation

SC_BRANCH_CLOSED, SC_BRANCH_OPEN, SC_BUTTON1_STATUS, SC_BUTTON2_STATUS, SC_BUTTON3_STATUS, SC_LEAF_NODE, SC_MIXED_STATE, SC_PICKER_FIXED, SC_PICKER_MENU, SC_PICKER_POINTER, SC_T_ARRAY, SC_T_BOOL, SC_T_CLASS, SC_T_ERROR, SC_T_FUNCTION, SC_T_HASH, SC_T_NULL, SC_T_NUMBER, SC_T_OBJECT, SC_T_STRING, SC_T_UNDEFINED

Constants included from Lebowski::Foundation::Mixins::WaitActions

Lebowski::Foundation::Mixins::WaitActions::DEFAULT_TIMEOUT

Instance Attribute Summary (collapse)

Attributes inherited from Application

#app_context_manager, #parent_app

Attributes inherited from ProxyObject

#driver, #name, #parent, #rel_path

Instance Method Summary (collapse)

Methods inherited from WindowApplication

#maximize, #move_to, #resize_to

Methods inherited from Application

#abs_path, #acquire_application_context, #bundle_loaded?, #define_root_object, #do_aquire_application_context, #exec_driver_in_context, #exec_in_context, #has_current_application_context?, #key_pane, #main_pane, #responding_panes, #root_object

Methods included from Lebowski::Foundation::Mixins::KeyCheck

#key_down?, #key_up?

Methods inherited from ProxyObject

#==, #[], #abs_path, #abs_path_with, #define, #define_proxy, #init_ext, #method_missing, #none?, #object?, #proxy, #represent_as, #sc_all_classes, #sc_class, #sc_guid, #sc_kind_of?, #sc_path_defined?, #sc_type_of, #unravel_relative_path

Methods included from Lebowski::Foundation::Mixins::DefinePathsSupport

#define_path, #define_paths_for, #defined_path, #defined_paths, #path_defined?, #root_defined_path_part, #root_defined_path_part=

Methods included from Lebowski::Foundation::Mixins::WaitActions

#wait_until

Constructor Details

- (MainApplication) initialize(params)

Creates an Application instance that will allow you to interact with a SproutCore-based application.

Initialization requires a hash input containing parameters to set up the application instance. At minimum, the following are required

app_root_path  => The root URL path to the SproutCore-based application (e.g. /my_app)
app_name       => The name of the application's root object (e.g. MyApp)

In addition to the two required params, the following optional params can also be supplied:

selenium_server_host => The name of the host the selenium server is running on (default is localhost)
selenium_server_port => The port the selenium server is listening on (default is 4444)
app_server_host      => The name of the server hosting the web application (defalt is localhost)
app_server_port      => The port on the server to access the web application (default is 4020)
browser              => The web browser to load the web application in to (default is SAFARI)

Example:

Lebowski::Foundation::Application.new \
  :app_root_path => "/hello_world",
  :app_name => "HelloWorldApp"


280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/lebowski/foundation/application.rb', line 280

def initialize(params)
  super(params)
  
  @host = get_selenium_server_host(params)
  @port = get_selenium_server_port(params)
  @browser = get_browser(params)
  
  @app_root_path = get_app_root_path(params)
  raise ArgumentError.new "Application root path is required - :app_root_path" if @app_root_path.nil?
  
  @app_name = get_app_name(params)
  raise ArgumentError.new "Application name is required - :app_name" if @app_name.nil?
  
  @rel_path = @app_name
  @timeout_in_seconds = get_timeout_in_second(params)
  @base_url = get_application_base_url(params)
  @session_id = get_session_id(params)
  
  @driver = Lebowski::Runtime::SproutCoreDriver.new \
    :host => @host, 
    :port => @port, 
    :browser => @browser, 
    :url => @base_url, 
    :timeout_in_second => @timeout_in_seconds
    
  @started = false 
  
  @app_context_manager = Support::ApplicationContextManager.new self
  @parent_app = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Lebowski::Foundation::ProxyObject

Instance Attribute Details

- (Object) app_name (readonly)

Returns the value of attribute app_name



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def app_name
  @app_name
end

- (Object) app_root_path (readonly)

Returns the value of attribute app_root_path



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def app_root_path
  @app_root_path
end

- (Object) base_url (readonly)

Returns the value of attribute base_url



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def base_url
  @base_url
end

- (Object) browser (readonly)

Returns the value of attribute browser



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def browser
  @browser
end

- (Object) host (readonly)

Returns the value of attribute host



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def host
  @host
end

- (Object) port (readonly)

Returns the value of attribute port



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def port
  @port
end

- (Object) session_id (readonly)

Returns the value of attribute session_id



247
248
249
# File 'lib/lebowski/foundation/application.rb', line 247

def session_id
  @session_id
end

Instance Method Details

- (Object) define_app_name(name)



381
382
383
# File 'lib/lebowski/foundation/application.rb', line 381

def define_app_name(name)
  define_path name
end

- (Object) do_acquire_application_context



390
391
392
# File 'lib/lebowski/foundation/application.rb', line 390

def do_acquire_application_context()
  @driver.sc_select_main_window
end

- (Object) end



360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/lebowski/foundation/application.rb', line 360

def end()
  return if (not started?)
  
  begin
    @driver.stop
    @started = false
  rescue Exception => ex
    err_message = "Error disconnecting from selenium server: #{ex.message}\n"
    err_message << "Confirm that selenium server is running on #{@selenium_server_host}:#{@selenium_server_port}"
    raise Runtime::SeleniumServerError.new err_message
  end
end

- (Object) opened_windows



385
386
387
388
# File 'lib/lebowski/foundation/application.rb', line 385

def opened_windows()
  @opened_windows = Support::OpenedWindows.new(self) if @opened_windows.nil?
  return @opened_windows
end

- (Object) reset_application_context



377
378
379
# File 'lib/lebowski/foundation/application.rb', line 377

def reset_application_context()
  acquire_application_context app_name
end

- (Object) start(timeout = nil, &block)

Responsible for starting the application. The application will create an internal driver that is used to actually communicate with the selenium server.

You can optionally supply a block used to wait until some condition has been satisfied before going on and running the rest of your script. Example:

application.start do |it|
  it['appIsLoaded'] == true
end

If the condition does not become true before timing out then an exception will be thrown. You can adjust the timeout like so,

application.start(20) do |it|
  it['appIsLoaded'] == true
end


331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/lebowski/foundation/application.rb', line 331

def start(timeout=nil, &block)
  return if started?
  
  begin
    if @session_id.nil? 
      @driver.start
    else 
      @driver.session_id = @session_id
    end
    
    @driver.set_application_name @app_name
  	@driver.open_sc_application @app_root_path, @timeout_in_seconds
  	@started = true
  rescue Exception => ex
    err_message = "Error connecting to selenium server: #{ex.message}\n"
    err_message << "Confirm that selenium server is running on #{@selenium_server_host}:#{@selenium_server_port}"
    raise Runtime::SeleniumServerError.new err_message
  end
  
  if block_given?
    begin
      wait_until(timeout, &block)
    rescue TimeoutError => toe
      err_message = "Unable to start application. Wait condition was not met before timeout. #{toe.message}"
      raise TimeoutError.new err_message
    end
  end
end

- (Boolean) started?

Returns:

  • (Boolean)


373
374
375
# File 'lib/lebowski/foundation/application.rb', line 373

def started?()
  return @started
end