Top Level Namespace

Defined Under Namespace

Modules: IFD_DBConnection, IfdAutomation, StepFallback, ToleranceForSeleniumSyncIssues Classes: IFD_Assertion, IFD_Email, IFD_File, IFD_Rest, IFD_Soap, IFD_Ssh, Request, Utils

Instance Method Summary collapse

Instance Method Details

#accept_alertObject



146
147
148
149
150
151
152
153
# File 'lib/helper/web_steps_helper.rb', line 146

def accept_alert
  begin
    page.driver.browser.switch_to.alert.accept
  rescue Exception => e
    raise "\n>>> ERROR: #{e}"
    exit
  end
end

#backObject



155
156
157
158
159
160
161
162
# File 'lib/helper/web_steps_helper.rb', line 155

def back
  begin
    page.execute_script('window.history.back()')
  rescue Exception => e
    raise "\n>>> ERROR: #{e}"
    exit
  end
end

#check_valid_keys?(key) ⇒ Boolean

Returns:

  • (Boolean)


482
483
484
# File 'lib/helper/web_steps_helper.rb', line 482

def check_valid_keys?(key)
  %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
end

#check_valid_option_by?(option_by) ⇒ Boolean

Returns:

  • (Boolean)


474
475
476
# File 'lib/helper/web_steps_helper.rb', line 474

def check_valid_option_by?(option_by)
  %w(text value).include? option_by
end

#clear_text(element) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/helper/web_steps_helper.rb', line 173

def clear_text(element)
  foundElement = find_object(element)
  if foundElement != nil?
    begin
      foundElement.native.clear
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#close_windowsObject



262
263
264
265
266
267
268
269
# File 'lib/helper/web_steps_helper.rb', line 262

def close_windows
  begin
    page.execute_script "window.close();"
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#double_click(element) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/helper/web_steps_helper.rb', line 52

def double_click(element)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      foundElement.double_click
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#drag_and_drop_by_offset(element, x, y) ⇒ Object



629
630
631
632
633
634
635
636
637
638
639
640
641
642
# File 'lib/helper/web_steps_helper.rb', line 629

def drag_and_drop_by_offset(element, x, y)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      page.driver.browser.action.drag_and_drop_by(foundElement, x, y).perform
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#drag_and_drop_to_object(from_element, element) ⇒ Object



644
645
646
647
648
649
650
# File 'lib/helper/web_steps_helper.rb', line 644

def drag_and_drop_to_object(from_element, element)
  found_from_element = find_object(from_element)
  foundElement = find_object(element)
  if foundElement != nil and found_from_element != nil
    found_from_element.drag_to(foundElement)
  end
end

#execute_checkproperty(element, property, negate, value, isSpecialChar = false) ⇒ Object



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/helper/web_steps_helper.rb', line 422

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
    # check.should eq true

    expect(check).to eq true
  else
    # put_log "\n\n\t>>> execute_checkproperty: finish to found element"

    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

    # if IFD_Assertion.reg_compare(actual_value, value, isSpecialChar)

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/helper/web_steps_helper.rb', line 21

def execute_click(element)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      foundElement.click
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_click_offset(element, x, y) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/helper/web_steps_helper.rb', line 36

def execute_click_offset(element, x, y)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      page.driver.browser.mouse.move_to(foundElement.native,x.to_i,y.to_i)
      page.driver.browser.mouse.click()
    rescue Exception => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_javascript(script) ⇒ Object



188
189
190
191
192
193
194
195
# File 'lib/helper/web_steps_helper.rb', line 188

def execute_javascript(script)
  begin
    page.execute_script(script)
  rescue Exception => e
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_mouse_over(element) ⇒ Object



215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/helper/web_steps_helper.rb', line 215

def execute_mouse_over(element)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      page.driver.browser.action.move_to(foundElement.native, element).click.perform
      sleep(1)
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_openbrowser(url_site) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 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 => e
    raise "\n>>> Error: #{e}"
    exit
  end

  if url_site == ""
    raise "\n>>> Error: Null web page URL."
    exit
  else
    visit(url_site)
  end
