Module: Awetestlib::Regression::Utilities

Included in:
Runner
Defined in:
lib/awetestlib/regression/utilities.rb

Instance Method Summary collapse

Instance Method Details

#calc_index(index, every = 1) ⇒ Object



88
89
90
# File 'lib/awetestlib/regression/utilities.rb', line 88

def calc_index(index, every = 1)
  (index / every) + (every - 1)
end

#capture_screen(browser, ts) ⇒ Object



536
537
538
539
540
541
542
543
544
545
546
547
548
549
# File 'lib/awetestlib/regression/utilities.rb', line 536

def capture_screen(browser, ts)
  browser.maximize
  browser.bring_to_front
  caller = get_caller
  caller.match(/:(\d+):/)
  lnbr       = $1
  path       = "#{@myRoot}/screenshot/"
  screenfile = "#{@myName}_#{@myRun.id}_#{lnbr.to_s}_#{ts.to_f.to_s}.scrsht.jpg"
  info_to_log("path:#{path} screenfile:#{screenfile}")
  screenSpec = '"' + path + screenfile + '"'
  screenSpec.gsub!('/', '\\')
  screen_capture(screenSpec)
  screenfile
end

#close_print(title = 'Print', text = '', button = '&Cancel', side = 'left') ⇒ Object

method for cancelling Print window TODO need to handle ‘Cancel’ and ‘&Cancel’ (first character underlined)



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
# File 'lib/awetestlib/regression/utilities.rb', line 760

def close_print(title = 'Print', text = '', button = '&Cancel', side = 'left')
  msg = "Popup: title=#{title} button='#{button}' text='#{text}' side='#{side}':"
  if @ai.WinWait(title, text, WAIT)
    passed_to_log("#{msg} found.")
    @ai.WinActivate(title)
    if @ai.WinActive(title, text)
      passed_to_log("#{msg} activated.")
      if @ai.ControlFocus(title, text, button)
        passed_to_log("#{msg} focus attained.")
        if @ai.ControlClick(title, text, button, side)
          passed_to_log("#{msg} closed successfully.")
        else
          failed_to_log("#{msg} click failed on button (#{__LINE__})")
        end
      else
        failed_to_log("#{msg} Unable to gain focus on button (#{__LINE__})")
      end
    else
      failed_to_log("#{msg} Unable to activate (#{__LINE__})")
    end
  else
    failed_to_log("#{msg} did not appear after #{WAIT} seconds. (#{__LINE__})")
  end
rescue
  failed_to_log("Close #{msg}: '#{$!}'. (#{__LINE__})")
end

#debug_call_list(msg) ⇒ Object



216
217
218
219
# File 'lib/awetestlib/regression/utilities.rb', line 216

def debug_call_list(msg)
  call_array = get_call_array
  debug_to_log("#{msg}\n#{dump_array(call_array)}")
end

#dump_all_tables(browser, to_report = false) ⇒ Object



456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
# File 'lib/awetestlib/regression/utilities.rb', line 456

def dump_all_tables(browser, to_report = false)
  tables  = browser.tables
  msg     = ''
  tbl_cnt = 0
  tables.each do |tbl|
    tbl_cnt += 1
    row_cnt = 0
    msg <<"\n=================\ntable: #{tbl_cnt}\n=================\n#{tbl}\ntext:\n#{tbl.text}"
    tbl.rows.each do |row|
      row_cnt  += 1
      cell_cnt = 0
      msg <<"\n=================\ntable: #{tbl_cnt} row: #{row_cnt}\n#{row.inspect}\n#{row}\ntext:'#{row.text}'"
      row.each do |cell|
        cell_cnt += 1
        msg <<"\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
      end
    end
  end
  if to_report
    debug_to_report(msg)
  else
    debug_to_log(msg)
  end
end

#dump_array(arr, space_to_underscore = false) ⇒ Object



399
400
401
402
403
404
405
406
407
# File 'lib/awetestlib/regression/utilities.rb', line 399

def dump_array(arr, space_to_underscore = false)
  dump = "  #{arr.inspect}\n"
  arr.each_index do |x|
    value = arr[x].to_s
    value.gsub!(/\s/, '_') if space_to_underscore
    dump << " #{x.to_s.rjust(5)}>> '#{arr[x].to_s}'\n"
  end
  dump
end

#dump_ole_get_methods(ole) ⇒ Object



421
422
423
424
425
426
427
428
429
430
431
# File 'lib/awetestlib/regression/utilities.rb', line 421

