awetestlib 0.1.30-x86-mingw32 → 1.2.4-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +101 -41
  3. data/awetestlib.gemspec +36 -47
  4. data/awetestlib_osx.gemspec +24 -18
  5. data/awetestlib_windows.gemspec +46 -0
  6. data/bin/awetestlib +130 -111
  7. data/bin/awetestlib-driver-setup.rb +0 -2
  8. data/bin/awetestlib-helpers.rb +43 -30
  9. data/lib/awetestlib.rb +196 -20
  10. data/lib/awetestlib/command_line.rb +44 -0
  11. data/lib/awetestlib/html_report.rb +57 -50
  12. data/lib/awetestlib/logging.rb +242 -171
  13. data/lib/awetestlib/regression/awetest_dsl.rb +4240 -0
  14. data/lib/awetestlib/regression/browser.rb +514 -397
  15. data/lib/awetestlib/regression/date_and_time.rb +280 -0
  16. data/lib/awetestlib/regression/drag_and_drop.rb +24 -0
  17. data/lib/awetestlib/regression/find.rb +70 -43
  18. data/lib/awetestlib/regression/legacy.rb +1 -1
  19. data/lib/awetestlib/regression/mobile.rb +293 -0
  20. data/lib/awetestlib/regression/reporting.rb +298 -0
  21. data/lib/awetestlib/regression/runner.rb +156 -200
  22. data/lib/awetestlib/regression/tables.rb +117 -7
  23. data/lib/awetestlib/regression/test_data.rb +354 -0
  24. data/lib/awetestlib/regression/user_input.rb +179 -93
  25. data/lib/awetestlib/regression/utilities.rb +755 -286
  26. data/lib/awetestlib/regression/validations.rb +325 -115
  27. data/lib/awetestlib/regression/waits.rb +60 -133
  28. data/lib/awetestlib/runner.rb +5 -2
  29. data/lib/version.rb +11 -2
  30. data/setup_samples/sample_cucumber/features/step_definitions/predefined_steps.rb +109 -49
  31. data/setup_samples/sample_mobile_app/features/support/env.rb +1 -1
  32. data/test/google_search2.rb +7 -6
  33. data/test/popup_child_0.rb +13 -0
  34. data/test/popup_child_1.rb +33 -0
  35. data/test/watir_no_require.rb +13 -0
  36. data/test/watir_with_require.rb +16 -0
  37. data/test/zoho_exercise.rb +8 -8
  38. metadata +216 -303
  39. data/AwetestLib Instructions.rtf +0 -0
  40. data/awetestlib.windows.gemspec +0 -42
  41. data/lib/patches/README +0 -2
  42. data/lib/patches/firewatir.rb +0 -106
  43. data/lib/patches/watir.rb +0 -175
@@ -15,13 +15,13 @@ module Awetestlib
15
15
  end
16
16
 
17
17
  def setup
18
- # if @os.name =~ /Windows.+Server\s+2003/
18
+ # if $os.name =~ /Windows.+Server\s+2003/
19
19
  ## 'Microsoft(R) Windows(R) Server 2003, Enterprise Edition'
20
20
  # @vertical_hack_ie = 110
21
21
  # @vertical_hack_ff = 138
22
22
  # @horizontal_hack_ie = 5
23
23
  # @horizontal_hack_ff = 4
24
- # elsif @os.name =~ /Windows XP Professional/
24
+ # elsif $os.name =~ /Windows XP Professional/
25
25
  # 'Microsoft Windows XP Professional'
26
26
  @vertical_hack_ie = 118
27
27
  @vertical_hack_ff = 144
@@ -50,39 +50,24 @@ module Awetestlib
50
50
  @y_tolerance = 4
51
51
  end
52
52
 
53
- def build_message(strg1, desc = '', strg2 = '', strg3 = '', strg4 = '')
53
+ def build_message(strg1, *strings)
54
54
  msg = "#{strg1}"
55
- msg << " #{desc}" if desc and desc.length > 0
56
- msg << " #{strg2}" if strg2 and strg2.length > 0
57
- msg << " #{strg3}" if strg3 and strg3.length > 0
58
- msg << " #{strg4}" if strg4 and strg4.length > 0
55
+ strings.each do |strg|
56
+ if strg.is_a?(Array)
57
+ strg.each do |str|
58
+ msg << " #{str}" if str and str.length > 0
59
+ end
60
+ else
61
+ msg << " #{strg}" if strg and strg.length > 0
62
+ end
63
+ end if strings
59
64
  msg
65
+ rescue
66
+ failed_to_log(unable_to)
60
67
  end
61
68
 
62
- def get_date_names(date = Date.today)
63
- this_month = date.month
64
- if this_month == 12
65
- next_month = 1
66
- else
67
- next_month = this_month + 1
68
- end
69
- if this_month == 1
70
- prev_month = 12
71
- else
72
- prev_month = this_month - 1
73
- end
74
-
75
- month_arr = ['', 'January', 'February', 'March', 'April', 'May', 'June',
76
- 'July', 'August', 'September', 'October', 'November', 'December']
77
-
78
- this_month_name = month_arr[this_month]
79
- next_month_name = month_arr[next_month]
80
- prev_month_name = month_arr[prev_month]
81
-
82
- arr = [date.year, date.day, this_month_name, next_month_name, prev_month_name]
83
- debug_to_log("#{__method__} #{nice_array(arr)}")
84
- arr
85
- end
69
+ alias build_msg build_message
70
+ alias bld_msg build_message
86
71
 
87
72
  def get_trace(lnbr)
88
73
  callertrace = "\nCaller trace: (#{lnbr})\n"
@@ -94,44 +79,43 @@ module Awetestlib
94
79
 
95
80
  alias dump_caller get_trace
96
81
 
97
- def get_mdyy(t = Time.now)
98
- "#{t.month}/#{t.day}/#{t.year}"
99
- end
100
-
101
82
  def get_prefix(strg, offset)
102
83
  a_slice = strg.slice(0, offset)
103
84
  a_slice.downcase
104
85
  end
105
86
 
106
- def get_timestamp(format = 'long', offset = nil, offset_unit = :years)
107
- t = DateTime.now
108
- if offset
109
- t = t.advance(offset_unit => offset)
110
- end
111
- case format
112
- when 'dateonly'
113
- t.strftime("%m/%d/%Y")
114
- when 'condensed'
115
- t.strftime("%Y%m%d%H%M")
116
- when 'condensed_seconds'
117
- t.strftime("%Y%m%d%H%M%S")
118
- when 'long'
119
- t.strftime("%m/%d/%Y %I:%M %p")
120
- when 'mdyy'
121
- get_mdyy(t)
122
- when 'm/d/y'
123
- get_mdyy(t)
124
- else
125
- Time.now.strftime("%m/%d/%Y %H:%M:%S")
126
- end
127
- end
128
-
129
87
  def calc_index(index, every = 1)
