class Object

Public Instance Methods

bind_with_dyn_json_vars(json, bind_json) click to toggle source
# File lib/Ifd_Mobile/methods/auto_utils.rb, line 35
def bind_with_dyn_json_vars(json, bind_json)
  if json.kind_of? Hash
    json.each_pair do |k, v|
      if v.kind_of? String
        bind_json[bind_with_dyn_vars(k)] = bind_with_dyn_json_vars(v, bind_json)
      elsif v.kind_of? Hash
        temp = Hash.new
        v.each_pair do |k1, v1|
          temp[bind_with_dyn_vars(k1)] = bind_with_dyn_json_vars(v1, temp)
        end
        bind_json[bind_with_dyn_vars(k)] = temp
      elsif v.kind_of? Array
        temp1 = Array.new
        v.each {|item|
          temp2 = Hash.new
          bind_with_dyn_json_vars(item, temp2)
          temp1 << temp2
        }
        bind_json[bind_with_dyn_vars(k)] = temp1
      end
    end
  elsif json.kind_of? Array
    temp1 = Array.new
    json.each {|item|
      temp2 = Hash.new
      bind_with_dyn_json_vars(item, temp2)
      temp1 << temp2
    }
    return temp1
  else
    return bind_with_dyn_vars(json)
  end
end
bind_with_dyn_vars(str) click to toggle source

bind string with $dyn_vars context

# File lib/Ifd_Mobile/methods/auto_utils.rb, line 17
def bind_with_dyn_vars(str)
  if $dyn_vars == nil
    $dyn_vars = binding
  end

  strEval = '"' + str + '"'
  return eval strEval, $dyn_vars
end
call_step(str_step) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 1
def call_step str_step
  put_log "\n-=> call step: #{str_step}"
  step %{#{str_step}}
end
click_by_coordinate(x, y) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 111
def click_by_coordinate x, y
  @driver.execute_script 'mobile: tap', :x => x, :y => y
end
close_app() click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 211
def close_app
  @driver.close_app
end
data(name) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 235
def data(name)
  require 'yaml'
  begin
    return $globalData["#{name}"]
  rescue Exception
    return name
  end
end
delete_an_character_android() click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 223
def delete_an_character_android
  system('adb shell input keyevent 67')
end
eval_with_dyn_vars(operation) click to toggle source

evaluate operation/statement with $dyn_vars context

# File lib/Ifd_Mobile/methods/auto_utils.rb, line 27
def eval_with_dyn_vars(operation)
  if $dyn_vars == nil
    $dyn_vars = binding
  end

  eval operation, $dyn_vars
end
execute_checkproperty(element, property, negate, value) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 66
def execute_checkproperty element, property, negate, value
  found_element = find_object element
  check = false
  if found_element == nil and value == ""
    check = true
    expect(check).to eq true
  else
    put_log "\n*** Execute_CheckProperty: finish to found element"
    if found_element != nil
      if property.upcase == 'VALUE'
        actual_value = found_element.attribute("value")
      elsif property.upcase == 'NAME'
        actual_value = found_element.attribute("name")
      elsif property.upcase == 'LABEL'
        actual_value = found_element.attribute("label")
      elsif property.upcase == 'TYPE'
        actual_value = found_element.attribute("type")
      elsif property.upcase == 'ENABLE'
        actual_value = found_element.attribute("enable")
      else
        actual_value = found_element.attribute("#{property}")
      end
      if actual_value == nil
        actual_value = ''
      end
    else
      put_log "ERROR: *** Not found object: #{element}"
    end

    if IFD_Assertion.reg_compare(actual_value, value)
      check = true
    end

    put_log "\n#{property} :: Actual Result Is '#{actual_value}' -- Expected Result Is '#{value}'"

    if negate == " not"
      actual_value.should_not eq value
      expect(actual_value).not_to eql value
    elsif
    actual_value.should eq value
      expect(actual_value).to eq value
    end
  end
end
execute_click(element) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 34
def execute_click element
  found_element = find_object element
  if found_element != nil
    startTime = Time.new.to_i
    begin
      sleep(1)
      found_element.click
    rescue StandardError => myStandardError
      put_log "\nERROR: *** #{myStandardError}"
    end
  else
    put_log "\nERROR: *** not found object: #{element}"
  end
end
execute_settext(element, text) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 49
def execute_settext element, text
  found_element = find_object element
  if found_element != nil
    begin
      sleep(1)
      # found_element.long_press_keycode(46)
      found_element.clear
      found_element.send_keys(text)
    rescue StandardError => myStandardError
      put_log "\nERROR: *** #{myStandardError}"
    end
  else
    put_log "\nERROR: *** not found object: #{element}"
    exit
  end
end
find_object(string_object) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 10
def find_object string_object
  string_object = string_object.gsub(/"/, "'")
  hash_object = $OBJECT[string_object]
  if hash_object.nil?
    expect(true).to eq(false)
  else
    hash_object.each { |key, value|
      $element_tag = key
      $element_value = value
    }
  end
  get_object_by_dynamic_selector($element_tag, $element_value)
end
get_object_by_dynamic_selector(selector_type,value) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 24
def get_object_by_dynamic_selector(selector_type,value)
  foundElements = nil
  begin
    foundElements = @driver.find_element(selector_type, value)
  rescue StandardError => myStandardError
    p "\n>>> Error: #{myStandardError}"
  end
  foundElements
end
launch_app() click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 215
def launch_app
  @driver.launch
end
long_press_on_coordinates(x, y) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 198
def long_press_on_coordinates(x, y)
  action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y:  "#{y}").release()
  action.perform
end
long_press_on_coordinates_with_duration(x, y, duration) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 203
def long_press_on_coordinates_with_duration(x, y, duration)
  duration = duration.to_i
  duration = duration * 1000
  puts duration
  action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y:  "#{y}").release()
  action.perform
