itms_automation 1.4 → 1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/itms_automation/auto_util.rb +573 -8
- data/lib/itms_automation/database_steps_helper.rb +51 -23
- data/lib/itms_automation/version.rb +1 -1
- data/lib/itms_automation/web_steps_helper.rb +214 -630
- data/project/Gemfile.lock +92 -0
- data/project/features/TestSuite/WebGUI.feature +1 -1
- data/project/features/step_definitions/lib_steps/steps_definition.rb +13 -4
- data/project/features/step_definitions/repositories/project_object.yml +12 -2
- data/project/features/support/env.rb +9 -11
- metadata +31 -2
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
1
|
+
# require "active_record"
|
2
2
|
|
3
|
-
def create_database_connection
|
3
|
+
def create_database_connection(config)
|
4
|
+
start = Time.now
|
4
5
|
begin
|
5
6
|
if config.class === "String"
|
6
7
|
config = JSON.parse config
|
@@ -17,81 +18,108 @@ def create_database_connection config
|
|
17
18
|
@connection = ActiveRecord::Base.establish_connection(config)
|
18
19
|
ActiveRecord::Base.connection.active?
|
19
20
|
|
20
|
-
if
|
21
|
+
if @connection.connected?
|
22
|
+
print_log("passed", start, __method__, config)
|
23
|
+
else
|
24
|
+
print_log("failed", start, __method__, config)
|
21
25
|
raise "Error: Can't connect to database"
|
22
26
|
end
|
23
27
|
rescue JSON::ParserError
|
24
|
-
|
28
|
+
print_log("failed", start, __method__, config)
|
29
|
+
raise "Error: Please check your connection configuration"
|
25
30
|
rescue Exception => e
|
26
|
-
|
31
|
+
print_log("failed", start, __method__, config)
|
32
|
+
raise "Error: #{e.message}"
|
27
33
|
end
|
28
34
|
end
|
29
35
|
|
30
36
|
def close_database_connection
|
37
|
+
start = Time.now
|
31
38
|
begin
|
32
39
|
@connection.disconnect!
|
40
|
+
print_log("passed", start, __method__)
|
33
41
|
rescue Exception => e
|
34
|
-
|
42
|
+
print_log("failed", start, __method__)
|
43
|
+
raise "Error: #{e.message}"
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
|
-
def execute_query
|
47
|
+
def execute_query(query)
|
48
|
+
start = Time.now
|
39
49
|
begin
|
40
50
|
if @connection.connected?
|
41
51
|
@result = @connection.connection.exec_query(query).to_a
|
52
|
+
print_log("passed", start, __method__, query)
|
42
53
|
else
|
54
|
+
print_log("failed", start, __method__, query)
|
43
55
|
raise "Error: Create connection to database first!"
|
44
56
|
end
|
45
57
|
rescue Exception => e
|
46
|
-
|
58
|
+
print_log("failed", start, __method__, query)
|
59
|
+
raise "Error: #{e.message}"
|
47
60
|
end
|
48
61
|
end
|
49
62
|
|
50
63
|
def print_sql_result
|
64
|
+
start = Time.now
|
51
65
|
if @result.present?
|
52
|
-
|
53
|
-
|
66
|
+
puts "SQL result:"
|
67
|
+
puts @result.to_json
|
54
68
|
else
|
55
|
-
|
69
|
+
puts "WARNING: No result from SQL statement"
|
56
70
|
end
|
57
71
|
end
|
58
72
|
|
59
|
-
def verify_sql_result_contain
|
73
|
+
def verify_sql_result_contain(expected_string)
|
74
|
+
start = Time.now
|
60
75
|
begin
|
61
76
|
@expected = JSON.parse(expected_string)
|
62
77
|
is_contain = false
|
63
78
|
if @expected.kind_of?(Array) && @expected.length > @result.length
|
64
|
-
|
79
|
+
print_log("failed", start, __method__, expected_string)
|
80
|
+
raise "Error: Expected: #{@expected}\nGot: #{@result}\nQuery result not includes your expected"
|
65
81
|
end
|
66
82
|
@result.each do |row|
|
67
83
|
is_contain = do_assertion_json(@expected, row)
|
68
84
|
break if !@expected.kind_of?(Array) && is_contain == true
|
69
85
|
end
|
70
|
-
|
71
|
-
|
86
|
+
if is_contain
|
87
|
+
print_log("passed", start, __method__, expected_string)
|
88
|
+
else
|
89
|
+
print_log("failed", start, __method__, expected_string)
|
90
|
+
raise "Error: Expected: #{@expected}\nGot: #{@result}\nQuery result not includes your expected"
|
72
91
|
end
|
73
92
|
rescue JSON::ParserError
|
74
|
-
|
93
|
+
print_log("failed", start, __method__, expected_string)
|
94
|
+
raise "Error: Please check your expected"
|
75
95
|
rescue Exception => e
|
76
|
-
|
96
|
+
print_log("failed", start, __method__, expected_string)
|
97
|
+
raise "Error: #{e.message}"
|
77
98
|
end
|
78
99
|
end
|
79
100
|
|
80
|
-
def verify_sql_result_equal
|
101
|
+
def verify_sql_result_equal(expected_string)
|
102
|
+
start = Time.now
|
81
103
|
begin
|
82
104
|
@expected = JSON.parse(expected_string)
|
83
105
|
if !@expected.kind_of?(Array) || @expected.length != @result.length
|
84
|
-
|
106
|
+
print_log("failed", start, __method__, expected_string)
|
107
|
+
raise "Error: Expected: #{@expected}\nGot: #{@result}\nQuery result not equal with your expected"
|
85
108
|
end
|
86
109
|
@result.each_with_index do |row, index|
|
87
110
|
is_contain = row.to_s == @expected[index].to_s
|
88
|
-
|
89
|
-
|
111
|
+
if is_contain
|
112
|
+
print_log("passed", start, __method__, expected_string)
|
113
|
+
else
|
114
|
+
print_log("failed", start, __method__, expected_string)
|
115
|
+
raise "Error: Expected: #{@expected}\nGot: #{@result}\nQuery result not equal with your expected"
|
90
116
|
end
|
91
117
|
end
|
92
118
|
rescue JSON::ParserError
|
93
|
-
|
119
|
+
print_log("failed", start, __method__, expected_string)
|
120
|
+
raise "Error: Please check your expected"
|
94
121
|
rescue Exception => e
|
95
|
-
|
122
|
+
print_log("failed", start, __method__, expected_string)
|
123
|
+
raise "Error: #{e.message}"
|
96
124
|
end
|
97
125
|
end
|
@@ -1,217 +1,284 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "net/https"
|
2
|
+
require "rspec"
|
3
3
|
|
4
4
|
def execute_openbrowser(url_site)
|
5
|
+
start = Time.now
|
5
6
|
begin
|
6
7
|
if url_site == ""
|
7
|
-
|
8
|
+
print_log("failed", start, __method__, url_site)
|
9
|
+
raise "Error: Null web page URL."
|
8
10
|
end
|
9
11
|
visit(url_site)
|
12
|
+
print_log("passed", start, __method__, url_site)
|
10
13
|
rescue StandardError => e
|
11
|
-
|
14
|
+
print_log("failed", start, __method__, url_site)
|
15
|
+
raise "Error: #{e.message}"
|
12
16
|
end
|
13
17
|
end
|
14
18
|
|
15
19
|
def execute_click(element)
|
20
|
+
start = Time.now
|
16
21
|
foundElement = find_object(element)
|
17
22
|
if foundElement != nil
|
18
23
|
begin
|
19
24
|
foundElement.click
|
25
|
+
print_log("passed", start, __method__, element)
|
20
26
|
rescue StandardError => e
|
21
|
-
|
27
|
+
print_log("failed", start, __method__, element)
|
28
|
+
raise "Error: #{e.message}"
|
22
29
|
end
|
23
30
|
else
|
24
|
-
|
31
|
+
print_log("failed", start, __method__, element)
|
32
|
+
raise "Error: Not found object #{element}"
|
25
33
|
end
|
26
34
|
end
|
27
35
|
|
28
36
|
def execute_click_offset(element, x, y)
|
37
|
+
start = Time.now
|
29
38
|
foundElement = find_object(element)
|
30
39
|
if foundElement != nil
|
31
40
|
begin
|
32
|
-
page.driver.browser.mouse.move_to(foundElement.native,x.to_i,y.to_i)
|
41
|
+
page.driver.browser.mouse.move_to(foundElement.native, x.to_i, y.to_i)
|
33
42
|
page.driver.browser.mouse.click()
|
43
|
+
print_log("passed", start, __method__, element, x, y)
|
34
44
|
rescue Exception => e
|
35
|
-
|
45
|
+
print_log("failed", start, __method__, element, x, y)
|
46
|
+
raise "Error: #{e.message}"
|
36
47
|
end
|
37
48
|
else
|
38
|
-
|
49
|
+
print_log("failed", start, __method__, element, x, y)
|
50
|
+
raise "Error: Not found object: #{element}"
|
39
51
|
end
|
40
52
|
end
|
41
53
|
|
42
54
|
def double_click(element)
|
55
|
+
start = Time.now
|
43
56
|
foundElement = find_object(element)
|
44
57
|
if foundElement != nil
|
45
58
|
begin
|
46
59
|
foundElement.double_click
|
60
|
+
print_log("passed", start, __method__, element)
|
47
61
|
rescue StandardError => e
|
48
|
-
|
62
|
+
print_log("failed", start, __method__, element)
|
63
|
+
raise "Error: #{e.message}"
|
49
64
|
end
|
50
65
|
else
|
51
|
-
|
66
|
+
print_log("failed", start, __method__, element)
|
67
|
+
raise "Error: Not found object: #{element}"
|
52
68
|
end
|
53
69
|
end
|
54
70
|
|
55
71
|
def execute_settext(element, text)
|
72
|
+
start = Time.now
|
56
73
|
foundElement = find_object(element)
|
57
74
|
if foundElement != nil
|
58
75
|
begin
|
59
76
|
foundElement.set(text)
|
77
|
+
print_log("passed", start, __method__, element, text)
|
60
78
|
rescue StandardError => e
|
61
|
-
|
79
|
+
print_log("failed", start, __method__, element, text)
|
80
|
+
raise "Error: #{e.message}"
|
62
81
|
end
|
63
82
|
else
|
64
|
-
|
83
|
+
print_log("failed", start, __method__, element, text)
|
84
|
+
raise "Error: Not found object: #{element}"
|
65
85
|
end
|
66
86
|
end
|
67
87
|
|
68
88
|
def maximize_browser
|
89
|
+
start = Time.now
|
69
90
|
begin
|
70
91
|
page.driver.browser.manage.window.maximize
|
92
|
+
print_log("passed", start, __method__)
|
71
93
|
rescue StandardError => e
|
72
|
-
|
94
|
+
print_log("failed", start, __method__)
|
95
|
+
raise "Error: #{e.message}"
|
73
96
|
end
|
74
97
|
end
|
75
98
|
|
76
99
|
def switch_to_window_by_title(window_title)
|
100
|
+
start = Time.now
|
77
101
|
$previous_window = page.driver.browser.window_handle
|
78
102
|
@window_found = false
|
79
103
|
page.driver.browser.window_handles.each { |handle|
|
80
104
|
page.driver.browser.switch_to.window handle
|
81
105
|
if page.title == window_title
|
82
106
|
@window_found = true
|
107
|
+
print_log("passed", start, __method__, window_title)
|
83
108
|
break
|
84
109
|
end
|
85
110
|
}
|
86
111
|
if @window_found == false
|
87
|
-
|
112
|
+
print_log("failed", start, __method__, window_title)
|
113
|
+
raise "Error: Window having title \"#{window_title}\" not found"
|
88
114
|
end
|
89
115
|
end
|
90
116
|
|
91
117
|
def scroll_to_end_page
|
118
|
+
start = Time.now
|
92
119
|
begin
|
93
|
-
page.driver.execute_script(
|
120
|
+
page.driver.execute_script("window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));")
|
121
|
+
print_log("passed", start, __method__)
|
94
122
|
rescue StandardError => e
|
95
|
-
|
123
|
+
print_log("failed", start, __method__)
|
124
|
+
raise "Error: #{e.message}"
|
96
125
|
end
|
97
126
|
end
|
98
127
|
|
99
128
|
def scroll_to_top_page
|
129
|
+
start = Time.now
|
100
130
|
begin
|
101
|
-
page.driver.execute_script(
|
131
|
+
page.driver.execute_script("window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);")
|
132
|
+
print_log("passed", start, __method__)
|
102
133
|
rescue StandardError => e
|
103
|
-
|
134
|
+
print_log("failed", start, __method__)
|
135
|
+
raise "Error: #{e.message}"
|
104
136
|
end
|
105
137
|
end
|
106
138
|
|
107
139
|
def verify_title(expected_title)
|
140
|
+
start = Time.now
|
108
141
|
begin
|
109
142
|
page_title = page.title
|
110
|
-
puts "Actual Page Title : #{page_title}, Expected Page Title : #{expected_title}"
|
111
143
|
expect(page_title).to eq expected_title
|
144
|
+
print_log("passed", start, __method__, expected_title)
|
145
|
+
puts "Actual Page Title : #{page_title}, Expected Page Title : #{expected_title}"
|
112
146
|
rescue StandardError => e
|
113
|
-
|
147
|
+
print_log("failed", start, __method__, expected_title)
|
148
|
+
raise "Error: #{e.message}"
|
114
149
|
end
|
115
150
|
end
|
116
151
|
|
117
152
|
def verify_alert_text(text)
|
153
|
+
start = Time.now
|
118
154
|
begin
|
119
155
|
alert = page.driver.browser.switch_to.alert.text
|
120
|
-
puts "Actual Page alert text : #{alert}, Expected value : #{text}"
|
121
156
|
expect(alert).to eq text
|
157
|
+
print_log("passed", start, __method__, text)
|
158
|
+
puts "Actual Page alert text : #{alert}, Expected value : #{text}"
|
122
159
|
rescue StandardError => e
|
123
|
-
|
160
|
+
print_log("failed", start, __method__, text)
|
161
|
+
raise "Error: #{e.message}"
|
124
162
|
end
|
125
163
|
end
|
126
164
|
|
127
165
|
def accept_alert
|
166
|
+
start = Time.now
|
128
167
|
begin
|
129
168
|
page.driver.browser.switch_to.alert.accept
|
169
|
+
print_log("passed", start, __method__)
|
130
170
|
rescue Exception => e
|
131
|
-
|
171
|
+
print_log("failed", start, __method__)
|
172
|
+
raise "Error: #{e.message}"
|
132
173
|
end
|
133
174
|
end
|
134
175
|
|
135
176
|
def back
|
177
|
+
start = Time.now
|
136
178
|
begin
|
137
|
-
page.execute_script(
|
179
|
+
page.execute_script("window.history.back()")
|
180
|
+
print_log("passed", start, __method__)
|
138
181
|
rescue Exception => e
|
139
|
-
|
182
|
+
print_log("failed", start, __method__)
|
183
|
+
raise "Error: #{e.message}"
|
140
184
|
end
|
141
185
|
end
|
142
186
|
|
143
187
|
def refresh
|
188
|
+
start = Time.now
|
144
189
|
begin
|
145
|
-
page.execute_script(
|
190
|
+
page.execute_script("window.location.reload()")
|
191
|
+
print_log("passed", start, __method__)
|
146
192
|
rescue Exception => e
|
147
|
-
|
193
|
+
print_log("failed", start, __method__)
|
194
|
+
raise "Error: #{e.message}"
|
148
195
|
end
|
149
196
|
end
|
150
197
|
|
151
198
|
def clear_text(element)
|
199
|
+
start = Time.now
|
152
200
|
foundElement = find_object(element)
|
153
201
|
if foundElement != nil?
|
154
202
|
begin
|
155
203
|
foundElement.native.clear
|
204
|
+
print_log("passed", start, __method__, element)
|
156
205
|
rescue Exception => e
|
157
|
-
|
206
|
+
print_log("failed", start, __method__, element)
|
207
|
+
raise "Error: #{e.message}"
|
158
208
|
end
|
159
209
|
else
|
160
|
-
|
210
|
+
print_log("failed", start, __method__, element)
|
211
|
+
raise "Error: Not found object: #{element}"
|
161
212
|
end
|
162
213
|
end
|
163
214
|
|
164
215
|
def execute_javascript(script)
|
216
|
+
start = Time.now
|
165
217
|
begin
|
166
218
|
page.execute_script(script)
|
219
|
+
print_log("passed", start, __method__, script)
|
167
220
|
rescue Exception => e
|
168
|
-
|
221
|
+
print_log("failed", start, __method__, script)
|
222
|
+
raise "Error: Not found object: #{element}"
|
169
223
|
end
|
170
224
|
end
|
171
225
|
|
172
226
|
def execute_select(element, option)
|
227
|
+
start = Time.now
|
173
228
|
foundElement = find_object(element)
|
174
229
|
if foundElement != nil
|
175
230
|
begin
|
176
|
-
foundElement.find(
|
231
|
+
foundElement.find("option", text: option).select_option
|
232
|
+
print_log("passed", start, __method__, element, option)
|
177
233
|
rescue Exception => e
|
178
|
-
|
234
|
+
print_log("failed", start, __method__, element, option)
|
235
|
+
raise "Error: #{e.message}"
|
179
236
|
end
|
180
237
|
else
|
181
|
-
|
238
|
+
print_log("failed", start, __method__, element, option)
|
239
|
+
raise "Error: Not found object: #{element}"
|
182
240
|
end
|
183
241
|
end
|
184
242
|
|
185
243
|
def execute_mouse_over(element)
|
244
|
+
start = Time.now
|
186
245
|
foundElement = find_object(element)
|
187
246
|
if foundElement != nil
|
188
247
|
begin
|
189
248
|
page.driver.browser.action.move_to(foundElement.native, element).click.perform
|
249
|
+
print_log("passed", start, __method__, element)
|
190
250
|
sleep(1)
|
191
251
|
rescue StandardError => e
|
192
|
-
|
252
|
+
print_log("failed", start, __method__, element)
|
253
|
+
raise "Error: #{e.message}"
|
193
254
|
end
|
194
255
|
else
|
195
|
-
|
256
|
+
print_log("failed", start, __method__, element)
|
257
|
+
raise "Error: Not found object: #{element}"
|
196
258
|
end
|
197
259
|
end
|
198
260
|
|
199
261
|
def remove_element_attribute(element, attr)
|
262
|
+
start = Time.now
|
200
263
|
foundElement = find_object(element)
|
201
264
|
if foundElement != nil
|
202
265
|
begin
|
203
266
|
page.driver.browser.execute_script("arguments[0].removeAttribute('#{attr}');", foundElement.native)
|
267
|
+
print_log("passed", start, __method__, element, attr)
|
204
268
|
sleep(1)
|
205
269
|
rescue StandardError => e
|
206
|
-
|
270
|
+
print_log("failed", start, __method__, element, attr)
|
271
|
+
raise "Error: #{e.message}"
|
207
272
|
end
|
208
273
|
else
|
209
|
-
|
274
|
+
print_log("failed", start, __method__, element, attr)
|
275
|
+
raise "Error: Not found object: #{element}"
|
210
276
|
end
|
211
277
|
end
|
212
278
|
|
213
279
|
# Set state
|
214
280
|
def execute_setstate(element, state)
|
281
|
+
start = Time.now
|
215
282
|
foundElement = find_object(element)
|
216
283
|
if foundElement != nil
|
217
284
|
if state
|
@@ -219,164 +286,189 @@ def execute_setstate(element, state)
|
|
219
286
|
else
|
220
287
|
foundElement.unselect_option
|
221
288
|
end
|
289
|
+
print_log("passed", start, __method__, element, state)
|
222
290
|
else
|
223
|
-
|
291
|
+
print_log("failed", start, __method__, element, state)
|
292
|
+
raise "Error: Not found object: #{element}"
|
224
293
|
end
|
225
294
|
end
|
226
295
|
|
227
296
|
def close_windows
|
297
|
+
start = Time.now
|
228
298
|
begin
|
229
299
|
page.execute_script "window.close();"
|
300
|
+
print_log("passed", start, __method__)
|
230
301
|
rescue StandardError => e
|
231
|
-
|
302
|
+
print_log("failed", start, __method__)
|
303
|
+
raise "Error: #{e.message}"
|
232
304
|
end
|
233
305
|
end
|
234
306
|
|
235
307
|
def resize_window_screen(x, y)
|
308
|
+
start = Time.now
|
236
309
|
begin
|
237
310
|
page.driver.browser.manage.window.resize_to(x, y)
|
238
|
-
|
311
|
+
print_log("passed", start, __method__, x, y)
|
239
312
|
rescue StandardError => e
|
240
|
-
|
313
|
+
print_log("failed", start, __method__, x, y)
|
314
|
+
raise "Error: #{e.message}"
|
241
315
|
end
|
242
316
|
end
|
243
317
|
|
244
318
|
def switch_to_iframe(element)
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
319
|
+
start = Time.now
|
320
|
+
foundElement = find_object(element)
|
321
|
+
if foundElement != nil
|
322
|
+
begin
|
323
|
+
page.driver.switch_to_frame(foundElement)
|
324
|
+
print_log("passed", start, __method__, element)
|
325
|
+
rescue Exception => e
|
326
|
+
print_log("failed", start, __method__, element)
|
327
|
+
raise "Error: #{e.message}"
|
328
|
+
end
|
329
|
+
else
|
330
|
+
print_log("failed", start, __method__, element)
|
331
|
+
raise "Error: Not found object #{element}"
|
250
332
|
end
|
251
333
|
end
|
252
334
|
|
253
335
|
def switch_out_frame
|
336
|
+
start = Time.now
|
254
337
|
begin
|
255
338
|
browser = page.driver.browser
|
256
339
|
browser.switch_to.default_content
|
340
|
+
print_log("passed", start, __method__)
|
257
341
|
rescue Exception => e
|
258
|
-
|
342
|
+
print_log("failed", start, __method__)
|
343
|
+
raise "Error: #{e.message}"
|
259
344
|
end
|
260
345
|
end
|
261
346
|
|
262
347
|
def get_computed_style(element, style)
|
348
|
+
start = Time.now
|
263
349
|
foundElement = get_object_value(element)
|
264
350
|
computedStyle = ""
|
265
351
|
if foundElement != nil
|
266
352
|
computedStyle = page.evaluate_script("window.getComputedStyle(document.querySelector('#{foundElement}')).#{style}")
|
267
353
|
else
|
268
|
-
|
354
|
+
print_log("failed", start, __method__, element, style)
|
355
|
+
raise "Error: Not found object: #{element}"
|
269
356
|
end
|
270
|
-
|
357
|
+
print_log("passed", start, __method__, element, style)
|
358
|
+
puts "Actual object style value is: #{computedStyle}"
|
271
359
|
computedStyle
|
272
360
|
end
|
273
361
|
|
274
|
-
def put_log str
|
275
|
-
p str if $print_log == true
|
276
|
-
end
|
277
|
-
|
278
|
-
def get_object_value(str_obj)
|
279
|
-
string_object = str_obj.gsub(/"/, "'")
|
280
|
-
hash_object = $OBJECT[string_object]
|
281
|
-
if hash_object == nil
|
282
|
-
raise ">>> OBJECT: #{str_obj} NAME MAYBE NOT FOUND!!!"
|
283
|
-
end
|
284
|
-
if hash_object.keys[0].to_s.upcase != "CSS_SELECTOR"
|
285
|
-
raise ">>> OBJECT: #{str_obj} should be formatted as Css Selector."
|
286
|
-
end
|
287
|
-
hash_object[hash_object.keys[0]]
|
288
|
-
end
|
289
|
-
|
290
362
|
def get_element_text(element)
|
363
|
+
start = Time.now
|
291
364
|
foundElement = find_object(element)
|
292
365
|
if foundElement != nil
|
293
366
|
begin
|
294
367
|
result = foundElement.text()
|
368
|
+
print_log("passed", start, __method__, element, style)
|
295
369
|
puts "Text of #{element}: #{result}"
|
296
370
|
rescue StandardError => e
|
297
|
-
|
371
|
+
print_log("failed", start, __method__, element)
|
372
|
+
raise "Error: #{e.message}"
|
298
373
|
end
|
299
374
|
else
|
300
|
-
|
375
|
+
print_log("failed", start, __method__, element)
|
376
|
+
raise "Error: Not found object: #{element}"
|
301
377
|
end
|
302
378
|
end
|
303
379
|
|
304
|
-
def get_element_attribute(element,value)
|
380
|
+
def get_element_attribute(element, value)
|
381
|
+
start = Time.now
|
305
382
|
foundElement = find_object(element)
|
306
383
|
if foundElement != nil
|
307
384
|
begin
|
308
385
|
result = foundElement.value()
|
386
|
+
print_log("passed", start, __method__, element, value)
|
309
387
|
puts "Attribute of #{element}: #{result}"
|
310
388
|
rescue StandardError => e
|
311
|
-
|
389
|
+
print_log("failed", start, __method__, element, value)
|
390
|
+
raise "Error: #{e.message}"
|
312
391
|
end
|
313
392
|
else
|
314
|
-
|
393
|
+
print_log("failed", start, __method__, element, value)
|
394
|
+
raise "Error: Not found object: #{element}"
|
315
395
|
end
|
316
396
|
end
|
317
397
|
|
318
|
-
def verify_element_text(element,value)
|
398
|
+
def verify_element_text(element, value)
|
399
|
+
start = Time.now
|
319
400
|
foundElement = find_object(element)
|
320
401
|
if foundElement != nil
|
321
402
|
begin
|
322
403
|
actual_value = foundElement.text()
|
323
|
-
put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
|
324
404
|
expect(actual_value).to eq value
|
405
|
+
print_log("passed", start, __method__, element, value)
|
325
406
|
rescue Exception => e
|
326
|
-
|
407
|
+
print_log("failed", start, __method__, element, value)
|
408
|
+
raise "Error: #{e.message}"
|
327
409
|
end
|
328
410
|
else
|
329
|
-
|
411
|
+
print_log("failed", start, __method__, element, value)
|
412
|
+
raise "Error: Not found object: #{element}"
|
330
413
|
end
|
331
414
|
end
|
332
415
|
|
333
|
-
def verify_element_not_has_text(element,value)
|
416
|
+
def verify_element_not_has_text(element, value)
|
417
|
+
start = Time.now
|
334
418
|
foundElement = find_object(element)
|
335
419
|
if foundElement != nil
|
336
420
|
begin
|
337
421
|
actual_value = foundElement.text()
|
338
|
-
put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
|
339
422
|
expect(actual_value).not_to eql value
|
423
|
+
print_log("passed", start, __method__, element, value)
|
340
424
|
rescue Exception => e
|
341
|
-
|
425
|
+
print_log("failed", start, __method__, element, value)
|
426
|
+
raise "Error: #{e.message}"
|
342
427
|
end
|
343
|
-
|
344
428
|
else
|
345
|
-
|
429
|
+
print_log("failed", start, __method__, element, value)
|
430
|
+
raise "Error: Not found object: #{element}"
|
346
431
|
end
|
347
432
|
end
|
348
433
|
|
349
|
-
def verify_element_value(element,value)
|
434
|
+
def verify_element_value(element, value)
|
435
|
+
start = Time.now
|
350
436
|
foundElement = find_object(element)
|
351
437
|
if foundElement != nil
|
352
438
|
begin
|
353
439
|
actual_value = foundElement.value()
|
354
|
-
put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
|
355
440
|
expect(actual_value).to eq value
|
441
|
+
print_log("passed", start, __method__, element, value)
|
356
442
|
rescue Exception => e
|
357
|
-
|
443
|
+
print_log("failed", start, __method__, element, value)
|
444
|
+
raise "Error: #{e.message}"
|
358
445
|
end
|
359
446
|
else
|
360
|
-
|
447
|
+
print_log("failed", start, __method__, element, value)
|
448
|
+
raise "Error: Not found object: #{element}"
|
361
449
|
end
|
362
450
|
end
|
363
451
|
|
364
|
-
def verify_element_not_has_value(element,value)
|
452
|
+
def verify_element_not_has_value(element, value)
|
453
|
+
start = Time.now
|
365
454
|
foundElement = find_object(element)
|
366
455
|
if foundElement != nil
|
367
456
|
begin
|
368
457
|
actual_value = foundElement.value()
|
369
|
-
put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
|
370
458
|
expect(actual_value).not_to eql value
|
459
|
+
print_log("passed", start, __method__, element, value)
|
371
460
|
rescue Exception => e
|
372
|
-
|
461
|
+
print_log("failed", start, __method__, element, value)
|
462
|
+
raise "Error: #{e.message}"
|
373
463
|
end
|
374
464
|
else
|
375
|
-
|
465
|
+
print_log("failed", start, __method__, element, value)
|
466
|
+
raise "Error: Not found object: #{element}"
|
376
467
|
end
|
377
468
|
end
|
378
469
|
|
379
|
-
def execute_checkproperty(element, property, negate, value, isSpecialChar=false)
|
470
|
+
def execute_checkproperty(element, property, negate, value, isSpecialChar = false)
|
471
|
+
start = Time.now
|
380
472
|
validate_option_by(property)
|
381
473
|
Capybara.configure do |config|
|
382
474
|
config.ignore_hidden_elements = false
|
@@ -389,24 +481,21 @@ def execute_checkproperty(element, property, negate, value, isSpecialChar=false)
|
|
389
481
|
# check.should eq true
|
390
482
|
expect(check).to eq true
|
391
483
|
else
|
392
|
-
# put_log "\n\n\t>>> execute_checkproperty: finish to found element"
|
393
484
|
if foundElement != nil
|
394
|
-
|
395
|
-
if property.upcase == 'VALUE'
|
485
|
+
if property.upcase == "VALUE"
|
396
486
|
actual_value = foundElement.value()
|
397
|
-
|
398
|
-
elsif property.upcase == 'TEXT'
|
487
|
+
elsif property.upcase == "TEXT"
|
399
488
|
actual_value = foundElement.text()
|
400
|
-
|
401
489
|
else
|
402
490
|
actual_value = foundElement["#{property}"]
|
403
491
|
end
|
404
492
|
|
405
493
|
if actual_value == nil
|
406
|
-
actual_value =
|
494
|
+
actual_value = ""
|
407
495
|
end
|
408
496
|
else
|
409
|
-
|
497
|
+
print_log("failed", start, __method__, element, property, negate, value, isSpecialChar)
|
498
|
+
raise "Error: Not found object: #{element}"
|
410
499
|
end
|
411
500
|
|
412
501
|
Capybara.configure do |config|
|
@@ -417,585 +506,80 @@ def execute_checkproperty(element, property, negate, value, isSpecialChar=false)
|
|
417
506
|
# check = true
|
418
507
|
# end
|
419
508
|
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
expect(actual_value).to eq value
|
427
|
-
end
|
428
|
-
end
|
429
|
-
end
|
430
|
-
|
431
|
-
def check_valid_option_by?(option_by)
|
432
|
-
%w(text value).include? option_by
|
433
|
-
end
|
434
|
-
|
435
|
-
def validate_option_by(option_by)
|
436
|
-
raise "Please select valid option, invalid option - #{option_by}" unless check_valid_option_by? option_by
|
437
|
-
end
|
438
|
-
|
439
|
-
def check_valid_keys?(key)
|
440
|
-
%w(:cancel :help :backspace :tab :clear :return :enter :shift :control :alt :pause :escape :space :page_up :page_down :end :home :left :up :right :down :insert :delete :semicolon :equals).include? key
|
441
|
-
end
|
442
|
-
|
443
|
-
def validate_supported_keys(key)
|
444
|
-
raise "Please select valid keys, invalid key - #{key}" unless check_valid_option_by? key
|
445
|
-
end
|
446
|
-
|
447
|
-
def find_object string_object
|
448
|
-
startTime = Time.new.to_i
|
449
|
-
string_object = string_object.gsub(/"/, "'")
|
450
|
-
locator_matching = /(.*?)(\{.*?\})/.match(string_object)
|
451
|
-
dyn_pros = {}
|
452
|
-
if locator_matching != nil
|
453
|
-
string_object = locator_matching[1]
|
454
|
-
eval(locator_matching[2].gsub(/['][\s,\t]*?:[\s,\t]*?[']?/, "'=>'")).each { |k, v|
|
455
|
-
dyn_pros[k.to_s.upcase] = v
|
456
|
-
}
|
457
|
-
end
|
458
|
-
hash_object = $OBJECT[string_object]
|
459
|
-
if hash_object == nil
|
460
|
-
raise "❌ ERROR: >>> Object: #{string_object} is not found in Object Repository."
|
461
|
-
end
|
462
|
-
upcase_attrb = {}
|
463
|
-
if hash_object != nil
|
464
|
-
hash_object.each {|k,v|
|
465
|
-
k = k.to_s.upcase
|
466
|
-
if k =~ /ph_/i
|
467
|
-
if dyn_pros[k] != nil
|
468
|
-
if v =~ /<ph_value>/i
|
469
|
-
upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
|
470
|
-
else
|
471
|
-
upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
|
472
|
-
end
|
473
|
-
dyn_pros.delete(k)
|
474
|
-
end
|
475
|
-
else
|
476
|
-
upcase_attrb[k.to_s.upcase] = v
|
477
|
-
end
|
478
|
-
}
|
479
|
-
end
|
480
|
-
ph_attrs = {}
|
481
|
-
dyn_pros.each{|k,v|
|
482
|
-
if k =~ /ph_/i
|
483
|
-
ph_attrs[k] = v
|
484
|
-
else
|
485
|
-
upcase_attrb[k.to_s.upcase] = v
|
486
|
-
end
|
487
|
-
}
|
488
|
-
if upcase_attrb.size > 0
|
489
|
-
strId = ""
|
490
|
-
strClass = ""
|
491
|
-
strName = ""
|
492
|
-
strTagname = ""
|
493
|
-
strCssSelector = ""
|
494
|
-
strXpathSelector = ""
|
495
|
-
strText = ""
|
496
|
-
strRelated = ""
|
497
|
-
strRelatedType = ""
|
498
|
-
|
499
|
-
index = nil
|
500
|
-
minWidth = -1
|
501
|
-
maxWidth = -1
|
502
|
-
minHeight = -1
|
503
|
-
maxHeight = -1
|
504
|
-
|
505
|
-
ano_pros = {}
|
506
|
-
|
507
|
-
upcase_attrb.each{|key, value|
|
508
|
-
upcase_key = key.to_s.upcase
|
509
|
-
case upcase_key
|
510
|
-
when "XPATH_SELECTOR"
|
511
|
-
strXpathSelector = value
|
512
|
-
when "CSS_SELECTOR"
|
513
|
-
strCssSelector = value
|
514
|
-
when "ID"
|
515
|
-
strId = value
|
516
|
-
when "CLASS"
|
517
|
-
strClass = value
|
518
|
-
when "NAME"
|
519
|
-
strName = value
|
520
|
-
when "TAGNAME"
|
521
|
-
strTagname = value
|
522
|
-
when "TEXT"
|
523
|
-
strText = value
|
524
|
-
when "INDEX"
|
525
|
-
index = value
|
526
|
-
else
|
527
|
-
raise "ERROR: >>> Wrong format type: #{key.to_s} of object: #{string_object}. Available supported format are: XPATH_SELECTOR | CSS_SELECTOR | ID | NAME | CLASS | TEXT | TAGNAME | INDEX"
|
528
|
-
end
|
529
|
-
}
|
530
|
-
continue_run = true;
|
531
|
-
ref_object = nil;
|
532
|
-
|
533
|
-
if strRelated != nil and strRelated.length > 0
|
534
|
-
ref_object = find_object(strRelated)
|
535
|
-
if (ref_object == nil)
|
536
|
-
continue_run = false
|
537
|
-
end
|
538
|
-
end
|
539
|
-
|
540
|
-
if continue_run == true
|
541
|
-
begin
|
542
|
-
if strCssSelector != nil and strCssSelector.length > 0
|
543
|
-
foundElements = get_objects_by_css_selector(strCssSelector)
|
544
|
-
elsif strXpathSelector != nil and strXpathSelector.length > 0
|
545
|
-
foundElements = get_objects_by_xpath_selector(strXpathSelector)
|
546
|
-
else
|
547
|
-
strGenerateXpathSel = generate_xpath_selector(strId, strClass, strName, strTagname)
|
548
|
-
if strGenerateXpathSel.length > 0
|
549
|
-
foundElements = get_objects_by_xpath_selector(strGenerateXpathSel)
|
550
|
-
else
|
551
|
-
if (check_string_letters_only(strId))
|
552
|
-
foundElements = get_objects_by_Id(strId)
|
553
|
-
elsif (check_string_letters_only(strName))
|
554
|
-
foundElements = get_objects_by_Name(strName)
|
555
|
-
elsif (check_string_letters_only(strClass))
|
556
|
-
foundElements = get_objects_by_Class(strClass)
|
557
|
-
elsif (check_string_letters_only(strTagname))
|
558
|
-
foundElements = get_objects_by_Tagname(strTagname)
|
559
|
-
end
|
560
|
-
end
|
561
|
-
end
|
562
|
-
if foundElements == nil or foundElements.length == 0
|
563
|
-
currentTime = Time.new.to_i
|
564
|
-
else
|
565
|
-
break
|
566
|
-
end
|
567
|
-
test = currentTime - startTime
|
568
|
-
puts "\n Finding the object #{string_object}... TIME-OUT:: #{test} < #{$wait_time}"
|
569
|
-
sleep(0.5)
|
570
|
-
end while (currentTime - startTime) < $wait_time
|
571
|
-
|
572
|
-
if foundElements != nil or foundElements.length != 0
|
573
|
-
if index != nil and index.to_i >= 0
|
574
|
-
matched_index = 0;
|
575
|
-
return_element = nil
|
576
|
-
foundElements.each{|cur_element|
|
577
|
-
passCheck = find_object_check_object(cur_element, ref_object, strRelatedType, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
|
578
|
-
if passCheck
|
579
|
-
if matched_index == index.to_i
|
580
|
-
return_element = cur_element
|
581
|
-
break
|
582
|
-
else
|
583
|
-
matched_index = matched_index + 1
|
584
|
-
end
|
585
|
-
end
|
586
|
-
}
|
587
|
-
return return_element
|
588
|
-
else
|
589
|
-
return_element = nil
|
590
|
-
foundElements.each{|cur_element|
|
591
|
-
passCheck = find_object_check_object(cur_element, ref_object, strRelatedType, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
|
592
|
-
if passCheck
|
593
|
-
return_element = cur_element
|
594
|
-
break
|
595
|
-
end
|
596
|
-
}
|
597
|
-
return return_element
|
598
|
-
end # if index != nil and index.to_i >= 0
|
599
|
-
end #if foundElements != nil or foundElements.length != 0
|
600
|
-
end #if continue = true
|
601
|
-
end
|
602
|
-
return nil
|
603
|
-
end
|
604
|
-
|
605
|
-
def generate_xpath_selector(strId, strClass, strName, strTagname)
|
606
|
-
strGenerateXpathSel = ""
|
607
|
-
if strId != nil and strId.length > 0 and (strId =~ /^#/) == nil
|
608
|
-
strGenerateXpathSel = "[@id='#{strId}']"
|
609
|
-
end
|
610
|
-
if strClass != nil and strClass.length > 0 and (strClass =~ /^#/) == nil
|
611
|
-
strGenerateXpathSel = "#{strGenerateXpathSel}[@class='#{strClass}']"
|
612
|
-
end
|
613
|
-
if strName != nil and strName.length > 0 and (strName =~ /^#/) == nil
|
614
|
-
strGenerateXpathSel = "#{strGenerateXpathSel}[@name='#{strName}']"
|
615
|
-
end
|
616
|
-
|
617
|
-
if strGenerateXpathSel.length > 0
|
618
|
-
if strTagname != nil and strTagname.length > 0
|
619
|
-
strGenerateXpathSel = "//#{strTagname}#{strGenerateXpathSel}"
|
620
|
-
else
|
621
|
-
strGenerateXpathSel = "//*#{strGenerateXpathSel}"
|
622
|
-
end
|
623
|
-
end
|
624
|
-
|
625
|
-
return strGenerateXpathSel
|
626
|
-
end
|
627
|
-
|
628
|
-
def check_string_letters_only(strToCheck)
|
629
|
-
if strToCheck != nil and strToCheck.length > 0 and strToCheck =~ /^[a-zA-Z]+$/
|
630
|
-
return true
|
631
|
-
end
|
632
|
-
return false
|
633
|
-
end
|
634
|
-
|
635
|
-
def get_objects_by_Id(strId)
|
636
|
-
foundElements = nil
|
637
|
-
begin
|
638
|
-
foundElements = page.all("*[@id='#{strId}']")
|
639
|
-
rescue StandardError => e
|
640
|
-
raise "❌ Error: #{e}"
|
641
|
-
end
|
642
|
-
|
643
|
-
return foundElements
|
644
|
-
end
|
645
|
-
|
646
|
-
def get_objects_by_Class(strClass)
|
647
|
-
foundElements = nil
|
648
|
-
begin
|
649
|
-
foundElements = page.all("*[@class='#{strClass}']")
|
650
|
-
rescue StandardError => e
|
651
|
-
raise "❌ Error: #{e}"
|
652
|
-
end
|
653
|
-
|
654
|
-
return foundElements
|
655
|
-
end
|
656
|
-
|
657
|
-
def get_objects_by_Name(strName)
|
658
|
-
foundElements = nil
|
659
|
-
begin
|
660
|
-
foundElements = page.all("*[@name='#{strName}']")
|
661
|
-
rescue StandardError => e
|
662
|
-
raise "❌ Error: #{e}"
|
663
|
-
end
|
664
|
-
|
665
|
-
return foundElements
|
666
|
-
end
|
667
|
-
|
668
|
-
def get_objects_by_Tagname(strTagname)
|
669
|
-
foundElements = nil
|
670
|
-
begin
|
671
|
-
foundElements = page.all("#{strTagname}")
|
672
|
-
rescue StandardError => e
|
673
|
-
raise "❌ Error: #{e}"
|
674
|
-
end
|
675
|
-
|
676
|
-
return foundElements
|
677
|
-
end
|
678
|
-
|
679
|
-
def get_objects_by_css_selector(strCssSelector)
|
680
|
-
foundElements = nil
|
681
|
-
begin
|
682
|
-
foundElements = page.all(:css, strCssSelector)
|
683
|
-
rescue StandardError => e
|
684
|
-
raise "❌ Error: #{e}"
|
685
|
-
end
|
686
|
-
foundElements
|
687
|
-
end
|
688
|
-
|
689
|
-
def get_objects_by_xpath_selector(strXpathSelector)
|
690
|
-
foundElements = nil
|
691
|
-
begin
|
692
|
-
foundElements = page.all(:xpath, strXpathSelector)
|
693
|
-
rescue StandardError => e
|
694
|
-
raise "❌ Error: #{e}"
|
695
|
-
end
|
696
|
-
foundElements
|
697
|
-
end
|
698
|
-
|
699
|
-
def find_object_check_object(cur_element, ref_object, ref_object_type, strId, strClass, strName, strTagname, strText, minWidth, maxWidth, minHeight, maxHeight, ano_pros)
|
700
|
-
passCheck = true
|
701
|
-
if cur_element != nil
|
702
|
-
# Check ref_object
|
703
|
-
if (ref_object != nil)
|
704
|
-
if find_object_check_ref_object(ref_object, ref_object_type, cur_element) == false
|
705
|
-
passCheck = false
|
706
|
-
end
|
707
|
-
end
|
708
|
-
|
709
|
-
# Check ID
|
710
|
-
if strId != nil and strId.length > 0
|
711
|
-
if strId =~ /^#/
|
712
|
-
strId = strId[1..-1]
|
713
|
-
end
|
714
|
-
if find_object_check_Id(cur_element, strId) == false
|
715
|
-
passCheck = false
|
716
|
-
end
|
717
|
-
end
|
718
|
-
|
719
|
-
# Check Class
|
720
|
-
if passCheck and strClass != nil and strClass.length > 0
|
721
|
-
if strClass =~ /^#/
|
722
|
-
strClass = strClass[1..-1]
|
723
|
-
end
|
724
|
-
if find_object_check_Class(cur_element, strClass) == false
|
725
|
-
passCheck = false
|
726
|
-
end
|
727
|
-
end
|
728
|
-
|
729
|
-
# Check Name
|
730
|
-
if passCheck and strName != nil and strName.length > 0
|
731
|
-
if strName =~ /^#/
|
732
|
-
strName = strName[1..-1]
|
733
|
-
end
|
734
|
-
if find_object_check_Name(cur_element, strName) == false
|
735
|
-
passCheck = false
|
736
|
-
end
|
737
|
-
end
|
738
|
-
|
739
|
-
# Check Tag name
|
740
|
-
if passCheck and strTagname != nil and strTagname.length > 0
|
741
|
-
if find_object_check_Tagname(cur_element, strTagname) == false
|
742
|
-
passCheck = false
|
743
|
-
end
|
744
|
-
end
|
745
|
-
|
746
|
-
# Check Text
|
747
|
-
if passCheck and strText != nil and strText.length > 0
|
748
|
-
if (strText =~ /^#/)
|
749
|
-
strText = strText[1..-1]
|
750
|
-
end
|
751
|
-
|
752
|
-
if find_object_check_Text(cur_element, strText) == false
|
753
|
-
passCheck = false
|
754
|
-
end
|
755
|
-
end
|
756
|
-
|
757
|
-
# Check minWidth
|
758
|
-
if passCheck and minWidth > 0
|
759
|
-
if !find_object_check_minWidth(cur_element, minWidth)
|
760
|
-
passCheck = false
|
761
|
-
end
|
762
|
-
end
|
763
|
-
|
764
|
-
# Check maxWidth
|
765
|
-
if passCheck and maxWidth > 0
|
766
|
-
if !find_object_check_maxWidth(cur_element, maxWidth)
|
767
|
-
passCheck = false
|
768
|
-
end
|
769
|
-
end
|
770
|
-
|
771
|
-
# Check minHeight
|
772
|
-
if passCheck and minHeight > 0
|
773
|
-
if !find_object_check_minHeight(cur_element, minHeight)
|
774
|
-
passCheck = false
|
775
|
-
end
|
776
|
-
end
|
777
|
-
|
778
|
-
# Check maxHeight
|
779
|
-
if passCheck and maxHeight > 0
|
780
|
-
if !find_object_check_maxHeight(cur_element, maxHeight)
|
781
|
-
passCheck = false
|
509
|
+
begin
|
510
|
+
if negate == " not"
|
511
|
+
actual_value.should_not eq value
|
512
|
+
expect(actual_value).not_to eql value
|
513
|
+
elsif actual_value.should eq value
|
514
|
+
expect(actual_value).to eq value
|
782
515
|
end
|
516
|
+
print_log("passed", start, __method__, element, property, negate, value, isSpecialChar)
|
517
|
+
rescue Exception => e
|
518
|
+
print_log("failed", start, __method__, element, property, negate, value, isSpecialChar)
|
519
|
+
raise "Error: #{e.message}"
|
783
520
|
end
|
784
|
-
|
785
|
-
# Check another properties
|
786
|
-
if passCheck and ano_pros.length > 0
|
787
|
-
ano_pros.each{|property, value|
|
788
|
-
if value =~ /^#/
|
789
|
-
value = value[1..-1]
|
790
|
-
end
|
791
|
-
if !find_object_check_property(cur_element, property, value)
|
792
|
-
passCheck = false
|
793
|
-
break
|
794
|
-
end
|
795
|
-
}
|
796
|
-
end
|
797
|
-
|
798
|
-
return passCheck
|
799
|
-
end
|
800
|
-
|
801
|
-
return false
|
802
|
-
end
|
803
|
-
|
804
|
-
def find_object_check_Id(element, strId)
|
805
|
-
actual_Id = element[:id]
|
806
|
-
if actual_Id != nil and actual_Id.length > 0
|
807
|
-
actual_Id = actual_Id.strip
|
808
|
-
if reg_compare(actual_Id, strId)
|
809
|
-
return true
|
810
|
-
end
|
811
|
-
end
|
812
|
-
|
813
|
-
return false
|
814
|
-
end
|
815
|
-
def find_object_check_Class(element, strClass)
|
816
|
-
actual_Class = element[:class]
|
817
|
-
if actual_Class != nil and actual_Class.length > 0
|
818
|
-
actual_Class = actual_Class.strip
|
819
|
-
if reg_compare(actual_Class, strClass)
|
820
|
-
return true
|
821
|
-
end
|
822
|
-
end
|
823
|
-
|
824
|
-
return false
|
825
|
-
end
|
826
|
-
def find_object_check_Name(element, strName)
|
827
|
-
actual_Name = element[:name]
|
828
|
-
if actual_Name != nil and actual_Name.length > 0
|
829
|
-
actual_Name = actual_Name.strip
|
830
|
-
if reg_compare(actual_Name, strName)
|
831
|
-
return true
|
832
|
-
end
|
833
|
-
end
|
834
|
-
|
835
|
-
return false
|
836
|
-
end
|
837
|
-
|
838
|
-
def find_object_check_Tagname(element, strTagname)
|
839
|
-
actual_Tagname = element.tag_name()
|
840
|
-
if actual_Tagname != nil and actual_Tagname.length > 0
|
841
|
-
actual_Tagname = actual_Tagname.strip
|
842
|
-
if reg_compare(actual_Tagname, strTagname)
|
843
|
-
return true
|
844
|
-
end
|
845
|
-
end
|
846
|
-
|
847
|
-
return false
|
848
|
-
end
|
849
|
-
def find_object_check_Xpath(element, strXpath)
|
850
|
-
|
851
|
-
end
|
852
|
-
def find_object_check_Text(element, strText)
|
853
|
-
actual_Text = element.text()
|
854
|
-
if actual_Text != nil and actual_Text.length > 0
|
855
|
-
actual_Text = actual_Text.strip
|
856
|
-
if reg_compare(actual_Text, strText)
|
857
|
-
return true
|
858
|
-
end
|
859
|
-
end
|
860
|
-
|
861
|
-
return false
|
862
|
-
end
|
863
|
-
def find_object_check_minWidth(element, minWidth)
|
864
|
-
width = element[:width]
|
865
|
-
if (width >= minWidth)
|
866
|
-
return true
|
867
|
-
end
|
868
|
-
|
869
|
-
return false
|
870
|
-
end
|
871
|
-
def find_object_check_maxWidth(element, maxWidth)
|
872
|
-
width = element[:width]
|
873
|
-
if (width <= maxWidth)
|
874
|
-
return true
|
875
|
-
end
|
876
|
-
|
877
|
-
return false
|
878
|
-
end
|
879
|
-
def find_object_check_minHeight(element, minHeight)
|
880
|
-
height = element[:height]
|
881
|
-
if (height <= minHeight)
|
882
|
-
return true
|
883
|
-
end
|
884
|
-
|
885
|
-
return false
|
886
|
-
end
|
887
|
-
def find_object_check_maxHeight(element, maxHeight)
|
888
|
-
height = element[:height]
|
889
|
-
if (height <= maxHeight)
|
890
|
-
return true
|
891
|
-
end
|
892
|
-
|
893
|
-
return false
|
894
|
-
end
|
895
|
-
|
896
|
-
def find_object_check_ref_object(ref_object, ref_type, target_element)
|
897
|
-
begin
|
898
|
-
ref = ref_object.native
|
899
|
-
target = target_element.native
|
900
|
-
if(ref_type == "up" or ref_type == "down")
|
901
|
-
ref_x1 = ref.location.x - 10
|
902
|
-
ref_x2 = ref.location.x + ref.size.width + 10
|
903
|
-
target_x1 = target.location.x
|
904
|
-
target_x2 = target_x1 + target.size.width
|
905
|
-
elsif(ref_type == "left" or ref_type == "right")
|
906
|
-
ref_y1 = ref.location.y - 10
|
907
|
-
ref_y2 = ref.location.y + ref_object.native.size.height + 10
|
908
|
-
target_y1 = target.location.y
|
909
|
-
target_y2 = target_y1 + target.size.height
|
910
|
-
elsif(ref_type == "child" or ref_type == "parent")
|
911
|
-
ref_W = ref.location.x + ref.size.width
|
912
|
-
ref_H = ref.location.y + ref.size.height
|
913
|
-
target_W = target.location.x + target.size.width
|
914
|
-
target_H = target.location.y + target.size.height
|
915
|
-
end
|
916
|
-
|
917
|
-
if(ref_type == "up" and
|
918
|
-
target_x1 > ref_x1 and target_x2 < ref_x2 and # has same column or X Position
|
919
|
-
target.location.y < ref.location.y) # at row or Y position, target is upper
|
920
|
-
return true
|
921
|
-
elsif(ref_type == "down" and
|
922
|
-
target_x1 > ref_x1 and target_x2 < ref_x2 and # has same column or X Position
|
923
|
-
target.location.y > ref.location.y) # at row or Y position, target is at down
|
924
|
-
return true
|
925
|
-
elsif(ref_type == "left" and
|
926
|
-
target.location.x < ref.location.x and # at column or X Position, target is at left
|
927
|
-
target_y1 > ref_y1 and target_y2 < ref_y2) # at row or Y position, target is same as ref object
|
928
|
-
return true
|
929
|
-
elsif(ref_type == "right" and
|
930
|
-
target.location.x > ref.location.x and # at column or X Position, target is at right
|
931
|
-
target_y1 > ref_y1 and target_y2 < ref_y2) # at row or Y position, target is same as ref object
|
932
|
-
return true
|
933
|
-
elsif(ref_type == "child" and
|
934
|
-
(target_W < ref_W) and (target_H < ref_H) and
|
935
|
-
(target.location.x > ref.location.x) and (target.location.y > ref.location.y))
|
936
|
-
return true
|
937
|
-
elsif(ref_type == "parent" and
|
938
|
-
(target_W > ref_W) and (target_H > ref_H) and
|
939
|
-
(target.location.x < ref.location.x) and (target.location.y < ref.location.y))
|
940
|
-
return true
|
941
|
-
end
|
942
|
-
rescue StandardError => e
|
943
|
-
puts "❌ Error: #{e}"
|
944
521
|
end
|
945
|
-
|
946
|
-
return false;
|
947
522
|
end
|
948
523
|
|
949
|
-
def get_object_and_store_as_string(object,string)
|
524
|
+
def get_object_and_store_as_string(object, string)
|
950
525
|
text = execute_gettext(object)
|
951
526
|
txt = "'" + text + "'"
|
952
527
|
set_var(string, txt)
|
953
528
|
end
|
954
529
|
|
955
|
-
|
956
|
-
def get_object_and_store_to_file(object,file_name)
|
530
|
+
def get_object_and_store_to_file(object, file_name)
|
957
531
|
$text = execute_gettext(object)
|
958
|
-
open($test_data_dir+file_name,
|
532
|
+
open($test_data_dir + file_name, "a+") do |f|
|
959
533
|
f << $text + "\n"
|
960
534
|
end
|
961
535
|
end
|
962
536
|
|
963
537
|
def drag_and_drop_by_offset(element, x, y)
|
538
|
+
start = Time.now
|
964
539
|
foundElement = find_object(element)
|
965
540
|
if foundElement != nil
|
966
541
|
begin
|
967
542
|
page.driver.browser.action.drag_and_drop_by(foundElement, x, y).perform
|
543
|
+
print_log("passed", start, __method__, element, x, y)
|
968
544
|
rescue Exception => e
|
969
|
-
|
545
|
+
print_log("failed", start, __method__, element, x, y)
|
546
|
+
raise "Error: #{e.message}"
|
970
547
|
end
|
971
548
|
else
|
972
|
-
|
549
|
+
print_log("failed", start, __method__, element, x, y)
|
550
|
+
raise "Error: Not found object: #{element}"
|
973
551
|
end
|
974
552
|
end
|
975
553
|
|
976
554
|
def drag_and_drop_to_object(from_element, element)
|
555
|
+
start = Time.now
|
977
556
|
found_from_element = find_object(from_element)
|
978
557
|
foundElement = find_object(element)
|
979
558
|
if foundElement != nil and found_from_element != nil
|
980
559
|
found_from_element.drag_to(foundElement)
|
560
|
+
print_log("passed", start, __method__, from_element, element)
|
981
561
|
end
|
982
562
|
end
|
983
563
|
|
984
564
|
def execute_sendkeys(element, key)
|
565
|
+
start = Time.now
|
985
566
|
validate_supported_keys(key)
|
986
567
|
foundElement = find_object(element)
|
987
568
|
if foundElement != nil
|
988
569
|
begin
|
989
570
|
foundElement.native.send_keys(key)
|
571
|
+
print_log("passed", start, __method__, element, key)
|
990
572
|
rescue Exception => e
|
991
|
-
|
573
|
+
print_log("failed", start, __method__, element, key)
|
574
|
+
raise "Error: #{e.message}"
|
992
575
|
end
|
993
576
|
else
|
994
|
-
|
577
|
+
print_log("failed", start, __method__, element, key)
|
578
|
+
raise "Error: Not found object: #{element}"
|
995
579
|
end
|
996
580
|
end
|
997
581
|
|
998
|
-
def movemouseandclick
|
582
|
+
def movemouseandclick(var, element)
|
999
583
|
Selenium::WebDriver::Support::Select.new(page.driver.browser.find_element(:id, "#{var}")).select_by(:text, "#{element}")
|
1000
584
|
page.driver.browser.find_element(:id, "#{var}").click
|
1001
585
|
end
|