Top Level Namespace

Includes:
RbConfig

Defined Under Namespace

Modules: Ifd Classes: IFD_Assertion, IFD_Connections

Instance Method Summary collapse

Instance Method Details

#call_step(str_step) ⇒ Object



1
2
3
4
# 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) ⇒ Object



111
112
113
# File 'lib/Ifd_Mobile/methods/core.rb', line 111

def click_by_coordinate x, y
  selenium.execute_script 'mobile: tap', :x => x, :y => y
end

#close_appObject



211
212
213
# File 'lib/Ifd_Mobile/methods/core.rb', line 211

def close_app
  selenium.close_app
end

#delete_an_character_androidObject



223
224
225
# File 'lib/Ifd_Mobile/methods/core.rb', line 223

def delete_an_character_android
  system('adb shell input keyevent 67')
end

#execute_checkproperty(element, property, negate, value) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/Ifd_Mobile/methods/core.rb', line 69

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"
      expect(check).not_to eql true
    elsif expect(check).to eq true
    end
  end
end

#execute_click(element) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/Ifd_Mobile/methods/core.rb', line 38

def execute_click element
  found_element = find_object element
  if found_element != nil
    startTime = Time.new.to_i
    begin
      sleep(1)
      currentTime= Time.new.to_i
    end while (currentTime - startTime) < $_CONFIG['Wait Time']
    # selenium.execute_script('mobile: scroll', found_element)

    found_element.click
  else
    put_log "\nERROR: *** not found object: #{element}"
  end
end

#execute_settext(element, text) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/Ifd_Mobile/methods/core.rb', line 53

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.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) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/Ifd_Mobile/methods/core.rb', line 10

def find_object string_object
  object = YAML.load_file("#{File.expand_path(File.dirname(__FILE__) + '/..')}/step_definitions/repositories/project_object.yml")
  string_object = string_object.gsub(/"/, "'")
  # puts string_object

  locator_matching = /(.*?)(\{.*?\})/.match(string_object)
  # puts "locator_matching : #{locator_matching}"

  dyn_pros = {}
  if locator_matching != nil
    string_object = locator_matching[1]
    eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
      dyn_pros[k.to_s.upcase] = v
    }
  end
  hash_object = object[string_object]
  puts hash_object
  if hash_object == nil
    put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
    true.should eq false
  else
    hash_object.each { |key, value|
      $element_tag = key
      $element_value = value
    }
  end

  return selenium.find_element($element_tag, $element_value)
end

#launch_appObject



215
216
217
# File 'lib/Ifd_Mobile/methods/core.rb', line 215

def launch_app
  selenium.launch
end

#long_press_on_coordinates(x, y) ⇒ Object



198
199
200
201
# 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) ⇒ Object



203
204
205
206
207
208
209
# 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) ⇒ Object



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# 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) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# 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_homeObject



231
232
233
# File 'lib/Ifd_Mobile/methods/core.rb', line 231

def move_home
  selenium.key_event 3
end

method to navigate back & forward



116
117
118
119
120
121
122
# File 'lib/Ifd_Mobile/methods/core.rb', line 116

def navigate(direction)
  if direction == 'back'
    selenium.navigate.back
  else
    selenium.navigate.forward
  end
end

#put_log(str) ⇒ Object



6
7
8
# File 'lib/Ifd_Mobile/methods/core.rb', line 6

def put_log str
  puts str if $_CONFIG['Print Log'] == true
end

#replace_day(str) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# 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) ⇒ Object



48
49
50
51
52
53
54
# 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) ⇒ Object



21
22
23
24
# 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_appObject



219
220
221
# File 'lib/Ifd_Mobile/methods/core.rb', line 219

def reset_app
  selenium.reset
end

#take_photo_androidObject



227
228
229
# File 'lib/Ifd_Mobile/methods/core.rb', line 227

def take_photo_android
  system('adb shell input keyevent 27')
end

#var_collect(string_var) ⇒ Object



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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