Top Level Namespace
Defined Under Namespace
Modules: IFD_DBConnection, IfdAutomation
Classes: IFD_Assertion, IFD_Email, IFD_File, IFD_Rest, IFD_Soap, IFD_Ssh, Request, Utils
Instance Method Summary
collapse
-
#check_alert_text(text) ⇒ Object
-
#check_title(title, test_case) ⇒ Object
Method to verify title param 1 : String : expected title param 2 : Boolean : test case [true or flase].
-
#check_valid_option_by?(option_by) ⇒ Boolean
-
#double_click(element) ⇒ Object
-
#drag_drop(el, x, y) ⇒ Object
-
#execute_checkproperty(element, property, negate, value, isSpecialChar = false) ⇒ Object
-
#execute_click(element) ⇒ Object
-
#execute_gettext(element) ⇒ Object
-
#execute_mousehoverandclick(element) ⇒ Object
-
#execute_openbrowser(url_site) ⇒ Object
Open Browser with config-able maximize browser option.
-
#execute_select(element, text) ⇒ Object
-
#execute_setstate(element, state) ⇒ Object
-
#execute_settext(element, text) ⇒ Object
-
#find_object(string_object) ⇒ Object
-
#find_object_check_object(cur_element) ⇒ Object
-
#get_computed_style(element, style) ⇒ Object
-
#get_object_and_store_as_string(object, string) ⇒ Object
-
#get_object_and_store_to_file(object, file_name) ⇒ Object
-
#get_object_value(str_obj) ⇒ Object
-
#get_objects_by_css_selector(strCssSelector) ⇒ Object
-
#get_objects_by_xpath_selector(strXpathSelector) ⇒ Object
-
#maximize_browser ⇒ Object
-
#movemouseandclick(var, element) ⇒ Object
-
#put_log(str) ⇒ Object
-
#remove_element_attribute(element, attr) ⇒ Object
-
#resize_window_screen(x, y) ⇒ Object
-
#scroll_page(to) ⇒ Object
-
#switch_to_window_by_title(window_title) ⇒ Object
-
#validate_option_by(option_by) ⇒ Object
Instance Method Details
#check_alert_text(text) ⇒ Object
110
111
112
113
114
115
|
# File 'lib/helper/web_steps_helper.rb', line 110
def check_alert_text(text)
alert = page.driver.browser.switch_to.alert.text
if alert != text
raise "Text on alert pop up not matched, Actual Text : #{alert}, Expected Text : #{text}"
end
end
|
#check_title(title, test_case) ⇒ Object
Method to verify title param 1 : String : expected title param 2 : Boolean : test case [true or flase]
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/helper/web_steps_helper.rb', line 97
def check_title(title, test_case)
page_title = page.title
if test_case
if page_title != "#{title}"
raise "Page Title Not Matched, Actual Page Title : #{page_title}, Expected Page Title : #{title}"
end
else
if page_title == "#{title}"
raise "Page Title Matched, Actual Page Title: #{page_title}"
end
end
end
|
#check_valid_option_by?(option_by) ⇒ Boolean
254
255
256
|
# File 'lib/helper/web_steps_helper.rb', line 254
def check_valid_option_by?(option_by)
%w(text value).include? option_by
end
|
#double_click(element) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/helper/web_steps_helper.rb', line 37
def double_click(element)
foundElement = find_object(element)
if foundElement != nil
begin
page.driver.browser.action.double_click(foundElement.native)
rescue StandardError => myStandardError
raise "\n>>> Error: #{myStandardError}"
end
else
raise "\nError >> Not found object: #{element}"
exit
end
end
|
#drag_drop(el, x, y) ⇒ Object
422
423
424
425
|
# File 'lib/helper/web_steps_helper.rb', line 422
def drag_drop el, x, y
foundElement = page.driver.browser.find_element(css: "#{el}")
page.driver.browser.action.drag_and_drop_by(foundElement, x, y).perform
end
|
#execute_checkproperty(element, property, negate, value, isSpecialChar = false) ⇒ Object
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/helper/web_steps_helper.rb', line 202
def execute_checkproperty(element, property, negate, value, isSpecialChar=false)
validate_option_by(property)
Capybara.configure do |config|
config.ignore_hidden_elements = false
end
foundElement = find_object(element)
check = false
if foundElement == nil and value == ""
check = true
expect(check).to eq true
else
if foundElement != nil
if property.upcase == 'VALUE'
actual_value = foundElement.value()
elsif property.upcase == 'TEXT'
actual_value = foundElement.text()
else
actual_value = foundElement["#{property}"]
end
if actual_value == nil
actual_value = ''
end
else
put_log "\nError >> Not found object: #{element}"
end
Capybara.configure do |config|
config.ignore_hidden_elements = 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) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/helper/web_steps_helper.rb', line 19
def execute_click(element)
foundElement = find_object(element)
if foundElement != nil
page.driver.execute_script('window.focus();')
startTime = Time.new.to_i
begin
sleep(0.5)
currentTime = Time.new.to_i
end while (foundElement.native.enabled? == false and (currentTime - startTime) < $_CFWEB['Wait Time'])
page.driver.browser.execute_script("arguments[0].scrollIntoView(true);", foundElement.native)
page.driver.browser.action.move_to(foundElement.native, element).click.perform
else
raise "\nError >> Not found object: #{element}"
end
end
|
#execute_gettext(element) ⇒ Object
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
# File 'lib/helper/web_steps_helper.rb', line 263
def execute_gettext(element)
foundElement = find_object(element)
if foundElement != nil
tagname = foundElement.tag_name()
if tagname.upcase == 'SELECT'
else
actual_text = foundElement.text()
if (actual_text == nil or actual_text.length == 0) and (tagname.upcase == 'INPUT' or tagname.upcase == 'TEXTAREA')
actual_text = foundElement.value()
end
end
put_log "\nText is '" + actual_text + "' of object '" + element + "'"
$context_value = actual_text
else
put_log "\nError >> Not found object: #{element}"
exit
end
end
|
#execute_mousehoverandclick(element) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/helper/web_steps_helper.rb', line 131
def execute_mousehoverandclick(element)
foundElement = find_object(element)
if foundElement != nil
page.driver.browser.action.move_to(foundElement.native, element).click.perform
sleep(1)
else
put_log "\nError >> Not found object: #{element}"
end
end
|
#execute_openbrowser(url_site) ⇒ Object
Open Browser with config-able maximize browser option
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/helper/web_steps_helper.rb', line 3
def execute_openbrowser(url_site)
begin
if $_CFWEB['Maximize Browser'] == true
page.driver.browser.manage.window.maximize
end
rescue StandardError => myStandardError
raise "\n>>> Error: #{myStandardError}"
end
if url_site == ""
raise "\n>>> Error: Null web page URL."
else
visit(url_site)
end
end
|
#execute_select(element, text) ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/helper/web_steps_helper.rb', line 117
def execute_select(element, text)
foundElement = find_object(element)
if foundElement != nil
option_value = page.evaluate_script("$(\"##{foundElement[:id]} option:contains('#{text}')\").val()")
page.execute_script("$('##{foundElement[:id]}').val('#{option_value}')")
page.execute_script("$('##{foundElement[:id]}').trigger('liszt:updated').trigger('change')")
else
put_log "\nError >> Not found object: #{element}"
exit
end
end
|
#execute_setstate(element, state) ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'lib/helper/web_steps_helper.rb', line 151
def execute_setstate(element, state)
foundElement = find_object(element)
if foundElement != nil
if state.upcase == "TRUE"
foundElement.select_option
else
foundElement.unselect_option
end
else
put_log "\nError >> Not found object: #{element}"
exit
end
end
|
#execute_settext(element, text) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/helper/web_steps_helper.rb', line 51
def execute_settext(element, text)
foundElement = find_object(element)
if foundElement != nil
begin
foundElement.set(text)
rescue StandardError => myStandardError
raise "\n>>> Error: #{myStandardError}"
end
else
raise "\nError >> Not found object: #{element}"
exit
end
end
|
#find_object(string_object) ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
|
# File 'lib/helper/web_steps_helper.rb', line 284
def find_object(string_object)
startTime = Time.new.to_i
string_object = string_object.gsub(/"/, "'")
locator_matching = /(.*?)(\{.*?\})/.match(string_object)
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]
if hash_object == nil
raise "ERROR: >>> Object: #{string_object} is not found in Object Repository."
end
upcase_attrb = {}
if hash_object != nil
hash_object.each { |k, v|
k = k.to_s.upcase
if k =~ /ph_/i
if dyn_pros[k] != nil
if v =~ /<ph_value>/i
upcase_attrb[k[3..k.size-1]] = v.gsub(/<ph_value>/i, dyn_pros[k])
else
upcase_attrb[k[3..k.size-1]] = dyn_pros[k]
end
dyn_pros.delete(k)
end
else
upcase_attrb[k.to_s.upcase] = v
end
}
end
ph_attrs = {}
dyn_pros.each { |k, v|
if k =~ /ph_/i
ph_attrs[k] = v
else
upcase_attrb[k.to_s.upcase] = v
end
}
if upcase_attrb.size > 0
strCssSelector = ""
strXpathSelector = ""
upcase_attrb.each { |key, value|
upcase_key = key.to_s.upcase
case upcase_key
when "XPATH_SELECTOR"
strXpathSelector = value
when "CSS_SELECTOR"
strCssSelector = value
else
raise "ERROR: >>> Wrong format type: #{key.to_s} of object: #{string_object}. Available supported format are: XPATH_SELECTOR and CSS_SELECTOR"
end
}
begin
if strCssSelector != nil and strCssSelector.length > 0
foundElements = get_objects_by_css_selector(strCssSelector)
else
foundElements = get_objects_by_xpath_selector(strXpathSelector)
end
if foundElements == nil or foundElements.length == 0
currentTime = Time.new.to_i
else
put_log "\nBREAK!!!"
break
end
test = currentTime - startTime
put_log "\n#TIMEOUNT:#{test} < #{$_CFWEB['Wait Time']}"
sleep(0.5)
end while (currentTime - startTime) < $_CFWEB['Wait Time']
if foundElements != nil or foundElements.length != 0
return_element = nil
foundElements.each { |cur_element|
passCheck = find_object_check_object(cur_element)
if passCheck
return_element = cur_element
break
end
}
return return_element
end
end
nil
end
|
#find_object_check_object(cur_element) ⇒ Object
400
401
402
403
404
405
406
|
# File 'lib/helper/web_steps_helper.rb', line 400
def find_object_check_object(cur_element)
passCheck = true
if cur_element != nil
return passCheck
end
false
end
|
#get_computed_style(element, style) ⇒ Object
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/helper/web_steps_helper.rb', line 170
def get_computed_style(element, style)
foundElement = get_object_value(element)
computedStyle = ""
if foundElement != nil
computedStyle = page.evaluate_script(
"window.getComputedStyle(document.querySelector('#{foundElement}')).#{style}"
)
else
puts "\nError >> Not found object: #{element}"
end
puts "\nActual object style value is: #{computedStyle}"
computedStyle
end
|
#get_object_and_store_as_string(object, string) ⇒ Object
408
409
410
411
412
|
# File 'lib/helper/web_steps_helper.rb', line 408
def get_object_and_store_as_string(object,string)
text = execute_gettext(object)
txt = "'" + text + "'"
Utils.set_var(string, txt)
end
|
#get_object_and_store_to_file(object, file_name) ⇒ Object
415
416
417
418
419
420
|
# File 'lib/helper/web_steps_helper.rb', line 415
def get_object_and_store_to_file(object,file_name)
$text = execute_gettext(object)
open($test_data_dir+file_name, 'a+') do |f|
f << $text + "\n"
end
end
|
#get_object_value(str_obj) ⇒ Object
190
191
192
193
194
195
196
197
198
199
200
|
# File 'lib/helper/web_steps_helper.rb', line 190
def get_object_value(str_obj)
string_object = str_obj.gsub(/"/, "'")
hash_object = $OBJECT[string_object]
if hash_object == nil
raise ">>> OBJECT: #{str_obj} NAME MAYBE NOT FOUND!!!"
end
if hash_object.keys[0].to_s.upcase != "CSS_SELECTOR"
raise ">>> OBJECT: #{str_obj} should be formatted as Css Selector."
end
hash_object[hash_object.keys[0]]
end
|
#get_objects_by_css_selector(strCssSelector) ⇒ Object
379
380
381
382
383
384
385
386
387
388
|
# File 'lib/helper/web_steps_helper.rb', line 379
def get_objects_by_css_selector(strCssSelector)
foundElements = nil
begin
foundElements = page.all(:css, strCssSelector)
rescue StandardError => myStandardError
raise "\n>>> Error: #{myStandardError}"
end
foundElements
end
|
#get_objects_by_xpath_selector(strXpathSelector) ⇒ Object
390
391
392
393
394
395
396
397
398
|
# File 'lib/helper/web_steps_helper.rb', line 390
def get_objects_by_xpath_selector(strXpathSelector)
foundElements = nil
begin
foundElements = page.all(:xpath, strXpathSelector)
rescue StandardError => myStandardError
put_log "\n>>> Error: #{myStandardError}"
end
foundElements
end
|
#maximize_browser ⇒ Object
65
66
67
|
# File 'lib/helper/web_steps_helper.rb', line 65
def maximize_browser
page.driver.browser.manage.window.maximize
end
|
#movemouseandclick(var, element) ⇒ Object
427
428
429
430
|
# File 'lib/helper/web_steps_helper.rb', line 427
def movemouseandclick var, element
Selenium::WebDriver::Support::Select.new(page.driver.browser.find_element(:id, "#{var}")).select_by(:text, "#{element}")
page.driver.browser.find_element(:id, "#{var}").click
end
|
#put_log(str) ⇒ Object
186
187
188
|
# File 'lib/helper/web_steps_helper.rb', line 186
def put_log str
p str if $_CFWEB['Print Log'] == true
end
|
#remove_element_attribute(element, attr) ⇒ Object
141
142
143
144
145
146
147
148
|
# File 'lib/helper/web_steps_helper.rb', line 141
def remove_element_attribute(element, attr)
foundElement = find_object(element)
if foundElement != nil
page.driver.browser.execute_script("arguments[0].removeAttribute('#{attr}');", foundElement.native)
else
put_log "\nError >> Not found object: #{element}"
end
end
|
#resize_window_screen(x, y) ⇒ Object
165
166
167
168
|
# File 'lib/helper/web_steps_helper.rb', line 165
def resize_window_screen(x, y)
page.driver.browser.manage.window.resize_to(x, y)
puts page.driver.browser.manage.window.size
end
|
#scroll_page(to) ⇒ Object
84
85
86
87
88
89
90
91
92
|
# File 'lib/helper/web_steps_helper.rb', line 84
def scroll_page(to)
if to == 'end'
page.driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
elsif to == 'top'
page.driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
else
raise "Exception : Invalid Direction (only scroll \"top\" or \"end\")"
end
end
|
#switch_to_window_by_title(window_title) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/helper/web_steps_helper.rb', line 69
def switch_to_window_by_title(window_title)
$previous_window = page.driver.browser.window_handle
@window_found = false
page.driver.browser.window_handles.each { |handle|
page.driver.browser.switch_to.window handle
if page.title == window_title
@window_found = true
break
end
}
if @window_found == false
raise "Window having title \"#{window_title}\" not found"
end
end
|
#validate_option_by(option_by) ⇒ Object
258
259
260
|
# File 'lib/helper/web_steps_helper.rb', line 258
def validate_option_by(option_by)
raise "Please select valid option, invalid option - #{option_by}" unless check_valid_option_by? option_by
end
|