-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommonutils.rb
133 lines (122 loc) · 4.23 KB
/
commonutils.rb
1
2
3
4
5
6
7
8
9
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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
#---------------------------------------------------------
# excellent-watir -- An EXPERIMENTAL Watir Automation Framework
#---------------------------------------------------------
#if __FILE__ == $0
# TODO Generated stub
#end
class BaseCommands
#Collection of common commands
#Extended at runtime with domain-specific commands from other files
def start_new_script(params)
#TODO check file exists
#if not found, look in current working directory
#TODO if still not found, exit
if params.class.name == "Array"
path2file = Dir.pwd + "/" + params[0].to_s #get first param value
else
path2file = Dir.pwd + "/" + params.to_s #use all of it as the field name...
end
#Run the Script
#branch to a new ScriptRunner instance
if params.class.name == "Array"
scriptRunner = ScriptRunner.new(path2file, params)
#reformat array for nicer log output
p_delimited = ""
params.each do |p|
p_delimited = p_delimited + p + "; "
end
$log.debug("passing parameters via array [#{p_delimited}]")
else
scriptRunner = ScriptRunner.new(path2file,[params.to_s])
$log.debug("passing parameters from string #{params.to_s}")
end
scriptRunner.runScript
#(note, session is tidied up by scriptRunner so my work is done)
end
def comment(params)
$log.add(" ------------ ") #the comment is already logged by ScriptRunner, this text is just a separator for emphasis
end
def pause_message(params)
#Calls method in BaseCommands
message_box([params[0].to_s, "excellent-watir Paused", 0, 48])
end
def message_box(params)
txt=params[0]
title=params[1]
buttons=params[2]
icon=params[3]
user32 = DL.dlopen('user32')
msgbox = user32['MessageBoxA', 'ILSSI']
r = msgbox.call(0, txt, title, buttons+icon)
return r
#### button/icon constants
#~ BUTTONS_OK = 0 #~ BUTTONS_OKCANCEL = 1 #~ BUTTONS_ABORTRETRYIGNORE = 2 #~ BUTTONS_YESNO = 4
#~ ICON_HAND = 16 #~ ICON_QUESTION = 32 #~ ICON_EXCLAMATION = 48 #~ ICON_ASTERISK = 64
#### return code constants
#~ CLICKED_OK = 1 #~ CLICKED_CANCEL = 2 #~ CLICKED_ABORT = 3 #~ CLICKED_RETRY = 4
#~ CLICKED_IGNORE = 5 #~ CLICKED_YES = 6 #~ CLICKED_NO = 7
end
#def get_input(prompt='', title='')
# This little thing pops up an input box to get around the CAPTCHA
# Requires MS Excel to be installed as it calls an Excel object
# excel = WIN32OLE.new('Excel.Application')
# response = excel.InputBox(prompt, title)
# excel.Quit
# excel = nil
# return response
#end
#debug code...
def this_method
caller[0] =~ /`([^']*)'/ and $1
end
end
class LogResults
def initialize
logtime = Time.now.strftime "%Y%m%d.%H%M%S"
logfile = "log." + logtime + ".txt" #filename
fullpath = Dir.pwd + "/" + logfile #just put it in current directory for now.
#log = REXML.Document.new File.new(logpath) #log file is a new XML object
@log = File.new fullpath,"a"
#start counters
@error = 0
@fail = 0
@pass = 0
end
def add(logmsg)
#write Log logmsg to logfile + console
logEntry = "#{Time.now.strftime '%Y%m%d.%H%M%S'} #{logmsg}\n"
@log.write(logEntry)
puts logEntry
end
def error(logmsg)
#write Error logmsg to logfile + console
@error+=1
logEntry = "#{Time.now.strftime '%Y%m%d.%H%M%S'} ERROR: #{logmsg}"
@log.write(logEntry)
$stderr.puts logEntry
end
def fail(logmsg,expect="",actual="")
@fail+=1
if expect.to_s.length>0 or actual.to_s.length >0
logEntry = "FAILURE: #{logmsg}, expected: #{expect} found: #{actual}"
else
logEntry = "FAILURE: #{logmsg}"
end
self.add(logEntry)
end
def pass(logmsg)
@pass+=1
logEntry = "PASS: #{logmsg}"
self.add(logEntry)
end
def debug(logmsg)
if $debug
self.add("DEBUG: #{logmsg}")
end
end
def close
logEntry = "RESULTS: == Pass: #{@pass} Fail: #{@fail} Error: #{@error} ==\n"
self.add(logEntry)
@log.close
end
end