end

#execute_select(element, text) ⇒ Object



197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# File 'lib/helper/web_steps_helper.rb', line 197

def execute_select(element, text)
  #select(text, :xpath => element)

  foundElement = find_object(element)
  if foundElement != nil
    begin
      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')")
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_sendkeys(element, key) ⇒ Object



652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/helper/web_steps_helper.rb', line 652

def execute_sendkeys(element, key)
  validate_supported_keys(key)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      foundElement.native.send_keys(key)
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_setstate(element, state) ⇒ Object

Set state



248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/helper/web_steps_helper.rb', line 248

def execute_setstate(element, state)
  foundElement = find_object(element)
  if foundElement != nil
    if state
      foundElement.select_option
    else
      foundElement.unselect_option
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#execute_settext(element, text) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/helper/web_steps_helper.rb', line 67

def execute_settext(element, text)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      foundElement.set(text)
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#find_object(string_object) ⇒ Object



491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
# File 'lib/helper/web_steps_helper.rb', line 491

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



607
608
609
610
611
612
613
# File 'lib/helper/web_steps_helper.rb', line 607

def find_object_check_object(cur_element)
  passCheck = true
  if cur_element != nil
    return passCheck
  end
  false
end

#get_computed_style(element, style) ⇒ Object



290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/helper/web_steps_helper.rb', line 290

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
    raise "\nError >> Not found object: #{element}"
    exit
  end
  puts "\nActual object style value is: #{computedStyle}"
  computedStyle
end

#get_element_attribute(element, value) ⇒ Object



337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
# File 'lib/helper/web_steps_helper.rb', line 337

def get_element_attribute(element,value)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      result = foundElement.value()
      puts "Attribute of #{element}: #{result}"
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#get_element_text(element) ⇒ Object



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/helper/web_steps_helper.rb', line 321

def get_element_text(element)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      result = foundElement.text()
      puts "Text of #{element}: #{result}"
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#get_object_and_store_as_string(object, string) ⇒ Object



615
616
617
618
619
# File 'lib/helper/web_steps_helper.rb', line 615

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



622
623
624
625
626
627
# File 'lib/helper/web_steps_helper.rb', line 622

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



307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/helper/web_steps_helper.rb', line 307

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!!!"
    exit
  end
  if hash_object.keys[0].to_s.upcase != "CSS_SELECTOR"
    raise ">>> OBJECT: #{str_obj} should be formatted as Css Selector."
    exit
  end
  hash_object[hash_object.keys[0]]
end

#get_objects_by_css_selector(strCssSelector) ⇒ Object



586
587
588
589
590
591
592
593
594
# File 'lib/helper/web_steps_helper.rb', line 586

def get_objects_by_css_selector(strCssSelector)
  foundElements = nil
  begin
    foundElements = page.all(:css, strCssSelector)
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
  end
  foundElements
end

#get_objects_by_xpath_selector(strXpathSelector) ⇒ Object



596
597
598
599
600
601
602
603
604
605
# File 'lib/helper/web_steps_helper.rb', line 596

def get_objects_by_xpath_selector(strXpathSelector)
  foundElements = nil
  begin
    foundElements = page.all(:xpath, strXpathSelector)
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
  foundElements
end

#maximize_browserObject



81
82
83
84
85
86
87
88
# File 'lib/helper/web_steps_helper.rb', line 81

def maximize_browser
  begin
    page.driver.browser.manage.window.maximize
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#movemouseandclick(var, element) ⇒ Object



668
669
670
671
# File 'lib/helper/web_steps_helper.rb', line 668

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



303
304
305
# File 'lib/helper/web_steps_helper.rb', line 303

def put_log str
  p str if $_CFWEB['Print Log'] == true
end

#refreshObject



164
165
166
167
168
169
170
171
# File 'lib/helper/web_steps_helper.rb', line 164

def refresh
  begin
    page.execute_script('window.location.reload()')
  rescue Exception => e
    raise "\n>>> ERROR: #{e}"
    exit
  end
