awetestlib 0.0.2-x86-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +70 -0
- data/awetestlib.gemspec +57 -0
- data/awetestlib.windows.gemspec +41 -0
- data/awetestlib_notes.txt +4 -0
- data/awetestlib_osx.gemspec +43 -0
- data/bin/awetestlib +67 -0
- data/create_zoho_account1.rb +66 -0
- data/create_zoho_account2.rb +70 -0
- data/demo.rb +86 -0
- data/ext/mkrf_conf.rb +27 -0
- data/google_search1.rb +16 -0
- data/google_search2.rb +19 -0
- data/lib/awetestlib.rb +39 -0
- data/lib/patches/README +2 -0
- data/lib/patches/firewatir.rb +106 -0
- data/lib/patches/watir.rb +175 -0
- data/lib/regression/legacy.rb +4615 -0
- data/lib/regression/logging.rb +444 -0
- data/lib/regression/runner.rb +264 -0
- data/lib/regression/validations.rb +1508 -0
- data/lib/version.rb +4 -0
- data/zoho_util.rb +484 -0
- data/zoho_variables.xls +0 -0
- metadata +326 -0
@@ -0,0 +1,444 @@
|
|
1
|
+
#require 'screencap'
|
2
|
+
module Logging
|
3
|
+
|
4
|
+
def self.included(mod)
|
5
|
+
# puts "RegressionSupport::Logging extended by #{mod}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def log_message(severity, message, tag = '', lnbr = nil, addts = 1, exception=nil)
|
9
|
+
# caller = get_caller(lnbr, exception)
|
10
|
+
|
11
|
+
# @sequence ||= log_properties ? log_properties.fetch('sequence', 0) : 0
|
12
|
+
# @sequence += 1
|
13
|
+
|
14
|
+
t = Time.now.utc
|
15
|
+
@last_t ||= t
|
16
|
+
|
17
|
+
# if log_properties
|
18
|
+
# log_args = {
|
19
|
+
# :cycle => @cycle,
|
20
|
+
# :browser_sequence => @browser_sequence,
|
21
|
+
# :session_num => @session_num,
|
22
|
+
# :sequence => @sequence,
|
23
|
+
# :job_id => log_properties['job_id'],
|
24
|
+
## :project_version_id => log_properties['project_version_id'],
|
25
|
+
# :test_run_id => log_properties['test_run_id'],
|
26
|
+
# :script_id => log_properties['script_id'],
|
27
|
+
# :caller => caller.split(":")[0] || 'unknown',
|
28
|
+
# :caller_line => caller.split(":")[1].to_i,
|
29
|
+
# :caller_method => caller.split(":")[2],
|
30
|
+
# :severity => severity,
|
31
|
+
# :message => message.gsub(/[\x80-\xff]/,"?"),
|
32
|
+
# :detail_timestamp => t.to_f.to_s,
|
33
|
+
# :duration => t.to_f-@last_t.to_f,
|
34
|
+
# :created_at => t,
|
35
|
+
### :company_id => log_properties['company_id'],
|
36
|
+
# :project_id => log_properties['project_id'],
|
37
|
+
# :level => tag.andand.is_a?(Fixnum) ? tag : nil,
|
38
|
+
# :pass => pass_code_for(tag),
|
39
|
+
# :test_category_id => log_properties['test_category_id'],
|
40
|
+
# :test_case_id => log_properties['test_case_id'],
|
41
|
+
# :application_role_id => nil, # not implemented yet
|
42
|
+
# :screen_path => nil
|
43
|
+
# }
|
44
|
+
# Resque::Job.create(log_queue.to_sym, log_class, log_args) if log_queue && log_class
|
45
|
+
#
|
46
|
+
# ::Screencap.capture(Shamisen::BROWSER_MAP[@browser],
|
47
|
+
# log_properties['test_run_id'], @sequence, root_path) if @screencap_path
|
48
|
+
#end
|
49
|
+
|
50
|
+
@last_t = t
|
51
|
+
|
52
|
+
dt = t.strftime("%Y%m%d %H%M%S")+' '+t.usec.to_s[0, 4]
|
53
|
+
mySev = translate_severity(severity)
|
54
|
+
myCaller = get_caller(lnbr) || 'unknown'
|
55
|
+
|
56
|
+
myMsg = "%-8s" % mySev
|
57
|
+
myMsg << '[' + dt + ']:'
|
58
|
+
if tag
|
59
|
+
if tag.is_a? Fixnum
|
60
|
+
tag = '-LVL' + tag.to_s
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
myMsg << "[%-5s]:" % tag
|
65
|
+
#myMsg << '[' + t.to_f.to_s + ']:'
|
66
|
+
#myMsg << '[' + myCaller + ']:'
|
67
|
+
#myMsg << "#{get_call_list[-1]}#{get_call_list[-2]} "
|
68
|
+
myMsg << get_call_list_new.to_s
|
69
|
+
myMsg << ' '+message
|
70
|
+
# myMsg << " {#{lnbr}} " if lnbr
|
71
|
+
|
72
|
+
# # TODO This is broken: @myBrowser is not necessarily populated
|
73
|
+
# if @screenCaptureOn and is_browser?(@myBrowser)
|
74
|
+
# if severity >= @options['screenshot'] andand
|
75
|
+
# tag.match(/PASS|FAIL/)
|
76
|
+
# then
|
77
|
+
# capture_screen(@myBrowser, t)
|
78
|
+
# end
|
79
|
+
# end
|
80
|
+
|
81
|
+
@myLog.add(severity, myMsg) if @myLog # add persistent logging for awetestlib. pmn 05jun2012
|
82
|
+
puts myMsg+"\n"
|
83
|
+
|
84
|
+
nil # so method doesn't return whole @output.
|
85
|
+
end
|
86
|
+
|
87
|
+
#private log_message
|
88
|
+
|
89
|
+
def pass_code_for(tag)
|
90
|
+
case
|
91
|
+
when tag =~ /PASS/
|
92
|
+
'P'
|
93
|
+
when tag =~ /FAIL/
|
94
|
+
'F'
|
95
|
+
#when tag =~ /\d+/ # avoid having to require andand for awetestlib. pmn 05jun2012
|
96
|
+
when tag.andand.is_a?(Fixnum)
|
97
|
+
'H'
|
98
|
+
when tag =~ /DONE/
|
99
|
+
'D'
|
100
|
+
when tag =~ /role/
|
101
|
+
'R'
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def log_sikuli_output(output_file, passed)
|
106
|
+
output_lines = File.open(output_file, 'r') { |f| f.readlines }
|
107
|
+
puts "IM FAILING?! #{passed}"
|
108
|
+
|
109
|
+
# if passed
|
110
|
+
|
111
|
+
log_messages = ['[log]', '[error]']
|
112
|
+
output_lines = output_lines.select { |l| log_messages } #.detect{|msg| l.include?(msg)} }
|
113
|
+
while line = output_lines.shift do
|
114
|
+
puts "line to be logged: #{line}"
|
115
|
+
if line.include? '[log]'
|
116
|
+
passed_to_log line
|
117
|
+
elsif line.include? '[error]'
|
118
|
+
failed_to_log line
|
119
|
+
elsif line.match /\s*Exception/
|
120
|
+
failed_to_log output_lines.join("\n")
|
121
|
+
break
|
122
|
+
else
|
123
|
+
debug_tolog line
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# else
|
128
|
+
# failed_to_log "SIKULI LOG:\n\n #{output_lines.join('\n')}"
|
129
|
+
# end
|
130
|
+
|
131
|
+
return { :result => passed, :msg => output_str }
|
132
|
+
end
|
133
|
+
|
134
|
+
# Put status message to the log and output window
|
135
|
+
# TODO: figure out a way to do the leveling automatically based on actual call depth within script (and project library?)
|
136
|
+
# When using to mark test groupings, include
|
137
|
+
# level 'lvl' (numeric literal, 1 through 9, usually 1-4)
|
138
|
+
# indicating test grouping hierarchy:
|
139
|
+
# 0 lowest level test case, a single validation
|
140
|
+
# a.k.a TEST CASE, VALIDATION
|
141
|
+
# not normally used in scripts as it is
|
142
|
+
# implied by method with 'validate' in name
|
143
|
+
# 1 group of closely related level 0 validations
|
144
|
+
# a.k.a TEST GROUP
|
145
|
+
# should never be followed by another level 1
|
146
|
+
# or higher level message without intervening
|
147
|
+
# level 0 validations.
|
148
|
+
# 2 group of closely related level 1 validation sets.
|
149
|
+
# a.k.a TEST SET, SUBMODULE, USE CASE
|
150
|
+
# should never be followed by another level 2
|
151
|
+
# or higher level message without intervening
|
152
|
+
# lower levels.
|
153
|
+
# 3 group of closely related level 2 validation sets.
|
154
|
+
# a.k.a TEST SET, TEST SUITE, MODULE, USE CASE
|
155
|
+
# should never be followed by another level 3
|
156
|
+
# or higher level message without intervening
|
157
|
+
# lower levels.
|
158
|
+
# 4 group of closely related level 3 validation sets.
|
159
|
+
# a.k.a TEST SUITE, APPLICATION UNDER TEST, PLAN, PROJECT
|
160
|
+
# should never be followed by another level 4
|
161
|
+
# or higher level message without intervening
|
162
|
+
# lower levels. Will seldom appear directly in
|
163
|
+
# scripts
|
164
|
+
|
165
|
+
=begin rdoc
|
166
|
+
category: Logging
|
167
|
+
tags: report, log, test level
|
168
|
+
=end
|
169
|
+
def mark_testlevel(message, lvl, desc = '', dbg = nil)
|
170
|
+
strg = ''
|
171
|
+
strg << message
|
172
|
+
strg << " [#{desc}]" if desc.length > 0
|
173
|
+
strg << " \n#{get_debug_list}" if dbg or @debug_calls
|
174
|
+
log_message(INFO, strg, lvl, 1)
|
175
|
+
rescue
|
176
|
+
failed_to_log("#{__method__}: #{$!}")
|
177
|
+
end
|
178
|
+
|
179
|
+
alias mark_test_level mark_testlevel
|
180
|
+
|
181
|
+
=begin rdoc
|
182
|
+
category: Logging
|
183
|
+
tags: log
|
184
|
+
=end
|
185
|
+
def info_to_log(message, lnbr = __LINE__)
|
186
|
+
log_message(INFO, message, nil, lnbr)
|
187
|
+
end
|
188
|
+
|
189
|
+
alias message_tolog info_to_log
|
190
|
+
alias message_to_log info_to_log
|
191
|
+
alias info_tolog info_to_log
|
192
|
+
|
193
|
+
=begin rdoc
|
194
|
+
category: Logging
|
195
|
+
tags: log, debug
|
196
|
+
=end
|
197
|
+
def debug_to_log(message, lnbr = __LINE__, dbg = false)
|
198
|
+
message << " \n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
199
|
+
log_message(DEBUG, "#{message}", nil, lnbr)
|
200
|
+
end
|
201
|
+
|
202
|
+
alias debug_tolog debug_to_log
|
203
|
+
|
204
|
+
=begin rdoc
|
205
|
+
category: Logging
|
206
|
+
tags: log, error
|
207
|
+
Do not use for failed validations.
|
208
|
+
=end
|
209
|
+
def error_to_log(message, lnbr = __LINE__)
|
210
|
+
log_message(ERROR, message, nil, lnbr)
|
211
|
+
end
|
212
|
+
|
213
|
+
alias error_tolog error_to_log
|
214
|
+
|
215
|
+
=begin rdoc
|
216
|
+
category: Logging
|
217
|
+
tags: log, error, pass, reference, tag, report
|
218
|
+
=end
|
219
|
+
def passed_to_log(message, lnbr = __LINE__, dbg = false)
|
220
|
+
message << " \n#{get_debug_list}" if dbg or @debug_calls # and not @debug_calls_fail_only)
|
221
|
+
@my_passed_count += 1 if @my_passed_count
|
222
|
+
parse_error_references(message)
|
223
|
+
log_message(INFO, "#{message}", PASS, lnbr)
|
224
|
+
end
|
225
|
+
|
226
|
+
alias validate_passed_tolog passed_to_log
|
227
|
+
alias validate_passed_to_log passed_to_log
|
228
|
+
alias passed_tolog passed_to_log
|
229
|
+
alias pass_tolog passed_to_log
|
230
|
+
alias pass_to_log passed_to_log
|
231
|
+
|
232
|
+
=begin rdoc
|
233
|
+
category: Logging
|
234
|
+
tags: log, error, fail, reference, tag, report
|
235
|
+
=end
|
236
|
+
def failed_to_log(message, lnbr = __LINE__, dbg = false)
|
237
|
+
message << " \n#{get_debug_list}" # if dbg or @debug_calls or @debug_calls_fail_only
|
238
|
+
@my_failed_count += 1 if @my_failed_count
|
239
|
+
parse_error_references(message, true)
|
240
|
+
log_message(WARN, "#{message}" + " (#{lnbr})]", FAIL, lnbr)
|
241
|
+
#debugger if debug_on_fail
|
242
|
+
end
|
243
|
+
|
244
|
+
alias validate_failed_tolog failed_to_log
|
245
|
+
alias validate_failed_to_log failed_to_log
|
246
|
+
alias failed_tolog failed_to_log
|
247
|
+
alias fail_tolog failed_to_log
|
248
|
+
alias fail_to_log failed_to_log
|
249
|
+
|
250
|
+
=begin rdoc
|
251
|
+
category: Logging
|
252
|
+
tags: log, error, fail, reference, tag, fatal, report
|
253
|
+
=end
|
254
|
+
def fatal_to_log(message, lnbr = __LINE__, dbg = false)
|
255
|
+
message << " \n#{get_debug_list}" # if dbg or (@debug_calls and not @debug_calls_fail_only)
|
256
|
+
@my_failed_count += 1 if @my_failed_count
|
257
|
+
parse_error_references(message, true)
|
258
|
+
debug_to_report("#{__method__}:\n#{dump_caller(lnbr)}")
|
259
|
+
log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr)
|
260
|
+
end
|
261
|
+
|
262
|
+
#def fatal_to_log(message, lnbr = __LINE__)
|
263
|
+
# log_message(FATAL, "#{message} (#{lnbr})", FAIL, lnbr)
|
264
|
+
# log_message(DEBUG, "\n#{dump_caller(lnbr)}")
|
265
|
+
#end
|
266
|
+
|
267
|
+
alias fatal_tolog fatal_to_log
|
268
|
+
|
269
|
+
=begin rdoc
|
270
|
+
category: Logging
|
271
|
+
tags: log, report
|
272
|
+
=end
|
273
|
+
def message_to_report(message, dbg = false)
|
274
|
+
mark_testlevel("#{message}", 0, '', dbg)
|
275
|
+
end
|
276
|
+
|
277
|
+
=begin rdoc
|
278
|
+
category: Logging
|
279
|
+
tags: log, debug, report
|
280
|
+
=end
|
281
|
+
def debug_to_report(message, dbg = false)
|
282
|
+
mark_testlevel("(DEBUG): \n", 0, "#{message}", dbg)
|
283
|
+
end
|
284
|
+
|
285
|
+
def translate_severity(severity)
|
286
|
+
mySev = ''
|
287
|
+
case
|
288
|
+
when severity == 0
|
289
|
+
mySev = 'DEBUG'
|
290
|
+
when severity == 1
|
291
|
+
mySev = 'INFO'
|
292
|
+
when severity == 2
|
293
|
+
mySev = 'WARN'
|
294
|
+
when severity == 3
|
295
|
+
mySev = 'ERROR'
|
296
|
+
when severity == 4
|
297
|
+
mySev = 'FATAL'
|
298
|
+
when severity > 4
|
299
|
+
mySev = 'UNKNOWN'
|
300
|
+
end
|
301
|
+
mySev
|
302
|
+
end
|
303
|
+
|
304
|
+
=begin rdoc
|
305
|
+
category: Debug
|
306
|
+
tags: log, caller, trace, report
|
307
|
+
=end
|
308
|
+
def get_caller(lnbr=nil, exception=nil)
|
309
|
+
script_name ||= File.basename(script_file)
|
310
|
+
if lnbr && script_type.eql?("Selenium")
|
311
|
+
[script_name, lnbr, 'in run()'].join(":")
|
312
|
+
elsif lnbr && script_type.eql?("MobileNativeApp")
|
313
|
+
[script_name, lnbr, 'in scenario()'].join(":")
|
314
|
+
else
|
315
|
+
caller_object = exception ? exception.backtrace : Kernel.caller
|
316
|
+
call_frame = caller_object.detect do |frame|
|
317
|
+
frame.match(/#{script_name}/) or (library && frame.match(/#{library}/))
|
318
|
+
end
|
319
|
+
unless call_frame.nil?
|
320
|
+
call_frame.gsub!(/^C:/, '')
|
321
|
+
file, line, method = call_frame.split(":")
|
322
|
+
[File.basename(file), line, method].join(":")
|
323
|
+
else
|
324
|
+
'unknown'
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
def init_logger(logFile, scriptName = nil)
|
330
|
+
if File.exist?(logFile)
|
331
|
+
puts "==> Logfile already exists: #{logFile}. Replacing it."
|
332
|
+
begin
|
333
|
+
File.delete(logFile)
|
334
|
+
rescue
|
335
|
+
puts "#{scriptName}: init_logger RESCUE: #{$!}"
|
336
|
+
end
|
337
|
+
end
|
338
|
+
logger = ActiveSupport::BufferedLogger.new(logFile)
|
339
|
+
logger.level = Logger::DEBUG
|
340
|
+
logger.auto_flushing = (true)
|
341
|
+
logger.add(INFO, "#{logFile}\n#{ENV["OS"]}")
|
342
|
+
logger
|
343
|
+
end
|
344
|
+
|
345
|
+
#private init_logger
|
346
|
+
|
347
|
+
=begin rdoc
|
348
|
+
category: Logging
|
349
|
+
tags: error, fail, reference, tag
|
350
|
+
=end
|
351
|
+
def start_run(ts = nil)
|
352
|
+
@start_timestamp = Time.now unless ts
|
353
|
+
utc_ts = @start_timestamp.getutc
|
354
|
+
loc_tm = "#{@start_timestamp.strftime("%H:%M:%S")} #{@start_timestamp.zone}"
|
355
|
+
mark_testlevel(">> Starting #{@myName.titleize} #{utc_ts} (#{loc_tm})", 9)
|
356
|
+
end
|
357
|
+
|
358
|
+
alias start_to_log start_run
|
359
|
+
|
360
|
+
=begin rdoc
|
361
|
+
category: Logging
|
362
|
+
tags: log, begin, error, reference, validation, pass, fail, tallies, tag
|
363
|
+
=end
|
364
|
+
def finish_run(ts = nil)
|
365
|
+
timestamp = Time.now unless ts
|
366
|
+
|
367
|
+
mark_testlevel(">> #{@myName.titleize} duration: #{sec2hms(timestamp - @start_timestamp)}", 0)
|
368
|
+
|
369
|
+
mark_testlevel(">> #{@myName.titleize} validations: #{@my_passed_count + @my_failed_count} "+
|
370
|
+
"fail: #{@my_failed_count}]", 0) if @my_passed_count and @my_failed_count
|
371
|
+
|
372
|
+
tally_error_references
|
373
|
+
|
374
|
+
utc_ts = timestamp.getutc
|
375
|
+
loc_tm = "#{timestamp.strftime("%H:%M:%S")} #{timestamp.zone}"
|
376
|
+
mark_testlevel(">> End #{@myName.titleize} #{utc_ts} (#{loc_tm})", 9)
|
377
|
+
|
378
|
+
end
|
379
|
+
|
380
|
+
alias finish_to_log finish_run
|
381
|
+
|
382
|
+
=begin rdoc
|
383
|
+
category: Logging
|
384
|
+
tags: log, error, reference, tag, tallies
|
385
|
+
=end
|
386
|
+
def tally_error_references(list_tags = @report_all_refs)
|
387
|
+
tags_tested = 0
|
388
|
+
tags_hit = 0
|
389
|
+
if @my_error_hits and @my_error_hits.length > 0
|
390
|
+
mark_testlevel("Tagged Error Hits:", 0)
|
391
|
+
tags_hit = @my_error_hits.length
|
392
|
+
@my_error_hits.each_key do |ref|
|
393
|
+
mark_testlevel("#{ref} - #{@my_error_hits[ref]}", 0)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
if list_tags
|
397
|
+
if @my_error_references and @my_error_references.length > 0
|
398
|
+
mark_testlevel("Error and Test Case Tags:", 0)
|
399
|
+
tags_tested = @my_error_references.length
|
400
|
+
@my_error_references.each_key do |ref|
|
401
|
+
mark_testlevel("#{ref} - #{@my_error_references[ref]}", 0)
|
402
|
+
end
|
403
|
+
mark_testlevel("Fails were hit on #{tags_hit} of #{tags_tested} error/test case references", 0)
|
404
|
+
else
|
405
|
+
mark_testlevel("No Error or Test Case References found.", 0)
|
406
|
+
end
|
407
|
+
end
|
408
|
+
end
|
409
|
+
|
410
|
+
=begin rdoc
|
411
|
+
category: Logging
|
412
|
+
tags: error, reference, tag, tallies
|
413
|
+
=end
|
414
|
+
def parse_error_references(message, fail = false)
|
415
|
+
msg = message.dup
|
416
|
+
while msg =~ /(\*\*\*\s+[\w\d_\s,-:;\?]+\s+\*\*\*)/
|
417
|
+
capture_error_reference($1, fail)
|
418
|
+
msg.sub!($1, '')
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
=begin rdoc
|
423
|
+
category: Logging
|
424
|
+
tags: error, fail, hits, reference, tag, tallies
|
425
|
+
=end
|
426
|
+
def capture_error_reference(ref, fail)
|
427
|
+
if fail
|
428
|
+
@my_error_hits = Hash.new unless @my_error_hits
|
429
|
+
if @my_error_hits[ref]
|
430
|
+
@my_error_hits[ref] += 1
|
431
|
+
else
|
432
|
+
@my_error_hits[ref] = 1
|
433
|
+
end
|
434
|
+
#debug_to_report("#{__method__}: error hits:\n#{@my_error_hits.to_yaml}")
|
435
|
+
end
|
436
|
+
@my_error_references = Hash.new unless @my_error_references
|
437
|
+
if @my_error_references[ref]
|
438
|
+
@my_error_references[ref] += 1
|
439
|
+
else
|
440
|
+
@my_error_references[ref] = 1
|
441
|
+
end
|
442
|
+
end
|
443
|
+
|
444
|
+
end
|
@@ -0,0 +1,264 @@
|
|
1
|
+
require 'regression/legacy'
|
2
|
+
require 'regression/logging'
|
3
|
+
require 'regression/validations'
|
4
|
+
|
5
|
+
#require 'rbconfig'
|
6
|
+
require 'ostruct'
|
7
|
+
require 'active_support'
|
8
|
+
require 'active_support/inflector'
|
9
|
+
|
10
|
+
module Awetestlib
|
11
|
+
|
12
|
+
class Runner
|
13
|
+
|
14
|
+
# order matters here
|
15
|
+
include Logging
|
16
|
+
include Legacy
|
17
|
+
include Validations
|
18
|
+
|
19
|
+
::DEBUG = 0
|
20
|
+
::INFO = 1
|
21
|
+
::WARN = 2
|
22
|
+
::ERROR = 3
|
23
|
+
::FATAL = 4
|
24
|
+
::UNKNOWN = 5
|
25
|
+
|
26
|
+
::TOP_LEVEL = 7
|
27
|
+
::SECOND_LEVEL = ::TOP_LEVEL - 1
|
28
|
+
|
29
|
+
::WAIT = 20
|
30
|
+
::PASS = '-PASS'
|
31
|
+
::FAIL = '-FAIL'
|
32
|
+
|
33
|
+
puts ENV["OS"]
|
34
|
+
|
35
|
+
attr_accessor :browser, :browser_abbrev, :version, :env,
|
36
|
+
:library, :script_type, :script_file,
|
37
|
+
:log_properties, :log_queue, :log_class,
|
38
|
+
:notify_queue, :notify_class, :notify_id,
|
39
|
+
:screencap_path, :xls_path, :script_path, :user_token, :root_path,
|
40
|
+
:debug_on_fail,
|
41
|
+
:environment, :environment_name, :environment_url, :environment_nodename,
|
42
|
+
:cycle, :browser_sequence,
|
43
|
+
:output_to_log, :log_path_subdir, :report_all_test_refs,
|
44
|
+
:timeout
|
45
|
+
|
46
|
+
#def self.build(options)
|
47
|
+
# #build_class = "Awetestlib::#{script_module_for options[:script_type]}::Runner".constantize
|
48
|
+
# build_class = "Awetestlib::Runner".constantize
|
49
|
+
# #options = options.merge(:script_file => options[:script_file])
|
50
|
+
# #if build_class.respond_to?(:runner_class)
|
51
|
+
# # build_class.runner_class(options)
|
52
|
+
# #else
|
53
|
+
# build_class.new(options)
|
54
|
+
# #end
|
55
|
+
#end
|
56
|
+
|
57
|
+
# TODO: Encapsulate in some kind of config
|
58
|
+
###################################
|
59
|
+
def setup_global_test_vars(options)
|
60
|
+
@my_failed_count = 0
|
61
|
+
@my_passed_count = 0
|
62
|
+
@my_error_references = Hash.new
|
63
|
+
@my_error_hits = Hash.new
|
64
|
+
|
65
|
+
@report_all_refs = options[:report_all_test_refs]
|
66
|
+
|
67
|
+
if options[:environment]
|
68
|
+
@myAppEnv = OpenStruct.new(
|
69
|
+
:name => options[:environment]['name'],
|
70
|
+
:url => options[:environment]['url'],
|
71
|
+
:nodename => options[:environment]['nodename']
|
72
|
+
)
|
73
|
+
@runenv = options[:environment]['nodename'] || options[:environment]['name']
|
74
|
+
@myURL = options[:environment]['url']
|
75
|
+
else
|
76
|
+
@runenv = options[:environment_name]
|
77
|
+
end
|
78
|
+
|
79
|
+
@targetBrowser = browser_to_use(options[:browser], options[:version])
|
80
|
+
@targetVersion = @targetBrowser.version
|
81
|
+
@browserAbbrev = @targetBrowser.abbrev
|
82
|
+
@myRoot = USING_WINDOWS ? options[:root_path].gsub!('/', '\\') : options[:root_path]
|
83
|
+
@myName = File.basename(options[:script_file]).sub(/\.rb$/, '')
|
84
|
+
|
85
|
+
if options[:output_to_log]
|
86
|
+
log_path = "#{@myRoot}/"
|
87
|
+
log_path << "#{options[:log_path_subdir]}/" if options[:log_path_subdir]
|
88
|
+
log_spec = File.join log_path, "#{@myName}_#{Time.now.strftime("%Y%m%d%H%M%S")}.log"
|
89
|
+
@myLog = init_logger(log_spec, @myName)
|
90
|
+
#@start_timestamp = Time.now
|
91
|
+
#start_to_log(@start_timestamp)
|
92
|
+
end
|
93
|
+
|
94
|
+
if options[:xls_path]
|
95
|
+
@xls_path = options[:xls_path]
|
96
|
+
end
|
97
|
+
|
98
|
+
#TODO need to find way to calculate these on the fly
|
99
|
+
# window top border 30
|
100
|
+
# IE toolbars 86
|
101
|
+
@vertical_hack_ie = 117
|
102
|
+
# FF toolbars 114
|
103
|
+
@vertical_hack_ff = 144
|
104
|
+
# window left border 4
|
105
|
+
@horizontal_hack_ie = 5
|
106
|
+
@horizontal_hack_ff = 4
|
107
|
+
#
|
108
|
+
# @x_tolerance = 12
|
109
|
+
# @y_tolerance = 12
|
110
|
+
require_gems
|
111
|
+
end
|
112
|
+
|
113
|
+
#def self.runner_class(options)
|
114
|
+
# script_file = options[:script_file]
|
115
|
+
# load script_file # force a load
|
116
|
+
#
|
117
|
+
# runner_module = self.module_for script_file
|
118
|
+
# klass_name = "#{runner_module.to_s}::Runner"
|
119
|
+
#
|
120
|
+
# # Define a Runner class in the test script's module inheriting from AwetestLegacy::Runner
|
121
|
+
# runner_module.module_eval do
|
122
|
+
# eval <<-RUBY
|
123
|
+
# class #{klass_name} < Awetestlib::Runner
|
124
|
+
# def initialize(options)
|
125
|
+
# #super(options)
|
126
|
+
# setup_global_test_vars(options)
|
127
|
+
# end
|
128
|
+
# end
|
129
|
+
# RUBY
|
130
|
+
# end
|
131
|
+
#
|
132
|
+
# runner = runner_module::Runner.new(options)
|
133
|
+
#
|
134
|
+
# if options[:library]
|
135
|
+
# lib_file = options[:library]
|
136
|
+
# load lib_file
|
137
|
+
# lib_module = self.module_for lib_file
|
138
|
+
# runner.extend(lib_module)
|
139
|
+
# end
|
140
|
+
#
|
141
|
+
# # Add in the methods defined in the script's module
|
142
|
+
# runner.extend(runner_module)
|
143
|
+
# runner
|
144
|
+
#end
|
145
|
+
|
146
|
+
def initialize(options)
|
147
|
+
options.each_pair do |k, v|
|
148
|
+
self.send("#{k}=", v)
|
149
|
+
end
|
150
|
+
setup_global_test_vars(options)
|
151
|
+
|
152
|
+
# load and extend with library module if it exists
|
153
|
+
if options[:library]
|
154
|
+
lib_file = File.join @myRoot, options[:library]
|
155
|
+
load lib_file # force a fresh load
|
156
|
+
lib_module = module_for lib_file
|
157
|
+
self.extend(lib_module)
|
158
|
+
end
|
159
|
+
|
160
|
+
# load and extend with script
|
161
|
+
script_file = File.join @myRoot, options[:script_file]
|
162
|
+
load script_file # force a fresh load
|
163
|
+
runner_module = module_for script_file
|
164
|
+
self.extend(runner_module)
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
def browser_to_use(browser, browser_version = nil)
|
169
|
+
platform = ''
|
170
|
+
platform = 'Windows' if !!((RUBY_PLATFORM =~ /(win|w)(32|64)$/) || (RUBY_PLATFORM =~ /mswin|mingw/))
|
171
|
+
platform = 'OSX' if RUBY_PLATFORM =~ /darwin/
|
172
|
+
|
173
|
+
browser_abbrev =
|
174
|
+
Awetestlib::BROWSER_ALTERNATES[platform][browser] ?
|
175
|
+
Awetestlib::BROWSER_ALTERNATES[platform][browser] : browser
|
176
|
+
if not browser_version
|
177
|
+
case browser_abbrev
|
178
|
+
when 'IE'
|
179
|
+
browser_version = 8
|
180
|
+
when 'FF'
|
181
|
+
browser_version = 11
|
182
|
+
when 'C', 'GC'
|
183
|
+
browser_version = 10
|
184
|
+
when 'S'
|
185
|
+
browser_version = 10
|
186
|
+
end
|
187
|
+
end
|
188
|
+
return OpenStruct.new(
|
189
|
+
:name => (Awetestlib::BROWSER_MAP[browser_abbrev]),
|
190
|
+
:abbrev => browser_abbrev,
|
191
|
+
:version => browser_version
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
def require_gems
|
196
|
+
|
197
|
+
case @targetBrowser.abbrev
|
198
|
+
|
199
|
+
when 'IE'
|
200
|
+
if version.to_f >= 9.0
|
201
|
+
require 'watir-webdriver'
|
202
|
+
else
|
203
|
+
require 'watir/ie'
|
204
|
+
require 'watir'
|
205
|
+
require 'watir/process'
|
206
|
+
require 'watirloo'
|
207
|
+
require 'patches/watir'
|
208
|
+
Watir::IE.visible = true
|
209
|
+
end
|
210
|
+
when 'FF'
|
211
|
+
if @targetBrowser.version.to_f < 4.0
|
212
|
+
require 'firewatir'
|
213
|
+
require 'patches/firewatir'
|
214
|
+
else
|
215
|
+
require 'watir-webdriver'
|
216
|
+
end
|
217
|
+
|
218
|
+
when 'S'
|
219
|
+
require 'safariwatir'
|
220
|
+
|
221
|
+
when 'C', 'GC'
|
222
|
+
require 'watir-webdriver'
|
223
|
+
|
224
|
+
# when 'CL'
|
225
|
+
# require 'celerity'
|
226
|
+
# require 'watir-webdriver'
|
227
|
+
|
228
|
+
end
|
229
|
+
|
230
|
+
if USING_WINDOWS
|
231
|
+
require 'watir/win32ole'
|
232
|
+
@ai = ::WIN32OLE.new('AutoItX3.Control')
|
233
|
+
require 'pry'
|
234
|
+
else
|
235
|
+
# TODO: Need alternative for Mac?
|
236
|
+
@ai = ''
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
def module_for(script_file)
|
242
|
+
File.read(script_file).match(/^module\s+(\w+)/)[1].constantize
|
243
|
+
end
|
244
|
+
|
245
|
+
def before_run
|
246
|
+
start_run
|
247
|
+
end
|
248
|
+
|
249
|
+
def start
|
250
|
+
before_run
|
251
|
+
run
|
252
|
+
rescue Exception => e
|
253
|
+
failed_to_log(e.to_s)
|
254
|
+
ensure
|
255
|
+
after_run
|
256
|
+
end
|
257
|
+
|
258
|
+
def after_run
|
259
|
+
finish_run
|
260
|
+
@myLog.close if @myLog
|
261
|
+
end
|
262
|
+
|
263
|
+
end
|
264
|
+
end
|