lib/testcentricity_web/web_core/page_objects_helper.rb
# Populate the specified UI elements on this page or section object with the associated data from a Hash passed as an
# argument. Data values must be in the form of a String for textfield, selectlist, and filefield controls. For checkbox
# and radio buttons, data must either be a Boolean or a String that evaluates to a Boolean value (Yes, No, 1, 0, true,
# false). For range controls, data must be an Integer. For input(type='color') color picker controls, which are specified
# as a textfield, data must be in the form of a hex color String. For section objects, data values must be a String, and
# the section object must have a set method defined.
#
# The optional wait_time parameter is used to specify the time (in seconds) to wait for each UI element to become
# visible before entering the associated data value. This option is useful in situations where entering data, or
# setting the state of a UI element might cause other UI elements to become visible or active. Specifying a wait_time
# value ensures that the subsequent UI elements will be ready to be interacted with as states are changed. If the wait
# time is nil, then the wait time will be 5 seconds.
#
# To delete all text content in a text field, pass !DELETE as the data to be entered.
#
# @param data [Hash] UI element(s) and associated data to be entered
# @param wait_time [Integer] wait time in seconds
# @param integrity_check [Boolean] if TRUE, ensure that text entered into text fields matches what was entered
# @example
#   field_data = { prefix_select      => 'Ms',
#                  first_name_field   => 'Priscilla',
#                  last_name_field    => 'Pumperknickle',
#                  gender_select      => 'Female',
#                  dob_field          => '11/18/1976',
#                  email_field        => 'p.pumperknickle4876@gmail.com',
#                  mailing_list_check => 'Yes'
#          }
#   populate_data_fields(field_data)
#
Populate the specified UI elements on this page or section object with the associated data from a Hash passed as an
argument. Data values must be in the form of a String for textfield, selectlist, and filefield controls. For checkbox
and radio buttons, data must either be a Boolean or a String that evaluates to a Boolean value (Yes, No, 1, 0, true,
false). For range controls, data must be an Integer. For input(type='color') color picker controls, which are specified
as a textfield, data must be in the form of a hex color String. For section objects, data values must be a String, and
the section object must have a set method defined.

The optional wait_time parameter is used to specify the time (in seconds) to wait for each UI element to become
visible before entering the associated data value. This option is useful in situations where entering data, or
setting the state of a UI element might cause other UI elements to become visible or active. Specifying a wait_time
value ensures that the subsequent UI elements will be ready to be interacted with as states are changed. If the wait
time is nil, then the wait time will be 5 seconds.

To delete all text content in a text field, pass !DELETE as the data to be entered.
Populate the specified UI elements on this page or section object with the associated data from a Hash passed as an argument . Data values must be in the form of a String for textfield selectlist and filefield controls . For checkbox and radio buttons data must either be a Boolean or a String that evaluates to a Boolean value ( Yes No 1 0 true false ) . For range controls data must be an Integer . For input ( type = ' color ' ) color picker controls which are specified as a textfield data must be in the form of a hex color String . For section objects data values must be a String and the section object must have a set method defined . The optional wait_time parameter is used to specify the time ( in seconds ) to wait for each UI element to become visible before entering the associated data value . This option is useful in situations where entering data or setting the state of a UI element might cause other UI elements to become visible or active . Specifying a wait_time value ensures that the subsequent UI elements will be ready to be interacted with as states are changed . If the wait time is nil then the wait time will be 5 seconds . To delete all text content in a text field pass !DELETE as the data to be entered .
def populate_data_fields(data, wait_time = nil, integrity_check = false)
      timeout = wait_time.nil? ? 5 : wait_time
      data.each do |data_field, data_param|
        unless data_param != false && data_param.blank?
          data_field.wait_until_visible(timeout)
          if data_param == '!DELETE'
            data_field.clear
          else
            case data_field.get_object_type
            when :checkbox
              check_state = data_param.is_a?(String) ? data_param.to_bool : data_param
              data_field.set_checkbox_state(check_state)
            when :selectlist
              data_field.choose_option(data_param)
            when :radio
              check_state = data_param.is_a?(String) ? data_param.to_bool : data_param
              data_field.set_selected_state(check_state)
            when :textfield
              if %w[color number].include?(data_field.get_attribute(:type))
                data_field.set(data_param)
              else
                data_field.set("#{data_param}\t")
                if integrity_check && data_field.get_value != data_param
                  data_field.set('')
                  data_field.send_keys(data_param)
                  data_field.send_keys(:tab)
                end
              end
            when :section, :range
              data_field.set(data_param)
            when :filefield
              data_field.file_upload(data_param)
            end
          end
        end
      end
    end
def populate_data_fields ( data , wait_time = nil , integrity_check = false ) timeout = wait_time . nil? ? 5 : wait_time data . each do | data_field , data_param | unless data_param != false && data_param . blank? data_field . wait_until_visible ( timeout ) if data_param == '!DELETE' data_field . clear else case data_field . get_object_type when :checkbox check_state = data_param . is_a? ( String ) ? data_param . to_bool : data_param data_field . set_checkbox_state ( check_state ) when :selectlist data_field . choose_option ( data_param ) when :radio check_state = data_param . is_a? ( String ) ? data_param . to_bool : data_param data_field . set_selected_state ( check_state ) when :textfield if %w[ color number ] . include? ( data_field . get_attribute ( :type ) ) data_field . set ( data_param ) else data_field . set ( "#{data_param}\t" ) if integrity_check && data_field . get_value != data_param data_field . set ( '' ) data_field . send_keys ( data_param ) data_field . send_keys ( :tab ) end end when :section , :range data_field . set ( data_param ) when :filefield data_field . file_upload ( data_param ) end end end end end
Populate the specified UI elements on this page or section object with the associated data from a Hash passed as an
argument.
Populate the specified UI elements on this page or section object with the associated data from a Hash passed as an argument .
# make sure the intended UI target element is visible before trying to set its value
data
UI element(s) and associated data to be entered
UI element ( s ) and associated data to be entered
wait_time
wait time in seconds
wait time in seconds
integrity_check
if TRUE, ensure that text entered into text fields matches what was entered
if TRUE ensure that text entered into text fields matches what was entered
example
field_data = { prefix_select => 'Ms', first_name_field => 'Priscilla', last_name_field => 'Pumperknickle', gender_select => 'Female', dob_field => '11/18/1976', email_field => 'p.pumperknickle4876@gmail.com', mailing_list_check => 'Yes' } populate_data_fields(field_data)
field_data = { prefix_select = > ' Ms ' first_name_field = > ' Priscilla ' last_name_field = > ' Pumperknickle ' gender_select = > ' Female ' dob_field = > ' 11 / 18 / 1976 ' email_field = > ' p . pumperknickle4876@gmail . com ' mailing_list_check = > ' Yes ' } populate_data_fields ( field_data )