def dump_ole_get_methods(ole)
  rtrn = ''
  ole.ole_get_methods.each do |m|
    prms = ''
    m.params.each do |p|
      prms << "#{p}, "
    end
    rtrn << "#{m.name}(#{prms.chop.chop})\n"
  end
  rtrn
end

#dump_ole_help(ole) ⇒ Object



433
434
435
436
437
438
439
440
441
442
443
# File 'lib/awetestlib/regression/utilities.rb', line 433

def dump_ole_help(ole)
  rtrn = ''
  ole.ole_obj_help.each do |m|
    prms = ''
    m.params.each do |p|
      prms << "#{p}, "
    end
    rtrn << "#{m.name}(#{prms.chop.chop})\n"
  end
  rtrn
end

#dump_ole_methods(ole) ⇒ Object



409
410
411
412
413
414
415
416
417
418
419
# File 'lib/awetestlib/regression/utilities.rb', line 409

def dump_ole_methods(ole)
  rtrn = ''
  ole.ole_methods.each do |m|
    prms = ''
    m.params.each do |p|
      prms << "#{p}, "
    end
    rtrn << "#{m.name}(#{prms.chop.chop})\n"
  end
  rtrn
end

#dump_row_cells(row) ⇒ Object



514
515
516
517
518
519
520
521
522
523
# File 'lib/awetestlib/regression/utilities.rb', line 514

def dump_row_cells(row)
  msg      = ''
  cell_cnt = 0
  msg <<"\n=================\nrow: #{row.inspect}\n#{row}\ntext:'#{row.text}'"
  row.each do |cell|
    cell_cnt += 1
    msg <<"\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
  end
  debug_to_log(msg)
end

#dump_select_list_options(element) ⇒ Object



445
446
447
448
449
450
451
452
453
454
# File 'lib/awetestlib/regression/utilities.rb', line 445

def dump_select_list_options(element)
  msg     = "#{element.inspect}"
  options = element.options
  cnt     = 1
  options.each do |o|
    msg << "\n\t#{cnt}:\t'#{o}"
    cnt += 1
  end
  debug_to_log(msg)
end

#dump_table_and_rows(table, to_report = false) ⇒ Object



481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File 'lib/awetestlib/regression/utilities.rb', line 481

def dump_table_and_rows(table, to_report = false)
  msg = "\n=================\ntable\n=================\nn#{table}\n#{table.to_yaml}\nrows:"
  cnt = 0
  table.rows.each do |r|
    cnt += 1
    msg << "\n#{cnt}: #{r.text}"
  end
  msg << "\n=================\n================="
  if to_report
    debug_to_report(msg)
  else
    debug_to_log(msg)
  end
end

#dump_table_rows_and_cells(tbl) ⇒ Object Also known as: dump_table_rows



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/awetestlib/regression/utilities.rb', line 496

def dump_table_rows_and_cells(tbl)
  msg     = ''
  row_cnt = 0
  msg <<"\n=================\ntable: #{tbl.inspect}\n=================\n#{tbl}\ntext:\n#{tbl.text}"
  tbl.rows.each do |row|
    row_cnt  += 1
    cell_cnt = 0
    msg <<"\n=================\nrow: #{row_cnt}\n#{row.inspect}\n#{row}\ntext:'#{row.text}'"
    row.each do |cell|
      cell_cnt += 1
      msg <<"\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
    end
  end
  debug_to_log(msg)
end

#file_download(browser = nil) ⇒ Object

method for handling file download dialog use click_no_wait on the action that triggers the save dialog TODO need version for Firefox TODO need to handle ‘Cancel’ and ‘&Cancel’ (first character underlined) TODO replace call to close_modal_ie with actual file download



792
793
794
795
796
797
798
799
800
801
802
# File 'lib/awetestlib/regression/utilities.rb', line 792

def file_download(browser = nil)
  title  = 'File Download'
  title  = translate_popup_title(title)
  text   = ''
  button = 'Cancel'
  if @browserAbbrev == 'IE'
    close_popup(title, button, text)
  else

  end
end

#file_upload(filepath) ⇒ Object

method for handling file upload dialog use click_no_wait on the action that triggers the save dialog TODO need version for Firefox



807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
# File 'lib/awetestlib/regression/utilities.rb', line 807

