class Lebowski::Foundation::MainApplication
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.
Constants
- CHROME
- DEFAULT_APP_SERVER_HOST
- DEFAULT_APP_SERVER_PORT
- DEFAULT_BROWSER
- DEFAULT_SELENIUM_SERVER_HOST
- DEFAULT_SELENIUM_SERVER_PORT
- DEFAULT_TIMEOUT_IN_SECONDS
- FIREFOX
- GOOGLECHROME
- IEHTA
- IEXPLORER
- SAFARI
Attributes
Public Class Methods
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"
Lebowski::Foundation::WindowApplication::new
# File lib/lebowski/foundation/application.rb, line 287 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
Public Instance Methods
# File lib/lebowski/foundation/application.rb, line 388 def define_app_name(name) define_path name end
# File lib/lebowski/foundation/application.rb, line 397 def do_acquire_application_context() @driver.sc_select_main_window end
# File lib/lebowski/foundation/application.rb, line 367 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
# File lib/lebowski/foundation/application.rb, line 392 def opened_windows() @opened_windows = Support::OpenedWindows.new(self) if @opened_windows.nil? return @opened_windows end
# File lib/lebowski/foundation/application.rb, line 384 def reset_application_context() acquire_application_context app_name end
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
# File lib/lebowski/foundation/application.rb, line 338 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
# File lib/lebowski/foundation/application.rb, line 380 def started?() return @started end
Private Instance Methods
# File lib/lebowski/foundation/application.rb, line 475 def get_app_name(params) return params[:app_name] end
# File lib/lebowski/foundation/application.rb, line 471 def get_app_root_path(params) return params[:app_root_path] end
# File lib/lebowski/foundation/application.rb, line 421 def get_app_server_host(params) return DEFAULT_APP_SERVER_HOST if params[:app_server_host].nil? return params[:app_server_host] end
# File lib/lebowski/foundation/application.rb, line 426 def get_app_server_port(params) return DEFAULT_APP_SERVER_PORT if params[:app_server_port].nil? return params[:app_server_port].to_i end
# File lib/lebowski/foundation/application.rb, line 431 def get_application_base_url(params) client = get_selenium_client(params) return client.browser_url if (not client.nil?) host = get_app_server_host(params) host = "http://#{host}" if not host =~ /^http(|s):\/\// return "#{host}:#{get_app_server_port(params)}" end
# File lib/lebowski/foundation/application.rb, line 445 def get_browser(params) client = get_selenium_client(params) return client.browser_string if (not client.nil?) browser = params[:browser] return browser if browser.kind_of?(String) case (browser) when :firefox return FIREFOX when :safari return SAFARI when :chrome return CHROME when :iexplorer return IEXPLORER when :iehta return IEHTA when :googlechrome return GOOGLECHROME else return DEFAULT_BROWSER end end
# File lib/lebowski/foundation/application.rb, line 403 def get_selenium_client(params) return params[:driver] end
# File lib/lebowski/foundation/application.rb, line 407 def get_selenium_server_host(params) client = get_selenium_client(params) return client.host if (not client.nil?) return DEFAULT_SELENIUM_SERVER_HOST if params[:selenium_server_host].nil? return params[:selenium_server_host] end
# File lib/lebowski/foundation/application.rb, line 414 def get_selenium_server_port(params) client = get_selenium_client(params) return client.port if (not client.nil?) return DEFAULT_SELENIUM_SERVER_PORT if params[:selenium_server_port].nil? return params[:selenium_server_port].to_i end
# File lib/lebowski/foundation/application.rb, line 439 def get_session_id(params) client = get_selenium_client(params) return client.session_id if (not client.nil?) return nil end
# File lib/lebowski/foundation/application.rb, line 479 def get_timeout_in_second(params) return DEFAULT_TIMEOUT_IN_SECONDS if params[:timeout_in_seconds].nil? return params[:timeout_in_seconds].to_i end