Class: TestCentricity::UIElement
- Includes:
- Capybara::DSL, Test::Unit::Assertions
- Defined in:
- lib/testcentricity_web/ui_elements_helper.rb,
lib/testcentricity_web/siebel_open_ui_helper.rb
Direct Known Subclasses
Button, CheckBox, FileField, Image, Label, Link, Radio, SelectList, Table, TextField
Instance Attribute Summary collapse
-
#alt_locator ⇒ Object
Returns the value of attribute alt_locator.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#locator ⇒ Object
readonly
Returns the value of attribute locator.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #clear_alt_locator ⇒ Object
-
#click ⇒ Object
Click on an object.
-
#click_at(x, y) ⇒ Object
Click at a specific location within an an object.
-
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?.
-
#double_click ⇒ Object
Double-click on an object.
- #drag_by(right_offset, down_offset) ⇒ Object
-
#enabled? ⇒ Boolean
Is UI object enabled?.
-
#exists?(visible = true) ⇒ Boolean
Does UI object exists?.
- #get_attribute(attrib) ⇒ Object
- #get_list_items(item_locator) ⇒ Object
- #get_locator ⇒ Object
- #get_native_attribute(attrib) ⇒ Object
- #get_object_type ⇒ Object
- #get_siebel_object_type ⇒ Object
- #get_value(visible = true) ⇒ Object
-
#hidden? ⇒ Boolean
Is UI object hidden (not visible)?.
-
#hover ⇒ Object
Hover the cursor over an object.
-
#initialize(parent, locator, context) ⇒ UIElement
constructor
A new instance of UIElement.
- #invoke_siebel_dialog(popup) ⇒ Object
-
#send_keys(*keys) ⇒ Object
comment_field.send_keys(:enter).
- #set(value) ⇒ Object
- #set_alt_locator(temp_locator) ⇒ Object
- #verify_value(expected, enqueue = false) ⇒ Object
-
#visible? ⇒ Boolean
Is UI object visible?.
-
#wait_until_exists(seconds = nil) ⇒ Object
Wait until the object exists, or until the specified wait time has expired.
-
#wait_until_gone(seconds = nil) ⇒ Object
Wait until the object no longer exists, or until the specified wait time has expired.
-
#wait_until_value_changes(seconds = nil) ⇒ Object
Wait until the object's value changes to a different value, or until the specified wait time has expired.
-
#wait_until_value_is(value, seconds = nil) ⇒ Object
Wait until the object's value equals the specified value, or until the specified wait time has expired.
-
#wait_until_visible(seconds = nil) ⇒ Object
Wait until the object is visible, or until the specified wait time has expired.
Constructor Details
#initialize(parent, locator, context) ⇒ UIElement
Returns a new instance of UIElement.
28 29 30 31 32 33 34 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 28 def initialize(parent, locator, context) @parent = parent @locator = locator @context = context @type = nil @alt_locator = nil end |
Instance Attribute Details
#alt_locator ⇒ Object
Returns the value of attribute alt_locator.
26 27 28 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 26 def alt_locator @alt_locator end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
25 26 27 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25 def context @context end |
#locator ⇒ Object (readonly)
Returns the value of attribute locator.
25 26 27 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25 def locator @locator end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
25 26 27 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25 def parent @parent end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25 def type @type end |
Instance Method Details
#clear_alt_locator ⇒ Object
54 55 56 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 54 def clear_alt_locator @alt_locator = nil end |
#click ⇒ Object
Click on an object
63 64 65 66 67 68 69 70 71 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 63 def click obj, _ = find_element object_not_found_exception(obj, nil) begin obj.click rescue obj.click_at(10, 10) unless Capybara.current_driver == :poltergeist end end |
#click_at(x, y) ⇒ Object
Click at a specific location within an an object
91 92 93 94 95 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 91 def click_at(x, y) obj, _ = find_element raise "Object #{@locator} not found" unless obj obj.click_at(x, y) end |
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?
180 181 182 183 184 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 180 def disabled? obj, _ = find_element object_not_found_exception(obj, nil) obj.disabled? end |
#double_click ⇒ Object
Double-click on an object
78 79 80 81 82 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 78 def double_click obj, _ = find_element object_not_found_exception(obj, nil) page.driver.browser.mouse.double_click(obj.native) end |
#drag_by(right_offset, down_offset) ⇒ Object
286 287 288 289 290 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 286 def drag_by(right_offset, down_offset) obj, _ = find_element object_not_found_exception(obj, nil) obj.drag_by(right_offset, down_offset) end |
#enabled? ⇒ Boolean
Is UI object enabled?
170 171 172 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 170 def enabled? not disabled? end |
#exists?(visible = true) ⇒ Boolean
Does UI object exists?
121 122 123 124 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 121 def exists?(visible = true) obj, _ = find_object(visible) obj != nil end |
#get_attribute(attrib) ⇒ Object
298 299 300 301 302 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 298 def get_attribute(attrib) obj, _ = find_element object_not_found_exception(obj, nil) obj[attrib] end |
#get_list_items(item_locator) ⇒ Object
292 293 294 295 296 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 292 def get_list_items(item_locator) obj, _ = find_element object_not_found_exception(obj, nil) obj.all(item_locator).collect(&:text) end |
#get_locator ⇒ Object
46 47 48 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 46 def get_locator @locator end |
#get_native_attribute(attrib) ⇒ Object
304 305 306 307 308 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 304 def get_native_attribute(attrib) obj, _ = find_element object_not_found_exception(obj, nil) obj.native.attribute(attrib) end |
#get_object_type ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 36 def get_object_type if @type @type elsif obj.tag_name obj.tag_name elsif obj.native.attribute('type') obj.native.attribute('type') end end |
#get_siebel_object_type ⇒ Object
8 9 10 11 12 |
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 8 def get_siebel_object_type obj, _ = find_element object_not_found_exception(obj, 'Siebel object') obj.native.attribute('ot') end |
#get_value(visible = true) ⇒ Object
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 257 def get_value(visible = true) obj, _ = find_element(visible) object_not_found_exception(obj, nil) case obj.tag_name.downcase when 'input', 'select', 'textarea' obj.value else obj.text end end |
#hidden? ⇒ Boolean
Is UI object hidden (not visible)?
160 161 162 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 160 def hidden? not visible? end |
#hover ⇒ Object
Hover the cursor over an object
280 281 282 283 284 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 280 def hover obj, _ = find_element object_not_found_exception(obj, nil) obj.hover end |
#invoke_siebel_dialog(popup) ⇒ Object
3 4 5 6 |
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 3 def invoke_siebel_dialog(popup) invoke_siebel_popup popup.wait_until_exists(15) end |
#send_keys(*keys) ⇒ Object
comment_field.send_keys(:enter)
109 110 111 112 113 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 109 def send_keys(*keys) obj, _ = find_element object_not_found_exception(obj, nil) obj.send_keys(*keys) end |
#set(value) ⇒ Object
97 98 99 100 101 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 97 def set(value) obj, _ = find_element object_not_found_exception(obj, nil) obj.set(value) end |
#set_alt_locator(temp_locator) ⇒ Object
50 51 52 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 50 def set_alt_locator(temp_locator) @alt_locator = temp_locator end |
#verify_value(expected, enqueue = false) ⇒ Object
268 269 270 271 272 273 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 268 def verify_value(expected, enqueue = false) actual = get_value enqueue ? ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected #{@locator}") : assert_equal(expected.strip, actual.strip, "Expected #{@locator} to display '#{expected}' but found '#{actual}'") end |
#visible? ⇒ Boolean
Is UI object visible?
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 132 def visible? obj, type = find_object exists = obj invisible = false if type == :css Capybara.using_wait_time 0.1 do # is object itself hidden with .ui-helper-hidden class? self_hidden = page.has_css?("#{@locator}.ui-helper-hidden") # is parent of object hidden, thus hiding the object? parent_hidden = page.has_css?(".ui-helper-hidden > #{@locator}") # is grandparent of object, or any other ancestor, hidden? other_ancestor_hidden = page.has_css?(".ui-helper-hidden * #{@locator}") # if any of the above conditions are true, then object is invisible invisible = self_hidden || parent_hidden || other_ancestor_hidden end else invisible = !obj.visible? if exists end # the object is visible if it exists and it is not invisible (exists && !invisible) ? true : false end |
#wait_until_exists(seconds = nil) ⇒ Object
Wait until the object exists, or until the specified wait time has expired.
192 193 194 195 196 197 198 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 192 def wait_until_exists(seconds = nil) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { exists? } rescue raise "Could not find element #{@locator} after #{timeout} seconds" unless exists? end |
#wait_until_gone(seconds = nil) ⇒ Object
Wait until the object no longer exists, or until the specified wait time has expired.
220 221 222 223 224 225 226 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 220 def wait_until_gone(seconds = nil) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { !exists? } rescue raise "Element #{@locator} remained visible after #{timeout} seconds" if exists? end |
#wait_until_value_changes(seconds = nil) ⇒ Object
Wait until the object's value changes to a different value, or until the specified wait time has expired.
248 249 250 251 252 253 254 255 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 248 def wait_until_value_changes(seconds = nil) value = get_value timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { get_value != value } rescue raise "Value of UI element #{@locator} failed to change from '#{value}' after #{timeout} seconds" if get_value == value end |
#wait_until_value_is(value, seconds = nil) ⇒ Object
Wait until the object's value equals the specified value, or until the specified wait time has expired.
234 235 236 237 238 239 240 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 234 def wait_until_value_is(value, seconds = nil) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { get_value == value } rescue raise "Value of UI element #{@locator} failed to equal '#{value}' after #{timeout} seconds" unless get_value == value end |
#wait_until_visible(seconds = nil) ⇒ Object
Wait until the object is visible, or until the specified wait time has expired.
206 207 208 209 210 211 212 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 206 def wait_until_visible(seconds = nil) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { visible? } rescue raise "Could not find element #{@locator} after #{timeout} seconds" unless exists? end |