def file_upload(filepath)
  title   = 'Choose File'
  title   = translate_popup_title(title)
  text    = ''
  button  = "&Open"
  control = "Edit1"
  side    = 'primary'
  msg     = "Window title=#{title} button='#{button}' text='#{text}' side='#{side}':"
  begin
    if @ai.WinWait(title, text, WAIT)
      passed_to_log("#{msg} found.")
      @ai.WinActivate(title, text)
      if @ai.WinActive(title, text)
        passed_to_log("#{msg} activated.")
        if @ai.ControlSend(title, text, control, filepath)
          passed_to_log("#{msg} #{control} command sent.")
          sleep_for 1
          if @ai.ControlClick(title, text, button, "primary")
            passed_to_log("#{msg} Upload of #{filepath} succeeded.")
          else
            failed_to_log("#{msg} Upload of #{filepath} failed. (#{__LINE__})")
          end
        else
          failed_to_log("#{msg} Unable to select #{filepath}. (#{__LINE__})")
        end
      else
        failed_to_log("#{msg} Unable to activate. (#{__LINE__})")
      end
    else
      failed_to_log("#{msg} did not appear after #{WAIT} seconds. (#{__LINE__})")
    end
  rescue
    failed_to_log("#{msg} Unable to upload: '#{$!}'. (#{__LINE__})")
  end

end

#find_sheet_with_name(workbook, sheet_name) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/awetestlib/regression/utilities.rb', line 235

def find_sheet_with_name(workbook, sheet_name)
  sheets = workbook.sheets
  idx    = 0
  found  = false
  sheets.each do |s|
    if s == sheet_name
      found = true
      break
    end
    idx += 1
  end
  if found
    idx
  else
    -1
  end
end

#flash(element, count = 4) ⇒ Object



578
579
580
581
582
583
584
# File 'lib/awetestlib/regression/utilities.rb', line 578

def flash(element, count = 4)
  element.flash(count)
  debug_to_log("'#{element.inspect}' flashed #{count} times.")
  true
rescue
  debug_to_log("Flash '#{element.inspect}' failed: '#{$!}' (#{__LINE__})")
end

#flash_id(browser, strg, count) ⇒ Object



566
567
568
569
570
571
572
573
574
575
576
# File 'lib/awetestlib/regression/utilities.rb', line 566

def flash_id(browser, strg, count)
  msg = "Flash link id='#{strg}' #{count} times."
  msg << " #{desc}" if desc.length > 0
  browser.link(:id, strg).flash(count)
  if validate(browser, @myName, __LINE__)
    passed_to_log(msg)
    true
  end
rescue
  failed_to_log("Unable to #{msg} '#{$!}'")
end

#flash_text(browser, strg, count, desc = '') ⇒ Object



875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
# File 'lib/awetestlib/regression/utilities.rb', line 875

def flash_text(browser, strg, count, desc = '')
  msg = "Flash link text='#{strg}' #{count} times."
  msg << " #{desc}" if desc.length > 0
  strgCnt = string_count_in_string(browser.text, strg)
  if strgCnt > 0
    browser.link(:text, strg).flash(count)
    if validate(browser, @myName, __LINE__)
      passed_to_log(msg)
      true
    end
  else
    failed_to_log("#{msg} Link not found.")
  end
rescue
  failed_to_log("Unable to #{msg} '#{$!}'")
end

#focus_on_textfield_by_id(browser, strg, desc = '') ⇒ Object



860
861
862
863
864
865
866
867
868
869
870
871
872
873
# File 'lib/awetestlib/regression/utilities.rb', line 860

def focus_on_textfield_by_id(browser, strg, desc = '')
  msg = "Set focus on textfield name='#{strg}' "
  msg << " #{desc}" if desc.length > 0
  tf = browser.text_field(:id, strg)
  if validate(browser, @myName, __LINE__)
    tf.focus
    if validate(browser, @myName, __LINE__)
      passed_to_log(msg)
      true
    end
  end
rescue
  failed_to_log("Unable to #{msg} '#{$!}'")
end

#get_call_array(depth = 9) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
# File 'lib/awetestlib/regression/utilities.rb', line 368

def get_call_array(depth = 9)
  arr       = []
  call_list = Kernel.caller
  call_list.each_index do |x|
    myCaller = call_list[x].to_s
    break if x > depth or myCaller =~ /:in .run.$/
    myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
    arr << $1.gsub(/eval/, @myName)
  end
  arr
end

#get_call_list(depth = 9, dbg = false) ⇒ Object Also known as: get_callers



326
327
328
329
330
331
332
333
334
335
336
337
# File 'lib/awetestlib/regression/utilities.rb', line 326