end

#remove_element_attribute(element, attr) ⇒ Object



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/helper/web_steps_helper.rb', line 231

def remove_element_attribute(element, attr)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      page.driver.browser.execute_script("arguments[0].removeAttribute('#{attr}');", foundElement.native)
      sleep(1)
    rescue StandardError => e
      raise "\n>>> Error: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#resize_window_screen(x, y) ⇒ Object



271
272
273
274
275
276
277
278
279
# File 'lib/helper/web_steps_helper.rb', line 271

def resize_window_screen(x, y)
  begin
    page.driver.browser.manage.window.resize_to(x, y)
    puts page.driver.browser.manage.window.size
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#scroll_to_end_pageObject



106
107
108
109
110
111
112
113
# File 'lib/helper/web_steps_helper.rb', line 106

def scroll_to_end_page
  begin
    page.driver.execute_script('window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));')
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#scroll_to_top_pageObject



115
116
117
118
119
120
121
122
# File 'lib/helper/web_steps_helper.rb', line 115

def scroll_to_top_page
  begin
    page.driver.execute_script('window.scrollTo(Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight),0);')
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#switch_to_frame(element) ⇒ Object



281
282
283
284
285
286
287
288
# File 'lib/helper/web_steps_helper.rb', line 281

def switch_to_frame(element)
  begin
    page.driver.browser.switch_to.frame 'element'
  rescue Exception => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#switch_to_window_by_title(window_title) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/helper/web_steps_helper.rb', line 90

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"
    exit
  end
end

#validate_option_by(option_by) ⇒ Object



478
479
480
# File 'lib/helper/web_steps_helper.rb', line 478

def validate_option_by(option_by)
  raise "Please select valid option, invalid option - #{option_by}" unless check_valid_option_by? option_by
end

#validate_supported_keys(key) ⇒ Object



486
487
488
# File 'lib/helper/web_steps_helper.rb', line 486

def validate_supported_keys(key)
  raise "Please select valid keys, invalid key - #{key}" unless check_valid_option_by? key
end

#verify_alert_text(text) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/helper/web_steps_helper.rb', line 135

def verify_alert_text(text)
  begin
    alert = page.driver.browser.switch_to.alert.text
    puts "Actual Page alert text : #{alert}, Expected value : #{text}"
    expect(alert).to eq text
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end

#verify_element_not_has_text(element, value) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/helper/web_steps_helper.rb', line 370

def verify_element_not_has_text(element,value)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      actual_value = foundElement.text()
      put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
      expect(actual_value).not_to eql value
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end

  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#verify_element_not_has_value(element, value) ⇒ Object



405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
# File 'lib/helper/web_steps_helper.rb', line 405

def verify_element_not_has_value(element,value)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      actual_value = foundElement.value()
      put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
      expect(actual_value).not_to eql value
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#verify_element_text(element, value) ⇒ Object



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/helper/web_steps_helper.rb', line 353

def verify_element_text(element,value)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      actual_value = foundElement.text()
      put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
      expect(actual_value).to eq value
    rescue Exception => e
      raise "\n>>> ERROR: #{e} "
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#verify_element_value(element, value) ⇒ Object



388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
# File 'lib/helper/web_steps_helper.rb', line 388

def verify_element_value(element,value)
  foundElement = find_object(element)
  if foundElement != nil
    begin
      actual_value = foundElement.value()
      put_log "Actual result is: '#{actual_value}' -- Expected result is: '#{value}'"
      expect(actual_value).to eq value
    rescue Exception => e
      raise "\n>>> ERROR: #{e}"
      exit
    end
  else
    raise "\nError >> Not found object: #{element}"
    exit
  end
end

#verify_title(expected_title) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# File 'lib/helper/web_steps_helper.rb', line 124

def verify_title(expected_title)
  begin
    page_title = page.title
    puts "Actual Page Title : #{page_title}, Expected Page Title : #{expected_title}"
    expect(page_title).to eq expected_title
  rescue StandardError => e
    raise "\n>>> Error: #{e}"
    exit
  end
end