Class: Kookaburra::UIDriver::UIComponent Abstract
- Inherits:
-
Object
- Object
- Kookaburra::UIDriver::UIComponent
- Extended by:
- HasUIComponents
- Includes:
- Assertion
- Defined in:
- lib/kookaburra/ui_driver/ui_component.rb,
lib/kookaburra/ui_driver/ui_component/address_bar.rb
Overview
Subclass and implement (at least) #component_locator. Unless you override the default implementation of #url, you must also override the #component_path method.
UIComponent is intended to be subclassed to represent each component of your application-under-test's user interface. The purpose of the UIComponent object is to abstract away the implementation details of your interface when testing and allow you to concentrate on testing your business requirements. For instance, a UIComponent subclass for your sign-up form might have accessors for the individual fields as well as methods that allow you to perform distinct operations:
Note that the "browser operation" methods such as #fill_in
and
#click_button
are forwarded to the #browser object (see
#method_missing) and are automatically scoped to the component's DOM
element.
Direct Known Subclasses
Defined Under Namespace
Classes: AddressBar
Instance Attribute Summary collapse
-
#browser ⇒ Object
readonly
protected
The browser object from the initialized configuration.
-
#configuration ⇒ Object
readonly
The Configuration with which the component instance was instantiated.
-
#options ⇒ Object
readonly
The options Hash with which the component instance was instantiated.
Instance Method Summary collapse
-
#component_locator ⇒ String
protected
abstract
The CSS3 selector that will find the element in the DOM.
-
#component_path ⇒ String
protected
abstract
The URL path that should be loaded in order to reach this component.
-
#detect_server_error! ⇒ Object
protected
Runs the server error detection function specified in Configuration#server_error_detection.
-
#initialize(configuration, options = {}) ⇒ UIComponent
constructor
New UIComponent instances are typically created for you by your Kookaburra::UIDriver instance.
-
#method_missing(name, *args, &block) ⇒ Object
If the UIComponent is sent a message it does not understand, it will forward that message on to its #browser but wrap the call in a block provided to the the browser's
#within
method. -
#url(*args) ⇒ Object
Returns the full URL by appending #component_path to the value of the Configuration#app_host from the initialized configuration.
-
#visible? ⇒ Boolean
Is the component's element found on the page and is it considered "visible" by the browser driver.
Methods included from HasUIComponents
Methods included from Assertion
Constructor Details
#initialize(configuration, options = {}) ⇒ UIComponent
New UIComponent instances are typically created for you by your Kookaburra::UIDriver instance.
89 90 91 92 93 94 95 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 89 def initialize(configuration, = {}) @configuration = configuration @options = @browser = configuration.browser @app_host = configuration.app_host @server_error_detection = configuration.server_error_detection end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
If the UIComponent is sent a message it does not understand, it will
forward that message on to its #browser but wrap the call in a block
provided to the the browser's #within
method. This provides convenient
access to the browser driver's DSL, automatically scoped to this
component.
102 103 104 105 106 107 108 109 110 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 102 def method_missing(name, *args, &block) if respond_to?(name) browser.within(component_locator) do browser.send(name, *args, &block) end else super end end |
Instance Attribute Details
#browser ⇒ Object (readonly, protected)
The browser object from the initialized configuration
138 139 140 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 138 def browser @browser end |
#configuration ⇒ Object (readonly)
The Configuration with which the component instance was instantiated.
75 76 77 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 75 def configuration @configuration end |
#options ⇒ Object (readonly)
The options Hash with which the component instance was instantiated.
79 80 81 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 79 def @options end |
Instance Method Details
#component_locator ⇒ String (protected)
Returns the CSS3 selector that will find the element in the DOM.
152 153 154 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 152 def component_locator raise ConfigurationError, "You must define #{self.class.name}#component_locator." end |
#component_path ⇒ String (protected)
Returns the URL path that should be loaded in order to reach this component.
144 145 146 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 144 def component_path raise ConfigurationError, "You must define #{self.class.name}#component_path." end |
#detect_server_error! ⇒ Object (protected)
Runs the server error detection function specified in Configuration#server_error_detection.
It's a noop if no server error detection was specified.
163 164 165 166 167 168 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 163 def detect_server_error! return if @server_error_detection.nil? if @server_error_detection.call(browser) raise UnexpectedResponse, "Your server error detection function detected a server error. Looks like your applications is busted. :-(" end end |
#url(*args) ⇒ Object
Returns the full URL by appending #component_path to the value of the Configuration#app_host from the initialized configuration.
131 132 133 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 131 def url(*args) "#{@app_host}#{component_path(*args)}" end |
#visible? ⇒ Boolean
Is the component's element found on the page and is it considered "visible" by the browser driver.
121 122 123 124 125 126 127 |
# File 'lib/kookaburra/ui_driver/ui_component.rb', line 121 def visible? visible = browser.has_css?(component_locator, :visible) unless visible detect_server_error! end visible end |