def get_call_list(depth = 9, dbg = false)
  myList    = []
  call_list = Kernel.caller
  puts call_list if dbg
  call_list.each_index do |x|
    myCaller = call_list[x].to_s
    break if x > depth or myCaller =~ /:in .run.$/
    myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
    myList << "[#{$1.gsub(/eval/, @myName)}] "
  end
  myList
end

#get_call_list_new(depth = 9, dbg = false) ⇒ Object



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
# File 'lib/awetestlib/regression/utilities.rb', line 341

def get_call_list_new(depth = 9, dbg = false)
  myList    = []
  call_list = Kernel.caller
  puts call_list if dbg
  call_list.each_index do |x|
    myCaller = call_list[x].to_s
    break if x > depth or myCaller =~ /:in .run.$/
    if myCaller.include? @myName
      myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
      myList << "[#{$1.gsub(/eval/, @myName)}] "
      break
    end
  end
  if @projName
    call_list.each_index do |x|
      myCaller = call_list[x].to_s
      break if x > depth or myCaller =~ /:in .run.$/
      if myCaller.include? @projName
        myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
        myList << "[#{$1.gsub(/eval/, @projName)}] "
        break
      end
    end
  end
  myList
end

#get_caller_lineObject



320
321
322
323
324
# File 'lib/awetestlib/regression/utilities.rb', line 320

def get_caller_line
  last_caller = get_callers[0]
  line        = last_caller.split(':', 3)[1]
  line
end

#get_debug_list(dbg = false) ⇒ Object



380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/awetestlib/regression/utilities.rb', line 380

def get_debug_list(dbg = false)
  calls = get_call_array(10)
  puts "#{calls.to_yaml}" if dbg
  arr = []
  calls.each_index do |ix|
    if ix > 1 # skip this method and the logging method
      arr << calls[ix]
    end
  end
  puts "#{arr.to_yaml}" if dbg
  if arr.length > 0
    list = 'TRACE:'
    arr.reverse.each { |l| list << "=>#{l}" }
    " [[#{list}]]"
  else
    nil
  end
end

#get_mdyy(t = Time.now) ⇒ Object



56
57
58
# File 'lib/awetestlib/regression/utilities.rb', line 56

def get_mdyy(t = Time.now)
  "#{t.month}/#{t.day}/#{t.year}"
end

#get_prefix(strg, offset) ⇒ Object



60
61
62
63
# File 'lib/awetestlib/regression/utilities.rb', line 60

def get_prefix(strg, offset)
  a_slice = strg.slice(0, offset)
  a_slice.downcase
end

#get_save_file_path(root, filename) ⇒ Object



586
587
588
589
# File 'lib/awetestlib/regression/utilities.rb', line 586

def get_save_file_path(root, filename)
  filespec = "#{root}/file/#{filename}"
  filespec.gsub!('/', '\\')
end

#get_timestamp(format = 'long', offset = nil, offset_unit = :years) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/awetestlib/regression/utilities.rb', line 65

def get_timestamp(format = 'long', offset = nil, offset_unit = :years)
  t = DateTime.now
  if offset
    t = t.advance(offset_unit => offset)
  end
  case format
    when 'dateonly'
      t.strftime("%m/%d/%Y")
    when 'condensed'
      t.strftime("%Y%m%d%H%M")
    when 'condensed_seconds'
      t.strftime("%Y%m%d%H%M%S")
    when 'long'
      t.strftime("%m/%d/%Y %I:%M %p")
    when 'mdyy'
      get_mdyy(t)
    when 'm/d/y'
      get_mdyy(t)
    else
      Time.now.strftime("%m/%d/%Y %H:%M:%S")
  end
end

#get_trace(lnbr) ⇒ Object Also known as: dump_caller



46
47
48
49
50
51
52
# File 'lib/awetestlib/regression/utilities.rb', line 46

def get_trace(lnbr)
  callertrace = "\nCaller trace: (#{lnbr})\n"
  Kernel.caller.each_index do |x|
    callertrace << '    >> ' + Kernel.caller[x].to_s + "\n"
  end
  callertrace
end

#get_variables(file, login = :role, dbg = true) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/awetestlib/regression/utilities.rb', line 92

