Ifd_Mobile 1.4.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +1,44 @@
1
- # include Test::Unit::Assertions
2
- class IFD_Assertion
3
- # Assert 2 values
4
- def self.reg_compare sActual, regValue, isSpecialChar=false
5
- begin
6
- if !isSpecialChar
7
- sActual = sActual.strip
8
- regValue = regValue.strip.gsub("[", "\\[").gsub("]", "\\]").gsub("(", "\\(").gsub(")", "\\)").gsub(">", "\\>")
9
- end
10
- rescue StandardError => myStandardError
11
- put_log "\n>>> Error: #{myStandardError}"
12
- end
13
-
14
- # put_log "\nsActual:#{sActual}, regValue:#{regValue}"
15
- if ((sActual.nil? and regValue.nil?) or (!sActual.nil? and sActual.empty? and !regValue.nil? and regValue.empty?))
16
- return true
17
- end
18
-
19
- if ((sActual.nil? and !regValue.nil?) or (!sActual.nil? and regValue.nil?))
20
- return false
21
- end
22
-
23
- if (!sActual.nil? and !sActual.empty?)
24
- sCookActual = sActual.gsub(/\n|\r/, " ")
25
- if (sCookActual == regValue or (isSpecialChar and sCookActual.include? regValue) or (!isSpecialChar and sCookActual =~ /^.*#{regValue}.*$/))
26
- return true
27
- end
28
- end
29
-
30
- return false
31
- end
32
-
33
- def self.assert_string_contain(expected, actual)
34
- unless (actual.to_s).include? (expected.to_s)
35
- raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.")
36
- end
37
- end
38
-
39
- def self.assert_string_equal(expected, actual)
40
- if expected.to_s != actual.to_s
41
- raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.")
42
- end
43
- end
44
- end
1
+ # include Test::Unit::Assertions
2
+ class IFD_Assertion
3
+ # Assert 2 values
4
+ def self.reg_compare sActual, regValue, isSpecialChar=false
5
+ begin
6
+ if !isSpecialChar
7
+ sActual = sActual.strip
8
+ regValue = regValue.strip.gsub("[", "\\[").gsub("]", "\\]").gsub("(", "\\(").gsub(")", "\\)").gsub(">", "\\>")
9
+ end
10
+ rescue StandardError => myStandardError
11
+ put_log "\n>>> Error: #{myStandardError}"
12
+ end
13
+
14
+ # put_log "\nsActual:#{sActual}, regValue:#{regValue}"
15
+ if ((sActual.nil? and regValue.nil?) or (!sActual.nil? and sActual.empty? and !regValue.nil? and regValue.empty?))
16
+ return true
17
+ end
18
+
19
+ if ((sActual.nil? and !regValue.nil?) or (!sActual.nil? and regValue.nil?))
20
+ return false
21
+ end
22
+
23
+ if (!sActual.nil? and !sActual.empty?)
24
+ sCookActual = sActual.gsub(/\n|\r/, " ")
25
+ if (sCookActual == regValue or (isSpecialChar and sCookActual.include? regValue) or (!isSpecialChar and sCookActual =~ /^.*#{regValue}.*$/))
26
+ return true
27
+ end
28
+ end
29
+
30
+ return false
31
+ end
32
+
33
+ def self.assert_string_contain(expected, actual)
34
+ unless (actual.to_s).include? (expected.to_s)
35
+ raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.")
36
+ end
37
+ end
38
+
39
+ def self.assert_string_equal(expected, actual)
40
+ if expected.to_s != actual.to_s
41
+ raise ("*** ASSERTION ERROR: \nExpected: #{expected}. \nGot: #{actual}.")
42
+ end
43
+ end
44
+ end
@@ -1,28 +1,15 @@
1
- require 'mysql2'
2
- require 'tiny_tds'
3
-
4
- class IFD_Connections
5
- # Open the MYSQL connection to specific schema
6
- def self.get_mysql_db_connection(schema)
7
- begin
8
- # puts ("Connecting to database...");
9
- data_source_schema = schema.downcase
10
- return Mysql2::Client.new(host: $data_source_url, username: $data_source_username, password: $data_source_password,database:data_source_schema);
11
- rescue Exception => e
12
- raise "Cannot connect to database [username: %s; password: %s, dbUrl: %s, dbName: %s] with error %s" %
13
- [$data_source_username, $data_source_password, $data_source_url,data_source_schema, e.message]
14
- end
15
- end
16
-
17
- # Open the SQL Server connection to specific schema
18
- def self.get_sql_server_db_connection(schema)
19
- begin
20
- # puts ("Connecting to database...");
21
- data_source_schema = schema.downcase
22
- return TinyTds::Client.new(dataserver: $data_source_url, username: $data_source_username, password: $data_source_password, database:data_source_schema);
23
- rescue Exception => e
24
- raise "Cannot connect to database [username: %s; password: %s, dbUrl: %s, dbName: %s] with error %s" %
25
- [$data_source_username, $data_source_password, $data_source_url,data_source_schema, e.message]
26
- end
27
- end
28
- end
1
+ # require 'tiny_tds'
2
+ # require 'activerecord-sqlserver-adapter'
3
+ # require 'active_record'
4
+ #
5
+ # module Connection
6
+ # def self.new(connection_params)
7
+ # begin
8
+ # put_log ("Connecting to database...")
9
+ # return ActiveRecord::Base.establish_connection(connection_params)
10
+ # rescue Exception => e
11
+ # raise e.message
12
+ # end
13
+ # end
14
+ #
15
+ # end
@@ -0,0 +1,67 @@
1
+ #-----------------------------------------------------
2
+ # support define and bind variable dynamically
3
+ #-----------------------------------------------------
4
+ $dyn_vars = nil
5
+
6
+ # set value to a variable
7
+ def set_var(var_name, var_value)
8
+ if $dyn_vars == nil
9
+ $dyn_vars = binding
10
+ end
11
+
12
+ strEval = var_name + "=" + var_value
13
+ eval strEval, $dyn_vars
14
+ end
15
+
16
+ # bind string with $dyn_vars context
17
+ def bind_with_dyn_vars(str)
18
+ if $dyn_vars == nil
19
+ $dyn_vars = binding
20
+ end
21
+
22
+ strEval = '"' + str + '"'
23
+ return eval strEval, $dyn_vars
24
+ end
25
+
26
+ # evaluate operation/statement with $dyn_vars context
27
+ def eval_with_dyn_vars(operation)
28
+ if $dyn_vars == nil
29
+ $dyn_vars = binding
30
+ end
31
+
32
+ eval operation, $dyn_vars
33
+ end
34
+
35
+ def bind_with_dyn_json_vars(json, bind_json)
36
+ if json.kind_of? Hash
37
+ json.each_pair do |k, v|
38
+ if v.kind_of? String
39
+ bind_json[bind_with_dyn_vars(k)] = bind_with_dyn_json_vars(v, bind_json)
40
+ elsif v.kind_of? Hash
41
+ temp = Hash.new
42
+ v.each_pair do |k1, v1|
43
+ temp[bind_with_dyn_vars(k1)] = bind_with_dyn_json_vars(v1, temp)
44
+ end
45
+ bind_json[bind_with_dyn_vars(k)] = temp
46
+ elsif v.kind_of? Array
47
+ temp1 = Array.new
48
+ v.each {|item|
49
+ temp2 = Hash.new
50
+ bind_with_dyn_json_vars(item, temp2)
51
+ temp1 << temp2
52
+ }
53
+ bind_json[bind_with_dyn_vars(k)] = temp1
54
+ end
55
+ end
56
+ elsif json.kind_of? Array
57
+ temp1 = Array.new
58
+ json.each {|item|
59
+ temp2 = Hash.new
60
+ bind_with_dyn_json_vars(item, temp2)
61
+ temp1 << temp2
62
+ }
63
+ return temp1
64
+ else
65
+ return bind_with_dyn_vars(json)
66
+ end
67
+ end
@@ -1,241 +1,242 @@
1
- def call_step str_step
2
- put_log "\n-=> call step: #{str_step}"
3
- step %{#{str_step}}
4
- end
5
-
6
- def put_log str
7
- puts str if $_CONFIG['Print Log'] == true
8
- end
9
-
10
- def find_object string_object
11
- string_object = string_object.gsub(/"/, "'")
12
- # puts string_object
13
- locator_matching = /(.*?)(\{.*?\})/.match(string_object)
14
- # puts "locator_matching : #{locator_matching}"
15
- dyn_pros = {}
16
- if locator_matching != nil
17
- string_object = locator_matching[1]
18
- eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
19
- dyn_pros[k.to_s.upcase] = v
20
- }
21
- end
22
- hash_object = $OBJECT[string_object]
23
- puts hash_object
24
- if hash_object == nil
25
- put_log ">>> OBJECT NAME MAYBE NOT FOUND!!!"
26
- true.should eq false
27
- else
28
- hash_object.each { |key, value|
29
- $element_tag = key
30
- $element_value = value
31
- }
32
- end
33
-
34
- return selenium.find_element($element_tag, $element_value)
35
- end
36
-
37
- def execute_click element
38
- found_element = find_object element
39
- if found_element != nil
40
- startTime = Time.new.to_i
41
- begin
42
- sleep(1)
43
- currentTime= Time.new.to_i
44
- end while (currentTime - startTime) < $_CONFIG['Wait Time']
45
- # selenium.execute_script('mobile: scroll', found_element)
46
- found_element.click
47
- else
48
- put_log "\nERROR: *** not found object: #{element}"
49
- end
50
- end
51
-
52
- def execute_settext element, text
53
- found_element = find_object element
54
- if found_element != nil
55
- begin
56
- sleep(1)
57
- # found_element.long_press_keycode(46)
58
- found_element.send_keys(text)
59
- rescue StandardError => myStandardError
60
- put_log "\nERROR: *** #{myStandardError}"
61
- end
62
- else
63
- put_log "\nERROR: *** not found object: #{element}"
64
- exit
65
- end
66
- end
67
-
68
- def execute_checkproperty element, property, negate, value
69
- found_element = find_object element
70
- check = false
71
- if found_element == nil and value == ""
72
- check = true
73
- expect(check).to eq true
74
- else
75
- put_log "\n*** Execute_CheckProperty: finish to found element"
76
- if found_element != nil
77
- if property.upcase == 'VALUE'
78
- actual_value = found_element.attribute("value")
79
- elsif property.upcase == 'NAME'
80
- actual_value = found_element.attribute("name")
81
- elsif property.upcase == 'LABEL'
82
- actual_value = found_element.attribute("label")
83
- elsif property.upcase == 'TYPE'
84
- actual_value = found_element.attribute("type")
85
- elsif property.upcase == 'ENABLE'
86
- actual_value = found_element.attribute("enable")
87
- else
88
- actual_value = found_element.attribute("#{property}")
89
- end
90
- if actual_value == nil
91
- actual_value = ''
92
- end
93
- else
94
- put_log "ERROR: *** Not found object: #{element}"
95
- end
96
-
97
- if IFD_Assertion.reg_compare(actual_value, value)
98
- check = true
99
- end
100
-
101
- put_log "\n#{property} :: Actual Result Is '#{actual_value}' -- Expected Result Is '#{value}'"
102
-
103
- if negate == " not"
104
- expect(check).not_to eql true
105
- elsif expect(check).to eq true
106
- end
107
- end
108
- end
109
-
110
- def click_by_coordinate x, y
111
- selenium.execute_script 'mobile: tap', :x => x, :y => y
112
- end
113
-
114
- # method to navigate back & forward
115
- def navigate(direction)
116
- if direction == 'back'
117
- selenium.navigate.back
118
- else
119
- selenium.navigate.forward
120
- end
121
- end
122
-
123
- # def swipe_direction(direction)
124
- # size = selenium.manage.window.size
125
- # height = size.height.to_i - 10
126
- # width = size.width.to_i - 10
127
- #
128
- # if direction == 'right'
129
- # start_x = (width/100) * 15 # 83
130
- # start_y = height/2 # 695
131
- # end_x = (width/100) * 90 # 900
132
- # end_y = height/2 # 630
133
- # elsif direction == 'left'
134
- # start_x = (width/100) * 90
135
- # start_y = height/2
136
- # end_x = (width/100) * 15
137
- # end_y = height/2
138
- # elsif direction == 'up'
139
- # start_x = width/2
140
- # start_y = (height/100) * 90
141
- # end_x = width/2
142
- # end_y = (height/100) * 15
143
- # elsif direction == 'down'
144
- # start_x = width/2
145
- # start_y = (height/100) * 15
146
- # end_x = width/2
147
- # end_y = (height/100) * 90
148
- # else
149
- # raise "invalid direction"
150
- # end
151
- #
152
- # swipe(start_x, start_y, end_x, end_y)
153
- # end
154
-
155
- # def swipe(start_x, start_y, end_x, end_y)
156
- # action = Appium::TouchAction.new.press(x: "#{start_x}", y: "#{start_y}").wait(1000).move_to(x: "#{end_x}", y: "#{end_y}").release()
157
- # action.perform
158
- # end
159
-
160
-
161
- def long_press_on_element_default_duration(element)
162
- begin
163
- ele_from = find_object element.location
164
- x = ele_from.x
165
- y = ele_from.y
166
-
167
- action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y: "#{y}").release()
168
- action.perform
169
- rescue Exception => e
170
- if e.to_s == 'The swipe did not complete successfully'
171
- print ""
172
- else
173
- raise e
174
- end
175
- end
176
- end
177
-
178
- def long_press_on_element_with_duration(element, duration)
179
- begin
180
- ele_from = find_object element.location
181
- x = ele_from.x
182
- y = ele_from.y
183
-
184
- duration = duration.to_i
185
- duration = duration * 1000
186
- action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y: "#{y}").release()
187
- action.perform
188
- rescue Exception => e
189
- if e.to_s == 'The swipe did not complete successfully'
190
- print ""
191
- else
192
- raise e
193
- end
194
- end
195
- end
196
-
197
- def long_press_on_coordinates(x, y)
198
- action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y: "#{y}").release()
199
- action.perform
200
- end
201
-
202
- def long_press_on_coordinates_with_duration(x, y, duration)
203
- duration = duration.to_i
204
- duration = duration * 1000
205
- puts duration
206
- action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y: "#{y}").release()
207
- action.perform
208
- end
209
-
210
- def close_app
211
- selenium.close_app
212
- end
213
-
214
- def launch_app
215
- selenium.launch
216
- end
217
-
218
- def reset_app
219
- selenium.reset
220
- end
221
-
222
- def delete_an_character_android
223
- system('adb shell input keyevent 67')
224
- end
225
-
226
- def take_photo_android
227
- system('adb shell input keyevent 27')
228
- end
229
-
230
- def move_home
231
- selenium.key_event 3
232
- end
233
-
234
- def data(name)
235
- require 'yaml'
236
- begin
237
- return $globalData["#{name}"]
238
- rescue Exception
239
- return name
240
- end
1
+ def call_step str_step
2
+ put_log "\n-=> call step: #{str_step}"
3
+ step %{#{str_step}}
4
+ end
5
+
6
+ def put_log str
7
+ puts str if $print_log
8
+ end
9
+
10
+ def find_object string_object
11
+ string_object = string_object.gsub(/"/, "'")
12
+ hash_object = $OBJECT[string_object]
13
+ if hash_object.nil?
14
+ expect(true).to eq(false)
15
+ else
16
+ hash_object.each { |key, value|
17
+ $element_tag = key
18
+ $element_value = value
19
+ }
20
+ end
21
+ get_object_by_dynamic_selector($element_tag, $element_value)
22
+ end
23
+
24
+ def get_object_by_dynamic_selector(selector_type,value)
25
+ foundElements = nil
26
+ begin
27
+ foundElements = @driver.find_element(selector_type, value)
28
+ rescue StandardError => myStandardError
29
+ p "\n>>> Error: #{myStandardError}"
30
+ end
31
+ foundElements
32
+ end
33
+
34
+ def execute_click element
35
+ found_element = find_object element
36
+ if found_element != nil
37
+ startTime = Time.new.to_i
38
+ begin
39
+ sleep(1)
40
+ found_element.click
41
+ rescue StandardError => myStandardError
42
+ put_log "\nERROR: *** #{myStandardError}"
43
+ end
44
+ else
45
+ put_log "\nERROR: *** not found object: #{element}"
46
+ end
47
+ end
48
+
49
+ def execute_settext element, text
50
+ found_element = find_object element
51
+ if found_element != nil
52
+ begin
53
+ sleep(1)
54
+ # found_element.long_press_keycode(46)
55
+ found_element.clear
56
+ found_element.send_keys(text)
57
+ rescue StandardError => myStandardError
58
+ put_log "\nERROR: *** #{myStandardError}"
59
+ end
60
+ else
61
+ put_log "\nERROR: *** not found object: #{element}"
62
+ exit
63
+ end
64
+ end
65
+
66
+ def execute_checkproperty element, property, negate, value
67
+ found_element = find_object element
68
+ check = false
69
+ if found_element == nil and value == ""
70
+ check = true
71
+ expect(check).to eq true
72
+ else
73
+ put_log "\n*** Execute_CheckProperty: finish to found element"
74
+ if found_element != nil
75
+ if property.upcase == 'VALUE'
76
+ actual_value = found_element.attribute("value")
77
+ elsif property.upcase == 'NAME'
78
+ actual_value = found_element.attribute("name")
79
+ elsif property.upcase == 'LABEL'
80
+ actual_value = found_element.attribute("label")
81
+ elsif property.upcase == 'TYPE'
82
+ actual_value = found_element.attribute("type")
83
+ elsif property.upcase == 'ENABLE'
84
+ actual_value = found_element.attribute("enable")
85
+ else
86
+ actual_value = found_element.attribute("#{property}")
87
+ end
88
+ if actual_value == nil
89
+ actual_value = ''
90
+ end
91
+ else
92
+ put_log "ERROR: *** Not found object: #{element}"
93
+ end
94
+
95
+ if IFD_Assertion.reg_compare(actual_value, value)
96
+ check = true
97
+ end
98
+
99
+ put_log "\n#{property} :: Actual Result Is '#{actual_value}' -- Expected Result Is '#{value}'"
100
+
101
+ if negate == " not"
102
+ actual_value.should_not eq value
103
+ expect(actual_value).not_to eql value
104
+ elsif
105
+ actual_value.should eq value
106
+ expect(actual_value).to eq value
107
+ end
108
+ end
109
+ end
110
+
111
+ def click_by_coordinate x, y
112
+ @driver.execute_script 'mobile: tap', :x => x, :y => y
113
+ end
114
+
115
+ # method to navigate back & forward
116
+ def navigate(direction)
117
+ if direction == 'back'
118
+ @driver.navigate.back
119
+ else
120
+ @driver.navigate.forward
121
+ end
122
+ end
123
+
124
+ # def swipe_direction(direction)
125
+ # size = selenium.manage.window.size
126
+ # height = size.height.to_i - 10
127
+ # width = size.width.to_i - 10
128
+ #
129
+ # if direction == 'right'
130
+ # start_x = (width/100) * 15 # 83
131
+ # start_y = height/2 # 695
132
+ # end_x = (width/100) * 90 # 900
133
+ # end_y = height/2 # 630
134
+ # elsif direction == 'left'
135
+ # start_x = (width/100) * 90
136
+ # start_y = height/2
137
+ # end_x = (width/100) * 15
138
+ # end_y = height/2
139
+ # elsif direction == 'up'
140
+ # start_x = width/2
141
+ # start_y = (height/100) * 90
142
+ # end_x = width/2
143
+ # end_y = (height/100) * 15
144
+ # elsif direction == 'down'
145
+ # start_x = width/2
146
+ # start_y = (height/100) * 15
147
+ # end_x = width/2
148
+ # end_y = (height/100) * 90
149
+ # else
150
+ # raise "invalid direction"
151
+ # end
152
+ #
153
+ # swipe(start_x, start_y, end_x, end_y)
154
+ # end
155
+
156
+ # def swipe(start_x, start_y, end_x, end_y)
157
+ # action = Appium::TouchAction.new.press(x: "#{start_x}", y: "#{start_y}").wait(1000).move_to(x: "#{end_x}", y: "#{end_y}").release()
158
+ # action.perform
159
+ # end
160
+
161
+
162
+ def long_press_on_element_default_duration(element)
163
+ begin
164
+ ele_from = find_object element.location
165
+ x = ele_from.x
166
+ y = ele_from.y
167
+
168
+ action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y: "#{y}").release()
169
+ action.perform
170
+ rescue Exception => e
171
+ if e.to_s == 'The swipe did not complete successfully'
172
+ print ""
173
+ else
174
+ raise e
175
+ end
176
+ end
177
+ end
178
+
179
+ def long_press_on_element_with_duration(element, duration)
180
+ begin
181
+ ele_from = find_object element.location
182
+ x = ele_from.x
183
+ y = ele_from.y
184
+
185
+ duration = duration.to_i
186
+ duration = duration * 1000
187
+ action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y: "#{y}").release()
188
+ action.perform
189
+ rescue Exception => e
190
+ if e.to_s == 'The swipe did not complete successfully'
191
+ print ""
192
+ else
193
+ raise e
194
+ end
195
+ end
196
+ end
197
+
198
+ def long_press_on_coordinates(x, y)
199
+ action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait(2000).move_to(x: "#{x}", y: "#{y}").release()
200
+ action.perform
201
+ end
202
+
203
+ def long_press_on_coordinates_with_duration(x, y, duration)
204
+ duration = duration.to_i
205
+ duration = duration * 1000
206
+ puts duration
207
+ action = Appium::TouchAction.new.press(x: "#{x}", y: "#{y}").wait("#{duration}").move_to(x: "#{x}", y: "#{y}").release()
208
+ action.perform
209
+ end
210
+
211
+ def close_app
212
+ @driver.close_app
213
+ end
214
+
215
+ def launch_app
216
+ @driver.launch
217
+ end
218
+
219
+ def reset_app
220
+ @driver.reset
221
+ end
222
+
223
+ def delete_an_character_android
224
+ system('adb shell input keyevent 67')
225
+ end
226
+
227
+ def take_photo_android
228
+ system('adb shell input keyevent 27')
229
+ end
230
+
231
+ def move_home
232
+ @driver.key_event 3
233
+ end
234
+
235
+ def data(name)
236
+ require 'yaml'
237
+ begin
238
+ return $globalData["#{name}"]
239
+ rescue Exception
240
+ return name
241
+ end
241
242
  end