class TestCentricity::ScreenSection

Attributes

context[R]
list_index[RW]
locator[RW]
name[R]
parent[RW]
parent_list[RW]

Public Class Methods

alert(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 173
def self.alert(element_name, locator)
  define_method(element_name) do
    ivar_name = "@#{element_name}"
    ivar = instance_variable_get(ivar_name)
    return ivar if ivar
    instance_variable_set(ivar_name, TestCentricity::AppAlert.new(element_name, self, locator, :page))
  end
end
button(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 93
def self.button(element_name, locator)
  define_element(element_name, TestCentricity::AppButton, locator)
end
buttons(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 97
def self.buttons(element_hash)
  element_hash.each do |element_name, locator|
    button(element_name, locator)
  end
end
checkbox(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 123
def self.checkbox(element_name, locator)
  define_element(element_name, TestCentricity::AppCheckBox, locator)
end
checkboxes(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 127
def self.checkboxes(element_hash)
  element_hash.each do |element_name, locator|
    checkbox(element_name, locator)
  end
end
element(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 83
def self.element(element_name, locator)
  define_element(element_name, TestCentricity::AppUIElement, locator)
end
elements(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 87
def self.elements(element_hash)
  element_hash.each do |element_name, locator|
    element(element_name, locator)
  end
end
image(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 163
def self.image(element_name, locator)
  define_element(element_name, TestCentricity::AppImage, locator)
end
images(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 167
def self.images(element_hash)
  element_hash.each do |element_name, locator|
    image(element_name, locator)
  end
end
label(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 133
def self.label(element_name, locator)
  define_element(element_name, TestCentricity::AppLabel, locator)
end
labels(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 137
def self.labels(element_hash)
  element_hash.each do |element_name, locator|
    label(element_name, locator)
  end
end
list(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 143
def self.list(element_name, locator)
  define_element(element_name, TestCentricity::AppList, locator)
end
lists(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 147
def self.lists(element_hash)
  element_hash.each do |element_name, locator|
    list(element_name, locator)
  end
end
new(name, parent, locator, context) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 13
def initialize(name, parent, locator, context)
  @name        = name
  @parent      = parent
  @locator     = locator
  @context     = context
  @parent_list = nil
  @list_index  = nil
end
section(section_name, obj, locator = 0) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 182
def self.section(section_name, obj, locator = 0)
  define_element(section_name, obj, locator)
end
sections(section_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 186
def self.sections(section_hash)
  section_hash.each do |section_name, class_name|
    section(section_name, class_name)
  end
end
selectlist(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 153
def self.selectlist(element_name, locator)
  define_element(element_name, TestCentricity::AppSelectList, locator)
end
selectlists(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 157
def self.selectlists(element_hash)
  element_hash.each do |element_name, locator|
    selectlist(element_name, locator)
  end
end
switch(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 113
def self.switch(element_name, locator)
  define_element(element_name, TestCentricity::AppSwitch, locator)
end
switches(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 117
def self.switches(element_hash)
  element_hash.each do |element_name, locator|
    switch(element_name, locator)
  end
end
textfield(element_name, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 103
def self.textfield(element_name, locator)
  define_element(element_name, TestCentricity::AppTextField, locator)
end
textfields(element_hash) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 107
def self.textfields(element_hash)
  element_hash.each do |element_name, locator|
    textfield(element_name, locator)
  end
end
trait(trait_name, &block) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 79
def self.trait(trait_name, &block)
  define_method(trait_name.to_s, &block)
end

Private Class Methods

define_element(element_name, obj, locator) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 406
def self.define_element(element_name, obj, locator)
  define_method(element_name) do
    ivar_name = "@#{element_name}"
    ivar = instance_variable_get(ivar_name)
    return ivar if ivar
    instance_variable_set(ivar_name, obj.new(element_name, self, locator, :section))
  end
end

Public Instance Methods

click() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 193
def click
  section = find_section
  section_not_found_exception(section)
  section.click
end
disabled?() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 228
def disabled?
  section = find_section
  section_not_found_exception(section)
  section.enabled?
end
double_tap() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 208
def double_tap
  section = find_section
  section_not_found_exception(section)
  x = section.location.x
  y = section.location.y
  tap_action = Appium::TouchAction.new.double_tap(element: section, x: x, y: y)
  tap_action.perform
end
enabled?() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 222
def enabled?
  section = find_section
  section_not_found_exception(section)
  section.enabled?
end
exists?() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 217
def exists?
  section = find_section
  section != nil
end
get_item_count() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 53
def get_item_count
  raise 'No parent list defined' if @parent_list.nil?
  @parent_list.get_item_count
end
get_list_items() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 58
def get_list_items
  items = []
  (1..get_item_count).each do |item|
    set_list_index(nil, item)
    items.push(get_value)
  end
  items
end
get_locator() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 22
def get_locator
  if @locator.zero? && defined?(section_locator)
    my_locator = section_locator
  else
    my_locator = @locator
  end
  locators = []
  if @context == :section && !@parent.nil?
    locators.push(@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
      list_key = my_locator.keys[0]
      list_value = "#{my_locator.values[0]}[#{@list_index}]"
      locators.push( { list_key => list_value } )
    end
  end
  locators
end
get_name() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 71
def get_name
  @name
end
get_object_type() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 67
def get_object_type
  :section
end
height() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 285
def height
  section = find_section
  section_not_found_exception(section)
  section.size.height
end
hidden?() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 242
def hidden?
  !visible?
end
populate_data_fields(data, wait_time = nil) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 362
def populate_data_fields(data, wait_time = nil)
  timeout = wait_time.nil? ? 5 : wait_time
  data.each do |data_field, data_param|
    unless data_param.blank?
      # make sure the intended UI target element is visible before trying to set its value
      data_field.wait_until_visible(timeout)
      if data_param == '!DELETE'
        data_field.clear
      else
        case data_field.get_object_type
        when :checkbox
          data_field.set_checkbox_state(data_param.to_bool)
        when :textfield
          data_field.clear
          data_field.set("#{data_param}\t")
        end
      end
    end
  end
end
set_list_index(list, index = 1) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 48
def set_list_index(list, index = 1)
  @parent_list = list unless list.nil?
  @list_index  = index
end
set_parent(parent) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 75
def set_parent(parent)
  @parent = parent
end
tap() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 199
def tap
  section = find_section
  section_not_found_exception(section)
  x = section.location.x
  y = section.location.y
  tap_action = Appium::TouchAction.new.tap(element: section, x: x, y: y)
  tap_action.perform
end
verify_ui_states(ui_states) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 304
def verify_ui_states(ui_states)
  ui_states.each do |ui_object, object_states|
    object_states.each do |property, state|

      puts "#{ui_object.get_name} - #{property} = #{state}" if ENV['DEBUG']

      case property
      when :class
        actual = ui_object.get_attribute(:class)
      when :exists
        actual = ui_object.exists?
      when :enabled
        actual = ui_object.enabled?
      when :disabled
        actual = ui_object.disabled?
      when :visible
        actual = ui_object.visible?
      when :hidden
        actual = ui_object.hidden?
      when :checked
        actual = ui_object.checked?
      when :selected
        actual = ui_object.selected?
      when :value
        actual = ui_object.get_value
      when :caption
        actual = ui_object.get_caption
      when :name
        actual = ui_object.tag_name
      when :placeholder
        actual = ui_object.get_placeholder
      when :readonly
        actual = ui_object.read_only?
      when :maxlength
        actual = ui_object.get_max_length
      when :items
        actual = ui_object.get_list_items
      when :itemcount
        actual = ui_object.get_item_count
      when :width
        actual = ui_object.width
      when :height
        actual = ui_object.height
      when :x
        actual = ui_object.x_loc
      when :y
        actual = ui_object.y_loc
      end
      error_msg = "Expected UI object '#{ui_object.get_name}' (#{ui_object.get_locator}) #{property} property to"
      ExceptionQueue.enqueue_comparison(state, actual, error_msg)
    end
  end
rescue ObjectNotFoundError => e
  ExceptionQueue.enqueue_exception(e.message)
ensure
  ExceptionQueue.post_exceptions
end
visible?() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 234
def visible?
  if exists?
    section.displayed?
  else
    false
  end
end
wait_until_exists(seconds = nil) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 246
def wait_until_exists(seconds = nil)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { exists? }
rescue
  raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless exists?
end
wait_until_gone(seconds = nil) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 254
def wait_until_gone(seconds = nil)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { !exists? }
rescue
  raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if exists?
end
wait_until_hidden(seconds = nil) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 270
def wait_until_hidden(seconds = nil)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { hidden? }
rescue
  raise "Section object '#{get_name}' (#{get_locator}) remained visible after #{timeout} seconds" if visible?
end
wait_until_visible(seconds = nil) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 262
def wait_until_visible(seconds = nil)
  timeout = seconds.nil? ? Environ.default_max_wait_time : seconds
  wait = Selenium::WebDriver::Wait.new(timeout: timeout)
  wait.until { visible? }
rescue
  raise "Could not find Section object '#{get_name}' (#{get_locator}) after #{timeout} seconds" unless visible?
end
width() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 279
def width
  section = find_section
  section_not_found_exception(section)
  section.size.width
end
x_loc() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 291
def x_loc
  section = find_section
  section_not_found_exception(section)
  section.location.x
end
y_loc() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 297
def y_loc
  section = find_section
  section_not_found_exception(section)
  section.location.y
end

Private Instance Methods

find_section() click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 385
def find_section
  obj = nil
  locators = get_locator
  locators.each do |loc|
    if obj.nil?
      obj = find_element(loc.keys[0], loc.values[0])
      puts "Found object #{loc}" if ENV['DEBUG']
    else
      obj = obj.find_element(loc.keys[0], loc.values[0])
      puts "Found object #{loc}" if ENV['DEBUG']
    end
  end
  obj
rescue
  nil
end
section_not_found_exception(obj) click to toggle source
# File lib/testcentricity/app_core/screen_sections_helper.rb, line 402
def section_not_found_exception(obj)
  raise ObjectNotFoundError.new("Section object '#{get_name}' (#{get_locator}) not found") unless obj
end