def get_variables(file,  = :role, dbg = true)
  debug_to_log("#{__method__}: file = #{file}")
  debug_to_log("#{__method__}: role = #{}")

  @var                   = Hash.new
  workbook               = Excel.new(file)
  data_index             = find_sheet_with_name(workbook, 'Data')
  workbook.default_sheet = workbook.sheets[data_index]
  var_col                = 0

  2.upto(workbook.last_column) do |col|
    scriptName = workbook.cell(1, col)
    if scriptName == @myName
      var_col = col
      break
    end
  end

  2.upto(workbook.last_row) do |line|
    name       = workbook.cell(line, 'A')
    value      = workbook.cell(line, var_col).to_s.strip
    @var[name] = value
  end

  @var.keys.sort.each do |name|
    message_tolog("@var #{name}: '#{@var[name]}'")
  end if dbg

  @login       = Hash.new
      = 0
  role_col     = 0
  userid_col   = 0
  password_col = 0
  url_col      = 0
  name_col     = 0
  role_index   = find_sheet_with_name(workbook, 'Login')
  if role_index >= 0
    workbook.default_sheet = workbook.sheets[role_index]

    1.upto(workbook.last_column) do |col|
      a_cell = workbook.cell(1, col)
      case a_cell
        when @myName
           = col
          break
        when 'role'
          role_col = col
        when 'userid'
          userid_col = col
        when 'password'
          password_col = col
        when 'url'
          url_col = col
        when 'name'
          name_col = col
      end
    end

    2.upto(workbook.last_row) do |line|
      role     = workbook.cell(line, role_col)
      userid   = workbook.cell(line, userid_col)
      password = workbook.cell(line, password_col)
      url      = workbook.cell(line, url_col)
      username = workbook.cell(line, name_col)
      enabled  = workbook.cell(line, ).to_s

      case 
        when :id
          key = userid
        when :role
          key = role
        else
          key = role
      end

      @login[key]             = Hash.new
      @login[key]['role']     = role
      @login[key]['userid']   = userid
      @login[key]['password'] = password
      @login[key]['url']      = url
      @login[key]['name']     = username
      @login[key]['enabled']  = enabled

    end

    @login.keys.sort.each do |key|
      message_tolog("@login (by #{}): #{key}=>'#{@login[key].to_yaml}'")
    end if dbg
  end

rescue
  fatal_to_log("#{__method__}: '#{$!}'")
end

#grab_window_list(strg) ⇒ Object



198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# File 'lib/awetestlib/regression/utilities.rb', line 198

def grab_window_list(strg)
  @ai.AutoItSetOption("WinTitleMatchMode", 2)
  list    = @ai.WinList(strg)
  stuff   = ''
  names   = list[0]
  handles = list[1]
  max     = names.length - 1
  rng     = Range.new(0, max)
  rng.each do |idx|
    window_handle = "[HANDLE:#{handles[idx]}]"
    full_text     = @ai.WinGetText(window_handle)
    stuff << "[#{handles[idx]}]=>#{names[idx]}=>'#{full_text}'\n"
  end
  debug_to_log("\n#{stuff}")
  @ai.AutoItSetOption("WinTitleMatchMode", 1)
  stuff
end

#nice_array(arr, space_to_underscore = false) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
# File 'lib/awetestlib/regression/utilities.rb', line 253

def nice_array(arr, space_to_underscore = false)
  new_arr = Array.new
  if space_to_underscore
    arr.each do |nty|
      new_arr << nty.gsub(/\s/, '_')
    end
  else
    new_arr = arr
  end
  "['#{new_arr.join("','")}']"
end

#parse_cookies(browser) ⇒ Object



525
526
527
528
529
530
531
532
533
534
# File 'lib/awetestlib/regression/utilities.rb', line 525

def parse_cookies(browser)
  cookies = Hash.new
  strg    = browser.document.cookie
  ary     = strg.split(';')
  ary.each do |c|
    key, value          = c.split('=')
    cookies[key.lstrip] = value
  end
  cookies
end

#pdf_to_text(file, noblank = true) ⇒ Object



551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/awetestlib/regression/utilities.rb', line 551

def pdf_to_text(file, noblank = true)
  spec = file.sub(/\.pdf$/, '')
  `pdftotext #{spec}.pdf`
  file = File.new("#{spec}.txt")
  text = []
  file.readlines.each do |l|
    l.chomp! if noblank
    if l.length > 0
      text << l
    end
  end
  file.close
  text
end

#rescue_me(e, me = nil, what = nil, where = nil, who = nil) ⇒ Object



270
271
272
273
274
275
276
277
278
279
280
281
282
283
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
# File 'lib/awetestlib/regression/utilities.rb', line 270