130
88
  (index / every) + (every - 1)
131
89
  end
132
90
 
133
- def get_variables(file, key_type = :role, dbg = true)
91
+ def get_upload_file_control_indexes
92
+ case $win_major
93
+ when '5'
94
+ case @browserAbbrev
95
+ when 'IE'
96
+ ['1', '1', '2', 'Choose File to Upload']
97
+ when 'FF'
98
+ ['1', '1', '2', 'File Upload']
99
+ when 'GC', 'C'
100
+ ['1', '1', '2', 'Open']
101
+ end
102
+ when '6'
103
+ case @browserAbbrev
104
+ when 'IE'
105
+ ['1', '1', '2', 'Choose File to Upload']
106
+ when 'FF'
107
+ ['1', '1', '2', 'File Upload']
108
+ when 'GC', 'C'
109
+ ['1', '1', '2', 'Open']
110
+ end
111
+ end
112
+ end
113
+
114
+ def get_variables(file, key_type = :role, enabled_only = true, dbg = true)
115
+
116
+ #TODO: support for xlsx files
134
117
  #TODO refactor this
118
+
135
119
  debug_to_log("#{__method__}: file = #{file}")
136
120
  debug_to_log("#{__method__}: key = #{key_type}")
137
121
 
@@ -164,60 +148,75 @@ module Awetestlib
164
148
  end if dbg
165
149
 
166
150
  @login = Hash.new
167
- login_col = 0
151
+ script_col = 0
168
152
  role_col = 0
169
153
  userid_col = 0
154
+ company_col = 0
170
155
  password_col = 0
171
156
  url_col = 0
157
+ env_col = 0
172
158
  name_col = 0
173
159
  login_index = find_sheet_with_name(workbook, 'Login')
174
160
  if login_index and login_index >= 0
175
161
  workbook.default_sheet = workbook.sheets[login_index]
176
162
 
177
163
  1.upto(workbook.last_column) do |col|
178
- a_cell = workbook.cell(1, col)
164
+ a_cell = workbook.cell(1, col).downcase
179
165
  case a_cell
180
- when @myName
181
- login_col = col
166
+ when @myName.downcase
167
+ script_col = col
182
168
  script_found_in_login = true
183
169
  break
184
170
  when 'role'
185
171
  role_col = col
186
- when 'userid'
172
+ when 'userid', 'user_id'
187
173
  userid_col = col
174
+ when 'companyid', 'company_id'
175
+ company_col = col
188
176
  when 'password'
189
177
  password_col = col
190
178
  when 'url'
191
179
  url_col = col
180
+ when 'environment'
181
+ env_col = col
192
182
  when 'name'
193
183
  name_col = col
194
184
  end
195
185
  end
196
186
 
197
187
  2.upto(workbook.last_row) do |line|
198
- role = workbook.cell(line, role_col)
199
- userid = workbook.cell(line, userid_col)
200
- password = workbook.cell(line, password_col)
201
- url = workbook.cell(line, url_col)
202
- username = workbook.cell(line, name_col)
203
- enabled = workbook.cell(line, login_col).to_s
188
+ role = workbook.cell(line, role_col)
189
+ userid = workbook.cell(line, userid_col)
190
+ password = workbook.cell(line, password_col)
191
+ url = workbook.cell(line, url_col)
192
+ env = workbook.cell(line, env_col)
193
+ username = workbook.cell(line, name_col)
194
+ companyid = workbook.cell(line, company_col)
195
+ enabled = workbook.cell(line, script_col).to_s
204
196
 
205
197
  case key_type
206
198
  when :id, :userid
207
199
  key = userid
200
+ when :environment
201
+ key = env
208
202
  when :role
209
203
  key = role
210
204
  else
211
205
  key = userid
212
206
  end
213
207
 
214
- @login[key] = Hash.new
215
- @login[key]['role'] = role
216
- @login[key]['userid'] = userid
217
- @login[key]['password'] = password
218
- @login[key]['url'] = url
219
- @login[key]['name'] = username
220
- @login[key]['enabled'] = enabled
208
+ if enabled_only and enabled.length == 0
209
+ next
210
+ end
211
+
212
+ @login[key] = Hash.new
213
+ @login[key]['role'] = role
214
+ @login[key]['userid'] = userid
215
+ @login[key]['companyid'] = companyid
216
+ @login[key]['password'] = password
217
+ @login[key]['url'] = url
218
+ @login[key]['name'] = username
219
+ @login[key]['enabled'] = enabled
221
220
 
222
221
  end
223
222
 
@@ -232,7 +231,46 @@ module Awetestlib
232
231
  failed_to_log("Script found: in Login = #{script_found_in_login}; in Data = #{script_found_in_data}")
233
232
  end
234
233
  rescue
235
- failed_to_log("#{__method__}: '#{$!}'")
234
+ failed_to_log(unable_to)
235
+ end
236
+
237
+ def translate_color_name(color)
238
+ if color and color.length > 0
239
+ HTML_COLORS[color.camelize.downcase].downcase
240
+ else
241
+ color
242
+ end
243
+ end
244
+
245
+ def translate_tag_name(element)
246
+ rtrn = ''
247
+ tag = ''
248
+ typ = ''
249
+ if element.respond_to?(:tag_name)
250
+ tag = element.tag_name
251
+ typ = element.type if element.respond_to?(:type)
252
+ rtrn = tag
253
+ case tag
254
+ when 'a'
255
+ rtrn = 'link'
256
+ when 'input'
257
+ case typ
258
+ when 'text'
259
+ rtrn = 'textfield'
260
+ when 'textarea'
261
+ rtrn = 'textarea'
262
+ when 'submit', 'button'
263
+ rtrn = 'button'
264
+ else
265
+ rtrn = tag
266
+ end
267
+ else
268
+ rtrn = tag
269
+ end
270
+ end
271
+ rtrn
272
+ rescue
273
+ failed_to_log(unable_to(tag, typ))
236
274
  end
237
275
 
238
276
  def translate_var_list(key)
@@ -247,6 +285,66 @@ module Awetestlib
247
285
  failed_to_log("#{__method__}: '#{$!}'")
248
286
  end
249
287
 