end
long_press_on_element_default_duration(element) click to toggle source

def swipe(start_x, start_y, end_x, end_y)

action = Appium::TouchAction.new.press(x: "#{start_x}", y: "#{start_y}").wait(1000).move_to(x: "#{end_x}", y:  "#{end_y}").release()
action.perform

end

# File lib/Ifd_Mobile/methods/core.rb, line 162
def long_press_on_element_default_duration(element)
  begin
    ele_from = find_object element.location
    x = ele_from.x
    y = ele_from.y

    action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y:  "#{y}").release()
    action.perform
  rescue Exception => e
    if e.to_s == 'The swipe did not complete successfully'
      print ""
    else
      raise e
    end
  end
end
long_press_on_element_with_duration(element, duration) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 179
def long_press_on_element_with_duration(element, duration)
  begin
    ele_from = find_object element.location
    x = ele_from.x
    y = ele_from.y

    duration = duration.to_i
    duration = duration * 1000
    action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y:  "#{y}").release()
    action.perform
  rescue Exception => e
    if e.to_s == 'The swipe did not complete successfully'
      print ""
    else
      raise e
    end
  end
end
move_home() click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 231
def move_home
  @driver.key_event 3
end
navigate(direction) click to toggle source

method to navigate back & forward

put_log(str) click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 6
def put_log str
  puts str if $print_log
end
replace_day(str) click to toggle source
# File lib/Ifd_Mobile/methods/lib_var.rb, line 37
def replace_day str
  t = Time.now()
  _day = t.day
  if _day < 10
    return str.gsub("{day}", "0#{_day.to_s}")
  else
    return str.gsub("{day}", "#{_day.to_s}")
  end
  return str
end
replace_month(str) click to toggle source
# File lib/Ifd_Mobile/methods/lib_var.rb, line 26
def replace_month str
  t = Time.now()
  _month = t.month
  if _month < 10
    return str.gsub("{month}", "0#{_month.to_s}")
  else
    return str.gsub("{month}", "#{_month.to_s}")
  end
  return str
end
replace_pipe(str_pipe) click to toggle source
# File lib/Ifd_Mobile/methods/lib_var.rb, line 48
def replace_pipe str_pipe
  put_log ">>>> #{str_pipe}"
  if str_pipe =~ /^.*{pipe}.*$/
    return str_pipe.gsub("{pipe}", "|")
  end
  return str_pipe
end
replace_year(str) click to toggle source
# File lib/Ifd_Mobile/methods/lib_var.rb, line 21
def replace_year str
  t = Time.now()
  return str.gsub("{year}", t.year.to_s)
end
reset_app() click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 219
def reset_app
  @driver.reset
end
set_var(var_name, var_value) click to toggle source

set value to a variable

# File lib/Ifd_Mobile/methods/auto_utils.rb, line 7
def set_var(var_name, var_value)
  if $dyn_vars == nil
    $dyn_vars = binding
  end

  strEval = var_name + "=" + var_value
  eval strEval, $dyn_vars
end
take_photo_android() click to toggle source
# File lib/Ifd_Mobile/methods/core.rb, line 227
def take_photo_android
  system('adb shell input keyevent 27')
end
var_collect(string_var) click to toggle source
# File lib/Ifd_Mobile/methods/lib_var.rb, line 1
def var_collect string_var
  if string_var =~ /^.*{year}.*$/
    string_var = replace_year(string_var)
  end

  if string_var =~ /^.*{month}.*$/
    string_var = replace_month(string_var)
  end

  if string_var =~ /^.*{day}.*$/
    string_var = replace_day(string_var)
  end

  if string_var =~ /^.*{store_value}.*$/
    string_var = $context_value
  end

  return string_var
end