def rescue_me(e, me = nil, what = nil, where = nil, who = nil)
  #TODO: these are rescues from exceptions raised in Watir/Firewatir
  debug_to_log("#{__method__}: Begin rescue")
  ok = false
  begin
    gaak    = who.inspect
    located = gaak =~ /located=true/i
  rescue
    debug_to_log("#{__method__}: gaak: '#{gaak}'")
  end
  msg = e.message
  debug_to_log("#{__method__}: msg = #{msg}")
  if  msg =~ /undefined method\s+.join.\s+for/i # firewatir to_s implementation error
    ok = true
  elsif msg =~ /undefined method\s+.match.\s+for.+WIN32OLERuntimeError/i # watir and firewatir
    ok = true
  elsif msg =~ /undefined method\s+.match.\s+for.+UnknownObjectException/i # watir
    ok = true
  elsif msg =~ /window\.getBrowser is not a function/i # firewatir
    ok = true
  elsif msg =~ /WIN32OLERuntimeError/i # watir
    ok = true
  elsif msg =~ /undefined method\s+.match.\s+for/i # watir
    ok = true
  elsif msg =~ /wrong number of arguments \(1 for 0\)/i
    ok = true
  elsif (msg =~ /unable to locate element/i)
    if located
      ok = true
    elsif where == 'Watir::Div'
      ok = true
    end
  elsif (msg =~ /HRESULT error code:0x80070005/)
    ok = true
                                                #elsif msg =~ /missing\s+\;\s+before statement/
                                                #  ok = true
  end
  if ok
    debug_to_log("#{__method__}: RESCUED: \n#{who.to_yaml}=> #{what} in #{me}()\n=> '#{$!}'")
    debug_to_log("#{__method__}: #{who.inspect}") if who
    debug_to_log("#{__method__}: #{where.inspect}")
    debug_to_log("#{__method__}: #{get_callers(6, true)}")
  else
    debug_to_log("#{__method__}: NO RESCUE: #{e.message}")
    debug_to_log("#{__method__}: NO RESCUE: \n#{get_callers(6, true)}")
  end
  debug_to_log("#{__method__}: Exit")
  ok
end

#save_file(filepath, download_title = "File Download - Security Warning") ⇒ Object

method for handling save dialog use click_no_wait on the action that triggers the save dialog



670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/awetestlib/regression/utilities.rb', line 670

def save_file(filepath, download_title = "File Download - Security Warning")
  # TODO need version for Firefox
  # TODO need to handle first character underline, e.g. 'Cancel' and '&Cancel'
  download_title   = translate_popup_title(download_title)
  download_text    = ''
  download_control = "&Save"
  saveas_title     = 'Save As'
  saveas_text      = ''
  saveas_control   = "Edit1"
  dnld_cmplt_title = "Download Complete"
  dnld_cmplt_title = translate_popup_title(dnld_cmplt_title)
  dnld_cmplt_text  = ""
  #    save_title = ""
  side             = 'primary'
  msgdl            = "Window '#{download_title}':"
  msgsa            = "Window '#{saveas_title}':"
  msgdc            = "Window '#{dnld_cmplt_title}':"
  begin
    if @ai.WinWait(download_title, download_text, WAIT)
      @ai.WinActivate(download_title, download_text)
      if @ai.WinActive(download_title, download_text)
        dl_title = @ai.WinGetTitle(download_title, download_text)
        #          dl_hndl  = @ai.WinGetHandle(download_title, download_text)
        #          dl_text  = @ai.WinGetText(download_title, download_text)
        #          dl_sv_hndl = @ai.ControlGetHandle(dl_title, '', download_control)
        #          dl_op_hndl = @ai.ControlGetHandle(dl_title, '', '&Open')
        #          dl_cn_hndl = @ai.ControlGetHandle(dl_title, '', 'Cancel')
        debug_to_log("#{msgdl} activated. (#{__LINE__})")

        if @ai.ControlFocus(dl_title, download_text, download_control)
          debug_to_log("#{msgdl} focus gained. (#{__LINE__})")

          @ai.Send("S")
          #              @ai.ControlSend(dl_Stitle, download_text, download_control, "{ENTER}")
          sleep_for 1

          if @ai.ControlClick(dl_title, download_text, download_control, side)
            debug_to_log("#{msgdl} click succeeded on '#{download_control}'. (#{__LINE__})")

            if @ai.WinWait(saveas_title, saveas_text, WAIT)
              debug_to_log("#{msgsa} appeared. (#{__LINE__})")
              sleep_for 1
              if @ai.ControlSend(saveas_title, saveas_text, saveas_control, filepath)
                debug_to_log("#{msgsa} controlsend of '#{saveas_control}' succeeded. (#{__LINE__})")

                @ai.Send("S")
                @ai.ControlSend(saveas_title, saveas_text, saveas_control, "{ENTER}")
                sleep_for 1

                if @ai.ControlClick(saveas_title, saveas_text, saveas_control, side)
                  passed_to_log("#{msgsa} click succeeded on '#{saveas_control}'. (#{__LINE__})")
                  if @ai.WinWait(dnld_cmplt_title, dnld_cmplt_text, WAIT)
                    debug_to_log("#{msgdc} appeared. (#{__LINE__})")
                    sleep_for 1
                    if @ai.ControlClick(dnld_cmplt_title, dnld_cmplt_text, "Close", side)
                      passed_to_log("Save file for #{filepath} succeeded.")
                    else
                      failed_to_log("#{msgdc} click failed on 'Close'. (#{__LINE__})")
                    end
                  else
                    failed_to_log("#{msgdc} did not appear after #{WAIT} seconds. (#{__LINE__})")
                  end
                else
                  failed_to_log("#{msgsa} click failed on '#{saveas_control}'. (#{__LINE__})")
                end
              else
                failed_to_log("#{msgsa} controlsend of '#{saveas_control}' failed. (#{__LINE__})")
              end
            else
              failed_to_log("#{msgsa} did not appear after #{WAIT} seconds. (#{__LINE__})")
            end
          else
            failed_to_log("#{msgdl} click failed on '#{download_control}'. (#{__LINE__})")
          end
        else
          failed_to_log("#{msgdl} Unable to gain focus on control '#{dl_title}'. (#{__LINE__})")
        end
      else
        failed_to_log("#{msgdl} Unable to activate. (#{__LINE__})")
      end
    else
      failed_to_log("#{msgdl} did not appear after #{WAIT} seconds. (#{__LINE__})")
    end
  rescue
    failed_to_log("Save file failed: '#{$!}'. (#{__LINE__})")
  end