288
+ def get_awetestlib_metadata
289
+ $metadata = YAML.load(`gem spec awetestlib metadata`.chomp)
290
+ end
291
+
292
+ def parse_list(string, delim = ',', limit = -1)
293
+ string.split(/#{delim}\s*/, limit)
294
+ rescue
295
+ failed_to_log(unable_to("string:[#{string}]"))
296
+ end
297
+
298
+ def get_project_git(proj_name, proj_dir = Dir.pwd)
299
+ debug_to_log(with_caller(proj_dir))
300
+ sha = nil
301
+ branch = nil
302
+ date = nil
303
+
304
+ curr_dir = Dir.pwd
305
+ version_file = "#{proj_name.downcase.gsub(' ', '_')}_version"
306
+
307
+ if Dir.exists?(proj_dir)
308
+
309
+ Dir.chdir(proj_dir) unless proj_dir == curr_dir
310
+
311
+ if Dir.exists?('.git')
312
+ require 'git'
313
+ git = Git.open(Dir.pwd)
314
+ branch = git.current_branch
315
+ commit = git.gblob(branch).log(5).first
316
+ sha = commit.sha
317
+ date = commit.date
318
+
319
+ version_file = File.join(proj_dir, version_file)
320
+ file = File.open(version_file, 'w')
321
+ file.puts "#{branch}, #{date}, #{sha}"
322
+ file.close
323
+
324
+ end
325
+
326
+ Dir.chdir(curr_dir) unless proj_dir == curr_dir
327
+
328
+ end
329
+
330
+ unless branch
331
+ version_file = File.join(Dir.pwd, version_file)
332
+ if File.exists?(version_file)
333
+ vers = File.open(version_file).read
334
+ branch, date, sha = parse_list(vers.chomp)
335
+ end
336
+ end
337
+
338
+ [branch, date, sha]
339
+ end
340
+
341
+ def git_sha1(file)
342
+ if File.exists?(file)
343
+ size, sha1 = `ruby git_sha1.rb #{file}`.chomp.split(/\n/)
344
+ debug_to_log("#{file} #{size} sha1 is #{sha1}")
345
+ end
346
+ end
347
+
250
348
  def grab_window_list(strg)
251
349
  @ai.AutoItSetOption("WinTitleMatchMode", 2)
252
350
  list = @ai.WinList(strg)
@@ -265,25 +363,21 @@ module Awetestlib
265
363
  stuff
266
364
  end
267
365
 
366
+ def count_duplicates(arr)
367
+ counts = {}
368
+ dups = {}
369
+ arr.each do |id|
370
+ counts[id] = counts[id] ? counts[id] + 1 : 1
371
+ dups[id] = counts[id] if counts[id] > 1
372
+ end
373
+ [dups, counts]
374
+ end
375
+
268
376
  def debug_call_list(msg)
269
377
  call_array = get_call_array
270
378
  debug_to_log("#{msg}\n#{dump_array(call_array)}")
271
379
  end
272
380
 
273
- def sec2hms(s)
274
- Time.at(s.to_i).gmtime.strftime('%H:%M:%S')
275
- end
276
-
277
- def close_log(scriptName, lnbr = '')
278
- cmplTS = Time.now.to_f.to_s
279
- puts ("#{scriptName} finished. Closing log. #{lnbr.to_s}")
280
- passed_to_log("#{scriptName} run complete [#{cmplTS}]")
281
- @myLog.close()
282
- sleep(2)
283
- end
284
-
285
- protected :close_log
286
-
287
381
  def find_sheet_with_name(workbook, sheet_name)
288
382
  sheets = workbook.sheets
289
383
  idx = 0
@@ -321,33 +415,76 @@ module Awetestlib
321
415
  sprintf(ptrn, number).gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
322
416
  end
323
417
 
324
- def pad_date(dt)
325
- if dt and dt.length > 0
326
- a, d1, b, d2, c = dt.split(/([\/\.-])/)
327
- a = a.rjust(2, '0') unless a and a.length > 1
328
- b = b.rjust(2, '0') unless b and b.length > 1
329
- c = c.rjust(2, '0') unless c and c.length > 1
330
- a + d1 + b + d2 + c
331
- else
332
- ''
333
- end
334
- end
418
+ def normalize_color_value(value, rgba = true)
419
+ case value
420
+ when /^#/
421
+ html_to_rgb(value, rgba)
422
+ when /^rgba/i
423
+ value
424
+ when /^rgb()/i
425
+ rgb_to_rgba(value)
426
+ when /^transparent/i, /^0$/i
427
+ 'rgba(0, 0, 0, 0)'
428
+ when /white/
429
+ 'rgba(255, 255, 255, 1)'
430
+ else
431
+ html_to_rgb(translate_color_name(value), rgba)
432
+ end
433
+ end
434
+
435
+ def number_to_word(nbr)
436
+ map = { 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five',
437
+ 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten',
438
+ 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen',
439
+ 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty'
440
+ }
441
+ if nbr > 20
442
+ 'more than twenty'
443
+ else
444
+ map[nbr]
445
+ end
446
+ end
447
+
448
+ alias nbr2word number_to_word
449
+
450
+ def string_array_numeric_sort(arr)
451
+ #TODO: almost certainly a more 'rubyish' and less clunky way to do this
452
+ trgt = arr.dup
453
+ narr = []
454
+ trgt.each do |n|
455
+ narr << n.to_i
456
+ end
457
+ narr.sort!
458
+ sarr = []
459
+ narr.each do |n|
460
+ sarr << n.to_s
461
+ end
462
+ sarr
463
+ end
464
+
465
+ alias strg_arr_numeric_sort string_array_numeric_sort
335
466
 
336
467
  def string_count_in_string(strg, substrg)
337
468
  count = strg.scan(substrg).length
338
469
  count
339
470
  end
340
471
 
472
+ def string_to_hex(strg, format = 'U')
473
+ strg.unpack(format*strg.length)
474
+ # strg.split(//).collect do |x|
475
+ # x.match(/\d/) ? x : x.unpack('U')[0].to_s(16)
476
+ # end
477
+ end
478
+
341
479
  def strip_regex_mix(strg)
342
480
  rslt = strg.dup
343
- while match = rslt.match(/(\(\?-mix:(.+)\))/)
344
- rslt.sub!(match[1], "/#{match[2]}/")
345
- end
481
+ mtch = rslt.match(/(\(\?-mix:(.+)\))/)
482
+ rslt.sub!(mtch[1], "/#{mtch[2]}/")
346
483
  rslt
347
484
  end
348
485
 
349
486
  def rescue_me(e, me = nil, what = nil, where = nil, who = nil)
350
- #TODO: these are rescues from exceptions raised in Watir/Firewatir
487
+ #TODO: these are rescues from exceptions raised in Watir or Watir-webdriver
351
488
  debug_to_log("#{__method__}: Begin rescue")
352
489
  ok = false
353
490
  begin
@@ -358,7 +495,7 @@ module Awetestlib
358
495
  end
359
496
  msg = e.message
360
497
  debug_to_log("#{__method__}: msg = #{msg}")
361
- if msg =~ /undefined method\s+.join.\s+for/i # firewatir to_s implementation error
498
+ if msg =~ /undefined method\s+.join.\s+for/i # firewatir to_s implementation error
362
499
  ok = true
363
500
  elsif msg =~ /undefined method\s+.match.\s+for.+WIN32OLERuntimeError/i # watir and firewatir
364
501
  ok = true
@@ -372,106 +509,105 @@ module Awetestlib
372
509
  ok = true
373
510
  elsif msg =~ /wrong number of arguments \(1 for 0\)/i
374
511
  ok = true
375
- elsif (msg =~ /unable to locate element/i)
512
+ elsif msg =~ /unable to locate element/i
376
513
  if located
377
514
  ok = true
378
515
  elsif where == 'Watir::Div'
379
516
  ok = true
380
517
  end
381
- elsif (msg =~ /HRESULT error code:0x80070005/)
518
+ elsif msg =~ /(The SafariDriver does not interact with modal dialogs)/i
519
+ to_report = $1
520
+ ok = true
521
+ elsif msg =~ /HRESULT error code:0x80070005/
382
522
  ok = true
383
- #elsif msg =~ /missing\s+\;\s+before statement/
384
- # ok = true
523
+ #elsif msg =~ /missing\s+\;\s+before statement/
524
+ # ok = true
385
525
  end
526
+ call_list = get_call_list(6, true)
386
527
  if ok
387
528
  debug_to_log("#{__method__}: RESCUED: \n#{who.to_yaml}=> #{what} in #{me}()\n=> '#{$!}'")
388
529
  debug_to_log("#{__method__}: #{who.inspect}") if who
389
530
  debug_to_log("#{__method__}: #{where.inspect}")
390
- debug_to_log("#{__method__}: #{get_callers(6, true)}")
531
+ debug_to_log("#{__method__}: #{call_list}")
532
+ failed_to_log("#{to_report} #{call_list}")
391
533
  else
392
534
  debug_to_log("#{__method__}: NO RESCUE: #{e.message}")
393
- debug_to_log("#{__method__}: NO RESCUE: \n#{get_callers(6, true)}")
535
+ debug_to_log("#{__method__}: NO RESCUE: \n#{call_list}")
394
536
  end
395
537
  debug_to_log("#{__method__}: Exit")
396
538
  ok
397
539
  end
398
540
 
399
- def get_caller_line
400
- last_caller = get_call_list[0]
401
- line = last_caller.split(':', 3)[1]
402
- line
541
+ def convert_color_value(value, rgba = false)
542
+ if value =~ /^#/
543
+ html_to_rgb(value, rgba)
544
+ else
545
+ rgb_to_html(value)
546
+ end
403
547
  end
404
548
 
405
- def get_call_list(depth = 9, dbg = false)
406
- myList = []
407
- call_list = Kernel.caller
408
- puts call_list if dbg
409
- call_list.each_index do |x|
410
- myCaller = call_list[x].to_s
411
- myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
412
- myList << "[#{$1.gsub(/eval/, @myName)}] "
413
- break if x > depth or myCaller =~ /:in .run.$/
549
+ def rgb_to_html(rgb)
550
+ rgb =~ /rgba?\((.+)\)/
551
+ if $1
552
+ r, g, b, a = $1.split(/,\s*/)
553
+ "#%02x%02x%02x" % [r, g, b]
554
+ else
555
+ rgb
414
556
  end
415
- myList
416
557
  end
417
558
 
418
- alias get_callers get_call_list
419
-
420
- def get_call_list_new(depth = 9, dbg = false)
421
- myList = []
422
- call_list = Kernel.caller
423
- puts call_list if dbg
424
- call_list.each_index do |x|
425
- myCaller = call_list[x].to_s
426
- if myCaller.include? @myName
427
- myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
428
- myList << "[#{$1.gsub(/eval/, @myName)}] "
429
- break
430
- end
431
- break if x > depth or myCaller =~ /:in .run.$/ # this break causes error in Ruby 1.9.x
432
- end
433
- if @projName
434
- call_list.each_index do |x|
435
- myCaller = call_list[x].to_s
436
- if myCaller.include? @projName
437
- myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
438
- myList << "[#{$1.gsub(/eval/, @projName)}] "
439
- break
440
- end
441
- end
442
- break if x > depth or myCaller =~ /:in .run.$/ # this break causes error in Ruby 1.9.
559
+ def rgb_to_rgba(rgb)
560
+ if rgb =~ /^rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/i
561
+ r = $1
562
+ g = $2
563
+ b = $3
564
+ op = rgb =~ /[1-9]/ ? '1' : '0'
565
+ rtrn = "rgba(#{r}, #{g}, #{b}, #{op})" #waft-1148
566
+ else
567
+ rtrn = rgb
443
568
  end
444
- myList
569
+ rtrn
445
570
  end
446
571
 
447
- def get_call_array(depth = 9)
448
- arr = []
449
- call_list = Kernel.caller
450
- call_list.each_index do |x|
451
- myCaller = call_list[x].to_s
452
- myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
453
- arr << $1.gsub(/eval/, @myName)
454
- break if x > depth or myCaller =~ /:in .run.$/
572
+ def html_to_rgb(html, a = true)
573
+ if html and html.length > 0
574
+ html = html.gsub(%r{[#;]}, '')
575
+ case html.size
576
+ when 3
577
+ colors = html.scan(%r{[0-9A-Fa-f]}).map { |el| (el * 2).to_i(16) }
578
+ when 6
579
+ colors = html.scan(%r<[0-9A-Fa-f]{2}>).map { |el| el.to_i(16) }
580
+ end
581
+ rgb = 'rgb'
582
+ rgb << 'a' if a
583
+ rgb << '('
584
+ colors.each do |c|
585
+ rgb << "#{c}, "
586
+ end
587
+ if a
588
+ rgb << '1)'
589
+ else
590
+ rgb.strip!.chop!
591
+ rgb << ')'
592
+ end
593
+ rgb
594
+ else
595
+ html
455
596
  end
456
- arr
457
597
  end
458
598
 
459
- def get_debug_list(dbg = false)
460
- calls = get_call_array(10)
461
- puts "#{calls.to_yaml}" if dbg
462
- arr = []
463
- calls.each_index do |ix|
464
- if ix > 1 # skip this method and the logging method
465
- arr << calls[ix]
599
+ def analyse_element_presence(container, element, how, what, max_seconds = 30, interval = 0.25)
600
+ duration = 0
601
+ code = build_webdriver_fetch(element, how, what) + '.present?'
602
+ debug_to_log("#{__method__}: code=>[#{code}")
603
+ until duration > max_seconds do
604
+ begin
605
+ debug_to_log("#{eval(code)} #{duration}")
606
+ rescue => e
607
+ debug_to_log("#{__method__}: #{e.inspect}")
466
608
  end
467
- end
468
- puts "#{arr.to_yaml}" if dbg
469
- if arr.length > 0
470
- list = 'TRACE:'
471
- arr.reverse.each { |l| list << "=>#{l}" }
472
- " [[#{list}]]"
473
- else
474
- nil
609
+ duration += interval
610
+ sleep(interval)
475
611
  end
476
612
  end
477
613
 
@@ -536,23 +672,10 @@ module Awetestlib
536
672
  end
537
673
  end
538
674
 
539
- def dump_all_tables(browser, to_report = false)
540
- tables = browser.tables
541
- msg = ''
542
- tbl_cnt = 0
543
- tables.each do |tbl|
544
- tbl_cnt += 1
545
- row_cnt = 0
546
- msg << "\n=================\ntable: #{tbl_cnt}\n=================\n#{tbl}\ntext:\n#{tbl.text}"
547
- tbl.rows.each do |row|
548
- row_cnt += 1
549
- cell_cnt = 0
550
- msg << "\n=================\ntable: #{tbl_cnt} row: #{row_cnt}\n#{row.inspect}\n#{row}\ntext:'#{row.text}'"
551
- row.each do |cell|
552
- cell_cnt += 1
553
- msg << " \ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
554
- end
555
- end
675
+ def dump_option_array(options, desc = '', to_report = false)
676
+ msg = with_caller(desc, "\n")
677
+ options.each do |option|
678
+ msg << "text: '#{option.text}' value: '#{option.value}' selected: #{option.selected?}\n"
556
679
  end
557
680
  if to_report
558
681
  debug_to_report(msg)
@@ -561,59 +684,193 @@ module Awetestlib
561
684
  end
562
685
  end
563
686
 
564
- def dump_table_and_rows(table, to_report = false)
565
- msg = "\n=================\ntable\n=================\nn#{table}\n#{table.to_yaml}\nrows:"
566
- cnt = 0
567
- table.rows.each do |r|
568
- cnt += 1
569
- msg << "\n#{cnt}: #{r.text}"
687
+ def parse_cookies(browser)
688
+ cookies = Hash.new
689
+ strg = browser.document.cookie
690
+ ary = strg.split(';')
691
+ ary.each do |c|
692
+ key, value = c.split('=')
693
+ cookies[key.lstrip] = value
570
694
  end
571
- msg << "\n=================\n================="
572
- if to_report
573
- debug_to_report(msg)
695
+ cookies
696
+ end
697
+
698
+ def parse_test_flag(string)
699
+ test = false
700
+ refs = nil
701
+ if string
702
+ if string == true or string == false
703
+ test = string
704
+ else
705
+ if string.length > 0
706
+ unless string =~ /^no$/i
707
+ test = true
708
+ unless string =~ /^yes$/i
709
+ refs = format_refs(string)
710
+ end
711
+ end
712
+ end
713
+ end
714
+ end
715
+ [test, refs]
716
+ rescue
717
+ failed_to_log(unable_to)
718
+ end
719
+
720
+ def build_webdriver_fetch(element, how, what, more = {})
721
+ code = "container.#{element}(:#{how} => "
722
+ what = escape_stuff(what) unless how == :index
723
+ if what.is_a?(Regexp)
724
+ code << "/#{what.source}/"
725
+ elsif how == :index
726
+ code << "#{what}"
574
727
  else
575
- debug_to_log(msg)
728
+ code << "'#{what}'"
576
729
  end
730
+ if more and not more.empty?
731
+ more.each do |key, vlu|
732
+ next if key == :desc or key == :flash or key == :exists_only
733
+ code << ", :#{key} => "
734
+ if vlu.is_a?(Regexp)
735
+ code << "/#{vlu}/"
736
+ elsif vlu.is_a?(String)
737
+ code << "'#{vlu.gsub('/', '\/')}'"
738
+ else
739
+ code << "#{vlu}"
740
+ end
741
+ end
742
+ end
743
+ code << ')'
744
+ #debug_to_log("code: '#{code}'")
745
+ code
746
+ rescue
747
+ failed_to_log(unable_to)
577
748
  end
578
749
 
579
- def dump_table_rows_and_cells(tbl)
580
- msg = ''
581
- row_cnt = 0
582
- msg << "\n=================\ntable: #{tbl.inspect}\n=================\n#{tbl}\ntext:\n#{tbl.text}"
583
- tbl.rows.each do |row|
584
- row_cnt += 1
585
- cell_cnt = 0
586
- msg << "\n=================\nrow: #{row_cnt}\n#{row.inspect}\n#{row}\ntext:'#{row.text}'"
587
- row.each do |cell|
588
- cell_cnt += 1
589
- msg << "\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
750
+ def element_action_message(element, action, how = nil, what = nil, value = nil, desc = '', refs = '')
751
+ name = element.respond_to?(:tag_name) ? element.tag_name.upcase : element.to_s
752
+ how, what = extract_locator(element, how)[1, 2] unless how and what
753
+ build_message(desc, action, "#{name}",
754
+ (what ? "with #{how}=>'#{what}'" : nil),
755
+ (value ? "and value=>'#{value}'" : nil), refs)
756
+ end
757
+
758
+ def element_query_message(element, query, how = nil, what = nil, value = nil, desc = '', refs = '')
759
+ if element.exists?
760
+ name = element.respond_to?(:tag_name) ? element.tag_name.upcase : element.to_s
761
+ else
762
+ name = '(unknown)'
763
+ end
764
+ build_message(desc, "#{name}",
765
+ (what ? "with #{how}=>' #{what}'" : nil),
766
+ (value ? "and value=>'#{value}'" : nil),
767
+ query, refs)
768
+ rescue
769
+ failed_to_log(unable_to)
770
+ end
771
+
772
+ def end_processes(*names)
773
+ pattern = ''
774
+ names.each { |n| pattern << "#{n}|" }
775
+ pattern.chop!
776
+ # puts pattern
777
+ targets = {}
778
+
779
+ if USING_OSX
780
+ p_io = IO.popen("ps axo comm,pid,sess,fname")
781
+ else
782
+ p_io = IO.popen("tasklist /nh")
783
+ end
784
+
785
+ p_io.readlines.each do |prc|
786
+ # puts prc.chop
787
+ if prc =~ /#{pattern}/
788
+ name, pid = prc.split(/\s+/)[0, 2]
789
+ # puts "#{name} #{pid}"
790
+ base = File.basename(name)
791
+ targets[pid] = base
590
792
  end
591
793
  end
592
- debug_to_log(msg)
794
+
795
+ debug_to_log("End these processes:\n#{targets.to_yaml}")
796
+
797
+ if USING_OSX
798
+ kill_cmd = 'kill -9 @@@@@'
799
+ else
800
+ kill_cmd = 'taskkill /f /pid @@@@@'
801
+ end
802
+
803
+ targets.each do |pid, name|
804
+ cmd = kill_cmd.sub('@@@@@', pid)
805
+ debug_to_log("[#{cmd}]")
806
+ kill_io = IO.popen(cmd, :err => :out)
807
+ debug_to_log(kill_io.read.chomp)
808
+ end
809
+
810
+ if targets.length > 0
811
+ sleep_for(10)
812
+ end
593
813
  end
594
814
 
595
- alias dump_table_rows dump_table_rows_and_cells
815
+ def escape_stuff(strg)
816
+ if strg.respond_to?(:dup)
817
+ rslt = strg.dup
818
+ unless rslt.is_a?(Regexp)
819
+ if rslt.match(/[\/\(\)]/)
820
+ rslt.gsub!('/', '\/')
821
+ rslt.gsub!('(', '\(')
822
+ rslt.gsub!(')', '\)')
823
+ rslt = Regexp.new(rslt)
824
+ end
825
+ end
826
+ else
827
+ rslt = strg
828
+ end
829
+ rslt
830
+ rescue
831
+ failed_to_log(unable_to("#{rslt}"))
832
+ end
596
833
 
597
- def dump_row_cells(row)
598
- msg = ''
599
- cell_cnt = 0
600
- msg << "\n=================\nrow: #{row.inspect}\n#{row}\ntext:'#{row.text}'"
601
- row.each do |cell|
602
- cell_cnt += 1
603
- msg << "\ncell: #{cell_cnt}\n#{cell.inspect}\n#{row}\ntext: '#{cell.text}'"
834
+ def extract_selected(selected_options, which = :text)
835
+ arr = Array.new
836
+ selected_options.each do |so|
837
+ case which
838
+ when :text
839
+ arr << so.text
840
+ else
841
+ arr << so.value
842
+ end
604
843
  end
605
- debug_to_log(msg)
844
+ arr.sort
845
+ rescue
846
+ failed_to_log(unable_to)
606
847
  end
607
848
 
608
- def parse_cookies(browser)
609
- cookies = Hash.new
610
- strg = browser.document.cookie
611
- ary = strg.split(';')
612
- ary.each do |c|
613
- key, value = c.split('=')
614
- cookies[key.lstrip] = value
849
+ def extract_locator(element, how = nil)
850
+ # html_to_log(element)
851
+ if element.respond_to?(:tag_name)
852
+ tag = element.tag_name.to_sym
853
+ else
854
+ element = element.body.elements[0]
855
+ tag = element.tag_name.to_sym
615
856
  end
616
- cookies
857
+ what = nil
858
+ case how
859
+ when nil
860
+ [:id, :name, :title, :class, :value].each do |attr|
861
+ what = element.attribute_value(attr.to_s)
862
+ if what and what.length > 0
863
+ how = attr
864
+ break
865
+ end
866
+ end
867
+ else
868
+ what = element.attribute_value(how.to_s)
869
+ end
870
+ # debug_to_log(with_caller("#{tag}:#{how}:#{what}"))
871
+ [tag, how, what]
872
+ rescue
873
+ failed_to_log(unable_to(build_message(":#{tag}, :#{how}='#{what}'")))
617
874
  end
618
875
 
619
876
  def capture_screen(browser, ts)
@@ -657,12 +914,30 @@ module Awetestlib
657
914
  failed_to_log("Unable to #{msg} '#{$!}'")
658
915
  end
659
916
 
660
- def flash(element, count = 4)
661
- element.flash(count)
662
- debug_to_log("'#{element.inspect}' flashed #{count} times.")
663
- true
917
+ def flash(container, element, how, what, value = nil, desc = '', refs = '', options = {})
918
+ if @flash
919
+ value, desc, refs, options = capture_value_desc(value, desc, refs, options) # for backwards compatibility
920
+ code = build_webdriver_fetch(element, how, what, options)
921
+ target = eval(code)
922
+ flash_element(target, desc, refs)
923
+ end
924
+ rescue
925
+ failed_to_log(unable_to)
926
+ end
927
+
928
+ def flash_element(element, desc = '', refs = '')
929
+ if @flash
930
+ if element
931
+ element.wd.location_once_scrolled_into_view
932
+ # scroll_to(element.browser, element, desc, refs)
933
+ if element.respond_to?(:flash)
934
+ # sleep(0.1)
935
+ element.flash
936
+ end
937
+ end
938
+ end
664
939
  rescue
665
- debug_to_log("Flash '#{element.inspect}' failed: '#{$!}' (#{__LINE__})")
940
+ failed_to_log(unable_to)
666
941
  end
667
942
 
668
943
  def get_save_file_path(root, filename)
@@ -747,6 +1022,28 @@ module Awetestlib
747
1022
  failed_to_log("Save file failed: #{desc} '#{$!}'. (#{__LINE__})")
748
1023
  end
749
1024
 
1025
+ def rotate_array(arr, stop = 0, index = 0, target = '')
1026
+ rotated = arr.dup
1027
+ length = rotated.size
1028
+ (1..length).each do |itr|
1029
+ rotated.push(rotated.shift)
1030
+ if stop > 0
1031
+ break if itr == stop
1032
+ else
1033
+ break if rotated[index] == target
1034
+ end
1035
+ end
1036
+ rotated
1037
+ rescue
1038
+ failed_to_log(unable_to)
1039
+ end
1040
+
1041
+ def running_thread_count
1042
+ running = Thread.list.select { |thread| thread.status == "run" }.count
1043
+ asleep = Thread.list.select { |thread| thread.status == "sleep" }.count
1044
+ [running, asleep]
1045
+ end
1046
+
750
1047
  #method for handling save dialog
751
1048
  #use click_no_wait on the action that triggers the save dialog
752
1049
  def save_file(filepath, download_title = "File Download - Security Warning")
@@ -887,7 +1184,7 @@ module Awetestlib
887
1184
  #use click_no_wait on the action that triggers the save dialog
888
1185
  # TODO need version for Firefox
889
1186
  def file_upload(filepath, title = 'Choose File', text = '', button = '&Open',
890
- control = 'Edit1', side = 'primary')
1187
+ control = 'Edit1', side = 'primary')
891
1188
  title = translate_popup_title(title)
892
1189
  msg = "Window title=#{title} button='#{button}' text='#{text}' side='#{side}':"
893
1190
  begin
@@ -922,20 +1219,22 @@ module Awetestlib
922
1219
 
923
1220
  end
924
1221
 
925
- def upload_file(data_path)
926
- limit = 180 # .seconds
927
- Timeout::timeout(limit) {
928
- wait = 20
929
- @ai.WinWait("Choose File to Upload", "", wait)
930
- sleep 1
931
- @ai.ControlSend("Choose File to Upload", "", "Edit1", data_path)
932
- @ai.ControlClick("Choose File to Upload", "", "[CLASS:Button; INSTANCE:2]", "left")
933
- sleep 4
934
- #sleep 1
935
- }
936
- failed_to_log("Choose File to Upload not found after #{limit} '#{$!}'")
937
- rescue Timeout::Error
938
- failed_to_log("File Upload timeout after #{limit} '#{$!}'")
1222
+ def upload_file(browser, data_path, wait = 20)
1223
+ #mark_test_level(data_path)
1224
+ message_to_report(with_caller(data_path))
1225
+ data_path.gsub!('/', '\\') if USING_WINDOWS
1226
+
1227
+ file, open, cancel, title = get_upload_file_control_indexes
1228
+
1229
+ @ai.WinWait(title, "", wait)
1230
+ sleep_for(1)
1231
+ @ai.ControlSend(title, '', "[CLASS:Edit; INSTANCE:#{file}]", '!u')
1232
+ @ai.ControlSetText(title, '', "[CLASS:Edit; INSTANCE:#{file}]", data_path)
1233
+ sleep_for(0.5)
1234
+ @ai.ControlClick(title, "", "[CLASS:Button; INSTANCE:#{open}]", "primary")
1235
+
1236
+ rescue
1237
+ failed_to_log(unable_to)
939
1238
  end
940
1239
 
941
1240
  def focus_on_textfield_by_id(browser, strg, desc = '')
@@ -981,25 +1280,43 @@ module Awetestlib
981
1280
  loc
982
1281
  end
983
1282
 
984
- def method_to_title(method, no_sub = false)
1283
+ def rescue_msg_for_validation(desc, refs = nil)
1284
+ failed_to_log(unable_to(build_message(desc, refs), NO_DOLLAR_BANG, VERIFY_MSG), 2)
1285
+ end
1286
+
1287
+ def method_to_title(method, no_sub = false, subs = { /And/ => '&', /^Ac / => 'AC ' })
985
1288
  title = method.to_s.titleize
986
- title.gsub!(/And/, '&') unless no_sub
1289
+ unless no_sub
1290
+ subs.each do |ptrn, rplc|
1291
+ title.gsub!(ptrn, rplc)
1292
+ end
1293
+ end
987
1294
  title
988
1295
  rescue
989
- debug_to_log("#{__method__}: #{method} #{$!}")
1296
+ debug_to_log(unable_to(": #{method}"))
990
1297
  end
991
1298
 
992
- def unable_to(message = '', no_dolbang = false, verify_that = false)
993
- call_arr = get_call_array()
994
- call_script, call_line, call_meth = parse_caller(call_arr[1])
1299
+ def unable_to(message = '', no_dolbang = false, verify_that = false, caller_index = 1)
1300
+ call_arr = get_call_array
1301
+ puts call_arr
1302
+ call_script, call_line, call_meth = parse_caller(call_arr[caller_index])
995
1303
  strg = "Unable to"
996
1304
  strg << " verify" if verify_that
997
1305
  strg << " #{call_meth.titleize}:"
1306
+ strg << '?' if call_meth =~ /\?/
1307
+ strg << ':'
998
1308
  strg << " #{message}" if message.length > 0
999
1309
  strg << " '#{$!}'" unless no_dolbang
1000
1310
  strg
1001
1311
  end
1002
1312
 
1313
+ def pad_id_end_count(id, delim = '_', pad = 6)
1314
+ mtch = id.match(/^(.*)#{delim}(\d+)$/)
1315
+ mtch[1] + delim + mtch[2].rjust(pad, '0')
1316
+ rescue
1317
+ failed_to_log(unable_to("id: '#{id}' delim: '#{delim}' pad: #{pad}"))
1318
+ end
1319
+
1003
1320
  def parse_caller(caller)
1004
1321
  call_script, call_line, call_meth = caller.split(':')
1005
1322
  call_script.gsub!(/\.rb/, '')
@@ -1009,45 +1326,197 @@ module Awetestlib
1009
1326
  [call_script, call_line, call_meth]
1010
1327
  end
1011
1328
 
1012
- def get_test_level
1013
- arr = []
1014
- each_line = 0
1015
- call_list = Kernel.caller
1016
- #debug_to_log("#{call_list.to_yaml}")
1017
- call_list.each_index do |x|
1018
- myCaller = call_list[x].to_s
1019
- myCaller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/
1020
- string = $1
1021
- unless string =~ /logging\.rb|mark_testlevel|mark_test_level|debug_to_report|debug_toreport/
1022
- if string.length > 0
1023
- if string =~ /each|each_key/
1024
- each_line = string.match(/\:(\d+)\:/)[1]
1025
- elsif string.match(/\:(\d+)\:/)[1] == each_line
1026
- next
1329
+ def insert_id_pswd_in_url(userid, password, url)
1330
+ http = url.match(/^(http)(s?)(:\/\/)/)
1331
+ path = url.gsub(http[0], '')
1332
+ URI.encode("#{http[0]}#{userid}:#{password}@#{path}")
1333
+ end
1334
+
1335
+ def get_basic_auth_control_indexes
1336
+ case $win_major
1337
+ when '5'
1338
+ case @browserAbbrev
1339
+ when 'IE'
1340
+ ['2', '3', '1', 'Connect to']
1341
+ when 'FF'
1342
+ ['2', '3', '1', 'Authentication Required']
1343
+ when 'GC', 'C'
1344
+ ['2', '1', '2', 'Authentication Required']
1345
+ end
1346
+ when '6'
1347
+ case @browserAbbrev
1348
+ when 'IE'
1349
+ ['1', '2', '2', 'Windows Security']
1350
+ when 'FF'
1351
+ ['2', '1', '2', 'Authentication Required']
1352
+ when 'GC', 'C'
1353
+ ['2', '1', '2', 'Authentication Required']
1354
+ end
1355
+ end
1356
+ end
1357
+
1358
+ def windows_to_log(browser)
1359
+ msg = ("===== Current windows (#{where_am_i?(2)})")
1360
+ idx = 0
1361
+ browser.windows.each do |w|
1362
+ msg << "\n #{idx}: #{w.title} current?=#{w.current?}" #" (#{w.url})"
1363
+ idx += 1
1364
+ end
1365
+ debug_to_log(msg)
1366
+ rescue => e
1367
+ debug_to_log(unable_to("#{where_am_i?(2)}: #{e.inspect}"))
1368
+ end
1369
+
1370
+ # def where_am_i?(index = 1)
1371
+ # get_call_list_new[index].to_s
1372
+ # end
1373
+
1374
+ def get_windows_version
1375
+ ver = `ver`.gsub("\n", '')
1376
+ mtch = ver.match(/(.*)\s\[Version\s*(\d+)\.(\d+)\.(\d+)\]/)
1377
+ $win_name = mtch[1]
1378
+ $win_major = mtch[2]
1379
+ $win_minor = mtch[3]
1380
+ $win_build = mtch[4]
1381
+ $win_version = "#{$win_major}.#{$win_minor}.#{$win_build}"
1382
+ rescue
1383
+ failed_to_log(unable_to)
1384
+ end
1385
+
1386
+ def set_env_name(xls = @xls_path, fix = :prefix, strg = 'toad')
1387
+ if fix == :prefix
1388
+ pattern = /#{strg}_([\w\d]+)\.xls$/
1389
+ else
1390
+ pattern = /([\w\d]+)_#{strg}\.xls$/
1391
+ end
1392
+ if awetestlib?
1393
+ if @runenv
1394
+ @env_name = @myAppEnv.name.downcase.underscore
1395
+ else
1396
+ @env_name = 'dev'
1397
+ #if xls
1398
+ # xls =~ pattern
1399
+ # @env_name = $1
1400
+ #else
1401
+ # @env_name = 'sit'
1402
+ #end
1403
+ end
1404
+ else
1405
+ @env_name = @myAppEnv.name.downcase # .underscore #.gsub(/^toad./, '')
1406
+ end
1407
+ debug_to_report("#{__LINE__}: @env_name=#{@env_name}")
1408
+ rescue
1409
+ failed_to_log(unable_to)
1410
+ end
1411
+
1412
+ def set_xls_spec(proj_acro = 'unknown', env = @env_name.downcase.underscore, fix = :prefix, xlsx = @xlsx)
1413
+ env = env.split(/:[\s_]*/)[1] if env =~ /:/
1414
+ case fix
1415
+ when :prefix
1416
+ xls_name = "#{proj_acro}_#{env}.xls"
1417
+ when :suffix
1418
+ xls_name = "#{env}_#{proj_acro}.xls"
1419
+ when :none
1420
+ xls_name = "#{env.gsub('-', '_')}.xls"
1421
+ else
1422
+ failed_to_log(with_caller("Unknown fix type: '#{fix}'. Must be 'prefix', 'suffix', or 'none'."))
1423
+ return nil
1424
+ end
1425
+ spec = "#{@myRoot}/#{xls_name}"
1426
+ spec << 'x' if xlsx
1427
+ debug_to_log("#{where_am_i?}: #{spec}")
1428
+ spec
1429
+ rescue
1430
+ failed_to_log(unable_to)
1431
+ end
1432
+
1433
+ def format_refs(list)
1434
+ refs = ''
1435
+ if list
1436
+ list.split(/,\s*/).each do |ref|
1437
+ refs << "*** #{ref} *** "
1438
+ end
1439
+ end
1440
+ refs
1441
+ end
1442
+
1443
+ def force_regexp(target)
1444
+ if target.respond_to?(:dup)
1445
+ rslt = target.dup
1446
+ unless rslt.is_a?(Regexp)
1447
+ rslt = Regexp.new(Regexp.escape(target.to_s))
1448
+ end
1449
+ else
1450
+ rslt = target
1451
+ end
1452
+ rslt
1453
+ rescue
1454
+ failed_to_log(unable_to("'#{target}'"))
1455
+ end
1456
+
1457
+ def force_string(target, slash_regexp = true)
1458
+ if target
1459
+ if target.respond_to?(:dup)
1460
+ rslt = target.dup
1461
+ if rslt.is_a?(Regexp)
1462
+ if slash_regexp
1463
+ rslt = "/#{rslt.source}/"
1027
1464
  else
1028
- arr << string.gsub(/eval/, @myName)
1465
+ rslt = rslt.source
1029
1466
  end
1030
1467
  end
1468
+ else
1469
+ rslt = target.to_s
1470
+ end
1471
+ else
1472
+ rslt = ''
1473
+ end
1474
+ rslt
1475
+ rescue
1476
+ failed_to_log(unable_to("'#{target}'"))
1477
+ end
1478
+
1479
+ def array_neighbors(arr, target)
1480
+ less_than = []
1481
+ greater_than = []
1482
+ arr.each do |elmt|
1483
+ if elmt < target
1484
+ less_than << elmt
1485
+ elsif elmt > target
1486
+ greater_than << elmt
1487
+ end
1488
+ end
1489
+ [less_than.max, greater_than.min]
1490
+ end
1491
+
1492
+ def array_to_list(arr, delim = ',')
1493
+ list = ''
1494
+ arr.each do |entry|
1495
+ if entry =~ /#{delim}/
1496
+ list << "\"#{entry}\""
1497
+ else
1498
+ list << entry
1031
1499
  end
1032
- break if myCaller =~ /:in .run.$|runner\.rb/
1500
+ list << "#{delim} " unless entry == arr.last
1033
1501
  end
1034
- #debug_to_log("#{arr.length} #{nice_array(arr)}")
1035
- [arr.length, arr]
1502
+ list
1036
1503
  end
1037
1504
 
1505
+ alias arr2list array_to_list
1506
+
1038
1507
  def awetestlib?
1039
- not Awetestlib::Runner.nil?
1508
+ defined? Awetestlib::Runner
1040
1509
  rescue
1041
1510
  return false
1042
1511
  end
1043
1512
 
1044
1513
  def get_os
1045
- @os = OpenStruct.new(
1046
- :name => Sys::Uname.sysname,
1047
- :version => Sys::Uname.version,
1048
- :release => Sys::Uname.release,
1049
- :nodename => Sys::Uname.nodename,
1050
- :machine => Sys::Uname.machine
1514
+ $os = OpenStruct.new(
1515
+ :name => Sys::Uname.sysname,
1516
+ :version => Sys::Uname.version,
1517
+ :release => Sys::Uname.release,
1518
+ :nodename => Sys::Uname.nodename,
1519
+ :machine => Sys::Uname.machine
1051
1520
  )
1052
1521
  end
1053
1522