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, CellElement, CheckBox, FileField, Image, Label, Link, List, 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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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 object.
-
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?.
-
#double_click ⇒ Object
Double-click on an object.
- #drag_and_drop(target, right_offset = nil, down_offset = nil) ⇒ 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_locator ⇒ Object
- #get_name ⇒ Object
- #get_native_attribute(attrib) ⇒ Object
- #get_object_type ⇒ Object
- #get_siebel_object_type ⇒ Object
- #get_value(visible = true) ⇒ Object (also: #get_caption)
-
#hidden? ⇒ Boolean
Is UI object hidden (not visible)?.
-
#hover ⇒ Object
Hover the cursor over an object.
-
#initialize(name, parent, locator, context) ⇒ UIElement
constructor
A new instance of UIElement.
- #invoke_siebel_dialog(popup, seconds = nil) ⇒ Object
-
#right_click ⇒ Object
Right-click on an 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 (also: #verify_caption)
-
#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_hidden(seconds = nil) ⇒ Object
Wait until the object is hidden, 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(name, parent, locator, context) ⇒ UIElement
Returns a new instance of UIElement.
28 29 30 31 32 33 34 35 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 28 def initialize(name, parent, locator, context) @name = name @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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 25 def name @name 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
59 60 61 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 59 def clear_alt_locator @alt_locator = nil end |
#click ⇒ Object
Click on an object
68 69 70 71 72 73 74 75 76 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 68 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 object
107 108 109 110 111 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 107 def click_at(x, y) obj, = find_element raise "UI #{} not found" unless obj obj.click_at(x, y) end |
#disabled? ⇒ Boolean
Is UI object disabled (not enabled)?
196 197 198 199 200 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 196 def disabled? obj, = find_element object_not_found_exception(obj, nil) obj.disabled? end |
#double_click ⇒ Object
Double-click on an object
83 84 85 86 87 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 83 def double_click obj, = find_element object_not_found_exception(obj, nil) page.driver.browser.action.double_click(obj.native).perform end |
#drag_and_drop(target, right_offset = nil, down_offset = nil) ⇒ Object
326 327 328 329 330 331 332 333 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 326 def drag_and_drop(target, right_offset = nil, down_offset = nil) source, = find_element object_not_found_exception(source, nil) page.driver.browser.action.click_and_hold(source.native).perform sleep(0.5) target_drop, = target.find_element page.driver.browser.action.move_to(target_drop.native, right_offset.to_i, down_offset.to_i).release.perform end |
#drag_by(right_offset, down_offset) ⇒ Object
320 321 322 323 324 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 320 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?
186 187 188 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 186 def enabled? !disabled? end |
#exists?(visible = true) ⇒ Boolean
Does UI object exists?
137 138 139 140 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 137 def exists?(visible = true) obj, = find_object(visible) obj != nil end |
#get_attribute(attrib) ⇒ Object
335 336 337 338 339 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 335 def get_attribute(attrib) obj, = find_element object_not_found_exception(obj, nil) obj[attrib] end |
#get_locator ⇒ Object
47 48 49 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 47 def get_locator @locator end |
#get_name ⇒ Object
51 52 53 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 51 def get_name @name end |
#get_native_attribute(attrib) ⇒ Object
341 342 343 344 345 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 341 def get_native_attribute(attrib) obj, = find_element object_not_found_exception(obj, nil) obj.native.attribute(attrib) end |
#get_object_type ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 37 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
9 10 11 12 13 |
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 9 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 Also known as:
287 288 289 290 291 292 293 294 295 296 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 287 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)?
176 177 178 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 176 def hidden? !visible? end |
#hover ⇒ Object
Hover the cursor over an object
314 315 316 317 318 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 314 def hover obj, = find_element object_not_found_exception(obj, nil) obj.hover end |
#invoke_siebel_dialog(popup, seconds = nil) ⇒ Object
3 4 5 6 7 |
# File 'lib/testcentricity_web/siebel_open_ui_helper.rb', line 3 def invoke_siebel_dialog(popup, seconds = nil) invoke_siebel_popup timeout = seconds.nil? ? 15 : seconds popup.wait_until_exists(timeout) end |
#right_click ⇒ Object
Right-click on an object
94 95 96 97 98 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 94 def right_click obj, = find_element object_not_found_exception(obj, nil) page.driver.browser.action.context_click(obj.native).perform end |
#send_keys(*keys) ⇒ Object
comment_field.send_keys(:enter)
125 126 127 128 129 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 125 def send_keys(*keys) obj, = find_element object_not_found_exception(obj, nil) obj.send_keys(*keys) end |
#set(value) ⇒ Object
113 114 115 116 117 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 113 def set(value) obj, = find_element object_not_found_exception(obj, nil) obj.set(value) end |
#set_alt_locator(temp_locator) ⇒ Object
55 56 57 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 55 def set_alt_locator(temp_locator) @alt_locator = temp_locator end |
#verify_value(expected, enqueue = false) ⇒ Object Also known as:
300 301 302 303 304 305 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 300 def verify_value(expected, enqueue = false) actual = get_value enqueue ? ExceptionQueue.enqueue_assert_equal(expected.strip, actual.strip, "Expected UI #{}") : assert_equal(expected.strip, actual.strip, "Expected UI #{} to display '#{expected}' but found '#{actual}'") end |
#visible? ⇒ Boolean
Is UI object visible?
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 148 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.
208 209 210 211 212 213 214 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 208 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 UI #{} 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.
222 223 224 225 226 227 228 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 222 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 "UI #{} remained visible after #{timeout} seconds" if exists? end |
#wait_until_hidden(seconds = nil) ⇒ Object
Wait until the object is hidden, or until the specified wait time has expired.
250 251 252 253 254 255 256 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 250 def wait_until_hidden(seconds = nil) timeout = seconds.nil? ? Capybara.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { hidden? } rescue raise "UI #{} remained visible after #{timeout} seconds" if visible? 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.
278 279 280 281 282 283 284 285 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 278 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 #{} 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.
264 265 266 267 268 269 270 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 264 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 #{} 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.
236 237 238 239 240 241 242 |
# File 'lib/testcentricity_web/ui_elements_helper.rb', line 236 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 UI #{} after #{timeout} seconds" unless visible? end |