end

#save_file1(filepath, title = "File Download", desc = '', wait = WAIT) ⇒ Object

TODO This and save_file2 have to be combined somehow.



607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
# File 'lib/awetestlib/regression/utilities.rb', line 607

def save_file1(filepath, title = "File Download", desc = '', wait = WAIT)
  title = translate_popup_title(title)
  @ai.WinWait(title, '', wait)
  @ai.WinActivate(title, '')
  sleep 1
  @ai.ControlFocus(title, "", "&Save")
  sleep 3
  @ai.ControlClick(title, "", "&Save", "primary")
  sleep 2
  @ai.ControlClick(title, "", "Save", "primary")

  @ai.WinWait("Save As", "", wait)
  sleep 1
  @ai.ControlSend("Save As", "", "Edit1", filepath)
  @ai.ControlFocus("Save As", "", "&Save")
  @ai.ControlClick("Save As", "", "&Save", "primary")
  @ai.ControlClick("Save As", "", "Save", "primary")

  @ai.WinWait("Download complete", "", wait)
  passed_to_log("Save file '#{filepath}' succeeded. #{desc}")
  @ai.ControlClick("Download complete", "", "Close")
rescue
  failed_to_log("Save file failed: #{desc} '#{$!}'. (#{__LINE__})")
end

#save_file2(filepath, title = "File Download - Security Warning", desc = '', wait = WAIT) ⇒ Object



632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
# File 'lib/awetestlib/regression/utilities.rb', line 632

def save_file2(filepath, title = "File Download - Security Warning", desc = '', wait = WAIT)
  title = translate_popup_title(title)
  sleep(1)
  @ai.WinWait(title, '', wait)
  dl_hndl    = @ai.WinGetHandle(title, '')
  dl_sv_hndl = @ai.ControlGetHandle(title, '', "&Save")
  @ai.WinActivate(title, '')
  sleep 1
  @ai.ControlFocus(title, "", "&Save")
  sleep 1
  @ai.ControlFocus(title, "", "Save")
  sleep 1
  @ai.ControlClick(title, "", "&Save", "primary")
  sleep 1
  @ai.ControlClick(title, "", "Save", "primary")
  sleep 1
  w = WinClicker.new
  w.clickButtonWithHandle(dl_sv_hndl)
  sleep 1
  w.clickWindowsButton_hwnd(dl_hndl, "Save")
  sleep 1
  w.clickWindowsButton_hwnd(dl_hndl, "&Save")

  @ai.WinWait("Save As", "", wait)
  sleep 1
  @ai.ControlSend("Save As", "", "Edit1", filepath)
  @ai.ControlFocus("Save As", "", "&Save")
  @ai.ControlClick("Save As", "", "&Save", "primary")

  @ai.WinWait("Download complete", "", wait)
  passed_to_log("Save file '#{filepath}' succeeded. #{desc}")
  @ai.ControlClick("Download complete", "", "Close")
