Class: TestCentricity::ScreenSection
- Inherits:
-
BaseScreenSectionObject
- Object
- BaseScreenSectionObject
- TestCentricity::ScreenSection
- Includes:
- Test::Unit::Assertions
- Defined in:
- lib/testcentricity_apps/app_core/screen_section.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#list_index ⇒ Object
Returns the value of attribute list_index.
-
#locator ⇒ Object
Returns the value of attribute locator.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#parent_list ⇒ Object
Returns the value of attribute parent_list.
Class Method Summary collapse
-
.button(element_name, locator) ⇒ Object
Declare and instantiate a single button UI Element for this screen section object.
-
.buttons(element_hash) ⇒ Object
Declare and instantiate a collection of buttons for this screen section object.
-
.checkbox(element_name, locator) ⇒ Object
Declare and instantiate a single checkbox UI Element for this screen section object.
-
.checkboxes(element_hash) ⇒ Object
Declare and instantiate a collection of checkboxes for this screen section object.
-
.element(element_name, locator) ⇒ Object
Declare and instantiate a single generic UI Element for this screen section object.
-
.elements(element_hash) ⇒ Object
Declare and instantiate a collection of generic UI Elements for this screen section object.
-
.image(element_name, locator) ⇒ Object
Declare and instantiate a single image UI Element for this screen section object.
-
.images(element_hash) ⇒ Object
Declare and instantiate a collection of images for this screen section object.
-
.label(element_name, locator) ⇒ Object
Declare and instantiate a single label UI Element for this screen section object.
-
.labels(element_hash) ⇒ Object
Declare and instantiate a collection of labels for this screen section object.
-
.list(element_name, locator) ⇒ Object
Declare and instantiate a single list UI Element for this screen section object.
-
.lists(element_hash) ⇒ Object
Declare and instantiate a collection of lists for this screen section object.
-
.radio(element_name, locator) ⇒ Object
Declare and instantiate a single radio button UI Element for this screen section object.
-
.radios(element_hash) ⇒ Object
Declare and instantiate a collection of radio buttons for this screen section object.
-
.section(section_name, obj, locator = 0) ⇒ Object
Instantiate a single ScreenSection object within this ScreenSection object.
-
.sections(section_hash) ⇒ Object
Declare and instantiate a collection of ScreenSection objects for this ScreenSection object.
-
.selectlist(element_name, locator) ⇒ Object
Declare and instantiate a single selectlist UI Element for this screen section object.
-
.selectlists(element_hash) ⇒ Object
Declare and instantiate a collection of selectlists for this screen section object.
-
.switch(element_name, locator) ⇒ Object
Declare and instantiate a single switch UI Element for this screen section object.
-
.switches(element_hash) ⇒ Object
Declare and instantiate a collection of switches for this screen section object.
-
.textfield(element_name, locator) ⇒ Object
Declare and instantiate a single textfield UI Element for this screen section object.
-
.textfields(element_hash) ⇒ Object
Declare and instantiate a collection of textfields for this screen section object.
Instance Method Summary collapse
-
#click ⇒ Object
Click on a screen Section object.
-
#disabled? ⇒ Boolean
Is screen Section object disabled (not enabled)?.
-
#double_tap ⇒ Object
Double-tap on a screen Section object.
-
#enabled? ⇒ Boolean
Is screen Section object enabled?.
-
#exists? ⇒ Boolean
Does screen Section object exists?.
- #get_item_count ⇒ Object
- #get_list_items ⇒ Object
- #get_locator ⇒ Object
- #get_name ⇒ Object
- #get_object_type ⇒ Object
-
#height ⇒ Integer
Return height of screen Section object.
-
#hidden? ⇒ Boolean
Is screen Section object hidden (not visible)?.
- #identifier ⇒ Object
-
#initialize(name, parent, locator, context) ⇒ ScreenSection
constructor
A new instance of ScreenSection.
-
#long_press(duration = 1) ⇒ Object
Long press on a screen Section object.
-
#scroll_into_view(scroll_mode = :vertical) ⇒ Object
Scroll the screen Section object until it is visible.
-
#send_keys(value) ⇒ Object
Send keystrokes to this section object.
- #set_list_index(list, index = 1) ⇒ Object
- #set_parent(parent) ⇒ Object
-
#tap ⇒ Object
Tap on a screen Section object.
-
#visible? ⇒ Boolean
Is screen Section object visible?.
-
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object exists, or until the specified wait time has expired.
-
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object no longer exists, or until the specified wait time has expired.
-
#wait_until_hidden(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object is hidden, or until the specified wait time has expired.
-
#wait_until_visible(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object is visible, or until the specified wait time has expired.
-
#width ⇒ Integer
Return width of screen Section object.
-
#x_loc ⇒ Integer
Return x coordinate of screen Section object's location.
-
#y_loc ⇒ Integer
Return y coordinate of screen Section object's location.
Methods inherited from BaseScreenSectionObject
#populate_data_fields, #swipe_gesture, trait, #verify_ui_states
Constructor Details
#initialize(name, parent, locator, context) ⇒ ScreenSection
Returns a new instance of ScreenSection.
13 14 15 16 17 18 19 20 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 13 def initialize(name, parent, locator, context) @name = name @parent = parent @locator = locator @context = context @parent_list = nil @list_index = nil end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
7 8 9 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 7 def context @context end |
#list_index ⇒ Object
Returns the value of attribute list_index.
11 12 13 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 11 def list_index @list_index end |
#locator ⇒ Object
Returns the value of attribute locator.
8 9 10 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 8 def locator @locator end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 7 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
9 10 11 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 9 def parent @parent end |
#parent_list ⇒ Object
Returns the value of attribute parent_list.
10 11 12 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 10 def parent_list @parent_list end |
Class Method Details
.button(element_name, locator) ⇒ Object
Declare and instantiate a single button UI Element for this screen section object.
125 126 127 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 125 def self.(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppButton, locator) end |
.buttons(element_hash) ⇒ Object
Declare and instantiate a collection of buttons for this screen section object.
138 139 140 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 138 def self.(element_hash) element_hash.each_pair { |element_name, locator| (element_name, locator) } end |
.checkbox(element_name, locator) ⇒ Object
Declare and instantiate a single checkbox UI Element for this screen section object.
194 195 196 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 194 def self.checkbox(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppCheckBox, locator) end |
.checkboxes(element_hash) ⇒ Object
Declare and instantiate a collection of checkboxes for this screen section object.
205 206 207 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 205 def self.checkboxes(element_hash) element_hash.each_pair { |element_name, locator| checkbox(element_name, locator) } end |
.element(element_name, locator) ⇒ Object
Declare and instantiate a single generic UI Element for this screen section object.
- The locator_identifier (a String) is the value or attribute that uniquely and unambiguously identifies the UI element.
102 103 104 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 102 def self.element(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppUIElement, locator) end |
.elements(element_hash) ⇒ Object
Declare and instantiate a collection of generic UI Elements for this screen section object.
114 115 116 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 114 def self.elements(element_hash) element_hash.each_pair { |element_name, locator| element(element_name, locator) } end |
.image(element_name, locator) ⇒ Object
Declare and instantiate a single image UI Element for this screen section object.
304 305 306 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 304 def self.image(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppImage, locator) end |
.images(element_hash) ⇒ Object
Declare and instantiate a collection of images for this screen section object.
315 316 317 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 315 def self.images(element_hash) element_hash.each_pair { |element_name, locator| image(element_name, locator) } end |
.label(element_name, locator) ⇒ Object
Declare and instantiate a single label UI Element for this screen section object.
238 239 240 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 238 def self.label(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppLabel, locator) end |
.labels(element_hash) ⇒ Object
Declare and instantiate a collection of labels for this screen section object.
249 250 251 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 249 def self.labels(element_hash) element_hash.each_pair { |element_name, locator| label(element_name, locator) } end |
.list(element_name, locator) ⇒ Object
Declare and instantiate a single list UI Element for this screen section object.
260 261 262 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 260 def self.list(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppList, locator) end |
.lists(element_hash) ⇒ Object
Declare and instantiate a collection of lists for this screen section object.
271 272 273 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 271 def self.lists(element_hash) element_hash.each_pair { |element_name, locator| list(element_name, locator) } end |
.radio(element_name, locator) ⇒ Object
Declare and instantiate a single radio button UI Element for this screen section object.
216 217 218 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 216 def self.radio(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppRadio, locator) end |
.radios(element_hash) ⇒ Object
Declare and instantiate a collection of radio buttons for this screen section object.
227 228 229 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 227 def self.radios(element_hash) element_hash.each_pair { |element_name, locator| radio(element_name, locator) } end |
.section(section_name, obj, locator = 0) ⇒ Object
Instantiate a single ScreenSection object within this ScreenSection object.
326 327 328 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 326 def self.section(section_name, obj, locator = 0) define_section_element(section_name, obj, locator) end |
.sections(section_hash) ⇒ Object
Declare and instantiate a collection of ScreenSection objects for this ScreenSection object.
337 338 339 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 337 def self.sections(section_hash) section_hash.each_pair { |section_name, class_name| section(section_name, class_name) } end |
.selectlist(element_name, locator) ⇒ Object
Declare and instantiate a single selectlist UI Element for this screen section object.
282 283 284 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 282 def self.selectlist(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppSelectList, locator) end |
.selectlists(element_hash) ⇒ Object
Declare and instantiate a collection of selectlists for this screen section object.
293 294 295 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 293 def self.selectlists(element_hash) element_hash.each_pair { |element_name, locator| selectlist(element_name, locator) } end |
.switch(element_name, locator) ⇒ Object
Declare and instantiate a single switch UI Element for this screen section object.
172 173 174 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 172 def self.switch(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppSwitch, locator) end |
.switches(element_hash) ⇒ Object
Declare and instantiate a collection of switches for this screen section object.
183 184 185 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 183 def self.switches(element_hash) element_hash.each_pair { |element_name, locator| switch(element_name, locator) } end |
.textfield(element_name, locator) ⇒ Object
Declare and instantiate a single textfield UI Element for this screen section object.
150 151 152 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 150 def self.textfield(element_name, locator) define_section_element(element_name, TestCentricity::AppElements::AppTextField, locator) end |
.textfields(element_hash) ⇒ Object
Declare and instantiate a collection of textfields for this screen section object.
161 162 163 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 161 def self.textfields(element_hash) element_hash.each_pair { |element_name, locator| textfield(element_name, locator) } end |
Instance Method Details
#click ⇒ Object
Click on a screen Section object
346 347 348 349 350 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 346 def click section = find_section section_not_found_exception(section) section.click end |
#disabled? ⇒ Boolean
Is screen Section object disabled (not enabled)?
466 467 468 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 466 def disabled? !enabled? end |
#double_tap ⇒ Object
Double-tap on a screen Section object
371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 371 def double_tap section = find_section section_not_found_exception(section) driver.action .click_and_hold(section) .release .pause(duration: 0.2) .click_and_hold(section) .release .perform end |
#enabled? ⇒ Boolean
Is screen Section object enabled?
454 455 456 457 458 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 454 def enabled? section = find_section section_not_found_exception(section) section.enabled? end |
#exists? ⇒ Boolean
Does screen Section object exists?
443 444 445 446 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 443 def exists? section = find_section section != nil end |
#get_item_count ⇒ Object
59 60 61 62 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 59 def get_item_count raise 'No parent list defined' if @parent_list.nil? @parent_list.get_item_count end |
#get_list_items ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 64 def get_list_items items = [] (1..get_item_count).each do |item| set_list_index(nil, item) begin items.push(get_value) rescue scroll_into_view(@parent_list.scroll_mode) items.push(get_value) end end items end |
#get_locator ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 22 def get_locator my_locator = if @locator.zero? && defined?(section_locator) section_locator else @locator end locators = [] if @context == :section && !@parent.nil? locators = @parent.get_locator end if @parent_list.nil? locators.push(my_locator) else locators.push(@parent_list.get_locator) if @list_index.nil? locators.push(my_locator) else item_objects = @parent_list.item_refs if item_objects.nil? list_key = my_locator.keys[0] list_value = "#{my_locator.values[0]}[#{@list_index}]" else list_key = :object list_value = item_objects[@list_index - 1] end locators.push( { list_key => list_value } ) end end locators end |
#get_name ⇒ Object
82 83 84 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 82 def get_name @name end |
#get_object_type ⇒ Object
78 79 80 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 78 def get_object_type :section end |
#height ⇒ Integer
Return height of screen Section object.
608 609 610 611 612 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 608 def height section = find_section section_not_found_exception(section) section.size.height end |
#hidden? ⇒ Boolean
Is screen Section object hidden (not visible)?
488 489 490 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 488 def hidden? !visible? end |
#identifier ⇒ Object
492 493 494 495 496 497 498 499 500 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 492 def identifier if Environ.is_macos? section = find_section section_not_found_exception(section) section.identifier else raise 'identifier is not a supported attribute' end end |
#long_press(duration = 1) ⇒ Object
Long press on a screen Section object
389 390 391 392 393 394 395 396 397 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 389 def long_press(duration = 1) section = find_section section_not_found_exception(section) driver.action .click_and_hold(section) .pause(duration: duration) .release .perform end |
#scroll_into_view(scroll_mode = :vertical) ⇒ Object
Scroll the screen Section object until it is visible. If scroll_mode is not specified, then vertical scrolling will be used.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 406 def scroll_into_view(scroll_mode = :vertical) return if visible? obj = element object_not_found_exception(obj) driver.action.move_to(obj).perform case scroll_mode when :vertical start_direction = :down end_direction = :up when :horizontal start_direction = :right end_direction = :left else raise "#{scroll_mode} is not a valid selector" end try_count = 8 direction = start_direction while hidden? swipe_gesture(direction, distance = 0.2) try_count -= 1 if try_count.zero? if direction == end_direction break else direction = end_direction try_count = 8 end end end end |
#send_keys(value) ⇒ Object
Send keystrokes to this section object.
508 509 510 511 512 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 508 def send_keys(value) section = find_section section_not_found_exception(section) section.send_keys(value) end |
#set_list_index(list, index = 1) ⇒ Object
54 55 56 57 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 54 def set_list_index(list, index = 1) @parent_list = list unless list.nil? @list_index = index end |
#set_parent(parent) ⇒ Object
86 87 88 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 86 def set_parent(parent) @parent = parent end |
#tap ⇒ Object
Tap on a screen Section object
357 358 359 360 361 362 363 364 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 357 def tap section = find_section section_not_found_exception(section) driver.action .click_and_hold(section) .release .perform end |
#visible? ⇒ Boolean
Is screen Section object visible?
476 477 478 479 480 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 476 def visible? section = find_section return false if section.nil? section.displayed? end |
#wait_until_exists(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object exists, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Environ.default_max_wait_time.
521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 521 def wait_until_exists(seconds = nil, post_exception = true) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { exists? } rescue if post_exception raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless exists? else exists? end end |
#wait_until_gone(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object no longer exists, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Environ.default_max_wait_time.
540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 540 def wait_until_gone(seconds = nil, post_exception = true) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { !exists? } rescue if post_exception raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if exists? else exists? end end |
#wait_until_hidden(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object is hidden, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Environ.default_max_wait_time.
578 579 580 581 582 583 584 585 586 587 588 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 578 def wait_until_hidden(seconds = nil, post_exception = true) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { hidden? } rescue if post_exception raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if visible? else visible? end end |
#wait_until_visible(seconds = nil, post_exception = true) ⇒ Object
Wait until the screen Section object is visible, or until the specified wait time has expired. If the wait time is nil, then the wait time will be Environ.default_max_wait_time.
559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 559 def wait_until_visible(seconds = nil, post_exception = true) timeout = seconds.nil? ? Environ.default_max_wait_time : seconds wait = Selenium::WebDriver::Wait.new(timeout: timeout) wait.until { visible? } rescue if post_exception raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless visible? else visible? end end |
#width ⇒ Integer
Return width of screen Section object.
596 597 598 599 600 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 596 def width section = find_section section_not_found_exception(section) section.size.width end |
#x_loc ⇒ Integer
Return x coordinate of screen Section object's location.
620 621 622 623 624 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 620 def x_loc section = find_section section_not_found_exception(section) section.location.x end |
#y_loc ⇒ Integer
Return y coordinate of screen Section object's location.
632 633 634 635 636 |
# File 'lib/testcentricity_apps/app_core/screen_section.rb', line 632 def y_loc section = find_section section_not_found_exception(section) section.location.y end |