rescue
  failed_to_log("Save file failed: #{desc} '#{$!}'. (#{__LINE__})")
end

#save_file_orig(filepath, desc = '', wait = WAIT) ⇒ Object



591
592
593
594
595
596
597
598
599
600
601
602
603
604
# File 'lib/awetestlib/regression/utilities.rb', line 591

def save_file_orig(filepath, desc = '', wait = WAIT)
  #    title = translate_popup_title(title)
  @ai.WinWait("File Download", "", wait)
  @ai.ControlFocus("File Download", "", "&Save")
  sleep 1
  @ai.ControlClick("File Download", "", "&Save", "left")
  @ai.WinWait("Save As", "", wait)
  sleep 1
  @ai.ControlSend("Save As", "", "Edit1", filepath)
  @ai.ControlClick("Save As", "", "&Save", "left")
  sleep 1
  @ai.WinWait("Download complete", "", wait)
  @ai.ControlClick("Download complete", "", "Close")
end

#sec2hms(s) ⇒ Object



221
222
223
# File 'lib/awetestlib/regression/utilities.rb', line 221

def sec2hms(s)
  Time.at(s.to_i).gmtime.strftime('%H:%M:%S')
end

#set_script_variablesObject

Place holder to prevent method not found error in scripts



6
7
8
# File 'lib/awetestlib/regression/utilities.rb', line 6

def set_script_variables
  # TODO: replace with method_missing?
end

#setupObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/awetestlib/regression/utilities.rb', line 10

def setup
  #    if @os_sysname =~ /Windows.+Server\s+2003/
  ##  'Microsoft(R) Windows(R) Server 2003, Enterprise Edition'
  #      @vertical_hack_ie   = 110
  #      @vertical_hack_ff   = 138
  #      @horizontal_hack_ie = 5
  #      @horizontal_hack_ff = 4
  #    elsif @os_sysname =~ /Windows XP Professional/
  #  'Microsoft Windows XP Professional'
  @vertical_hack_ie        = 118
  @vertical_hack_ff        = 144
  @horizontal_hack_ie      = 5
  @horizontal_hack_ff      = 4
  #end

  @settings_display_ids    = Hash[
      "Currency"       => "row-currencyName",
      "Description"    => "row-description",
      "Tx Date"        => "row-fmtDate",
      "Total"          => "row-amount",
      "[currencyCode]" => "row-currencyCode",
      "Date in Millis" => "row-dateInMilliseconds",
  ]
  @column_data_display_ids = Hash[
      "Currency"       => "yui-dt0-th-currencyName",
      "Description"    => "yui-dt0-th-description",
      "Tx Date"        => "yui-dt0-th-fmtDate",
      "Total"          => "yui-dt0-th-fmtDate",
      "[currencyCode]" => "yui-dt0-th-currencyCode",
      "Date in Millis" => "yui-dt0-th-dateInMilliseconds",
  ]
  @settings_panel_index    = 0
  @x_tolerance             = 4
  @y_tolerance             = 4
end

#string_count_in_string(strg, substrg) ⇒ Object



265
266
267
268
# File 'lib/awetestlib/regression/utilities.rb', line 265

def string_count_in_string(strg, substrg)
  count = strg.scan(substrg).length
  count
end

#translate_var_list(key) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
# File 'lib/awetestlib/regression/utilities.rb', line 186

def translate_var_list(key)
  if @var[key] and @var[key].length > 0
    list = @var[key].dup
    unless list =~ /^\[.+\]$/
      list = "[#{list}]"
    end
    eval(list)
  end
rescue
  failed_to_log("#{__method__}: '#{$!}'")
end

#upload_file(data_path) ⇒ Object



844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
# File 'lib/awetestlib/regression/utilities.rb', line 844

def upload_file(data_path)
  limit = 180 # .seconds
  Timeout::timeout(limit) {
    wait = 20
    @ai.WinWait("Choose File to Upload", "", wait)
    sleep 1
    @ai.ControlSend("Choose File to Upload", "", "Edit1", data_path)
    @ai.ControlClick("Choose File to Upload", "", "[CLASS:Button; INSTANCE:2]", "left")
    sleep 4
    #sleep 1
  }
  failed_to_log("Choose File to Upload not found after #{limit} '#{$!}'")
rescue Timeout::Error
  failed_to_log("File Upload timeout after #{limit} '#{$!}'")
end