Class: Log
- Inherits:
-
Object
- Object
- Log
- Defined in:
- lib/testlogger.rb
Class Method Summary collapse
- .close_test_case ⇒ Object
- .close_test_script ⇒ Object
- .close_test_step ⇒ Object
- .close_utility ⇒ Object
- .configure(location = nil) ⇒ Object
- .createFileIfDoesnotExist ⇒ Object
- .error(details = 'NA', picture = 'NA') ⇒ Object
- .getCurrentNode ⇒ Object
- .getResultLocation ⇒ Object
- .message(details = 'NA', picture = 'NA') ⇒ Object
- .test_case(idValue = 'NA', nameValue = 'NA') ⇒ Object
- .test_script(scriptValue = 'NA') ⇒ Object
- .test_step(idValue = 'NA', nameValue = 'NA') ⇒ Object
- .utility(message = 'NA') ⇒ Object
- .warning(details = 'NA', picture = 'NA') ⇒ Object
Class Method Details
.close_test_case ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/testlogger.rb', line 118 def self.close_test_case() @nodeCursor = "log|test-script|test-case" f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) log['end_time'] = Time.now.iso8601(3) f2 = File.open(@logFileName,"w") rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = "log|test-script" end |
.close_test_script ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/testlogger.rb', line 76 def self.close_test_script() @nodeCursor = "log|test-script" f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) log['end_time'] = Time.now.iso8601(3) f2 = File.open(@logFileName,"w") rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = "log" end |
.close_test_step ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/testlogger.rb', line 158 def self.close_test_step() @nodeCursor = "log|test-script|test-case|test-step" f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) log['end_time'] = Time.now.iso8601(3) f2 = File.open(@logFileName,"w") rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = "log|test-script|test-case" end |
.close_utility ⇒ Object
286 287 288 289 290 291 |
# File 'lib/testlogger.rb', line 286 def self.close_utility() index = @nodeCursor.rindex('|utility') @nodeCursor = @nodeCursor.slice(0...index) end |
.configure(location = nil) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/testlogger.rb', line 15 def self.configure(location = nil) if location.nil? location = File.(File.dirname(__FILE__)+"/../conf.rb") require location configValues = getLogConfiguration() @logFileName = configValues[:resultFileLocation]+"/TestResults_"+(Time.new.strftime "%H_%M_%S")+".xml" puts "Loading results location from default 'config.rb'" Log.getResultLocation else require location configValues = getLogConfiguration() @logFileName = configValues[:resultFileLocation]+"/TestResults_"+(Time.new.strftime "%H_%M_%S")+".xml" puts "Updataed results location from '#{location}'" Log.getResultLocation end end |
.createFileIfDoesnotExist ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/testlogger.rb', line 32 def self.createFileIfDoesnotExist() unless File.exists?(@logFileName) FileUtils.mkdir_p(File.dirname(@logFileName)) f = File.new(@logFileName, "w") f.write("<log></log>") f.close end if File.zero?(@logFileName) f = File.new(@logFileName, "w") f.write("<log></log>") f.close end end |
.error(details = 'NA', picture = 'NA') ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/testlogger.rb', line 204 def self.error(details = 'NA',picture = 'NA') Log.createFileIfDoesnotExist f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) error = Nokogiri::XML::Node.new("error", doc) log.add_child(error) log = doc.at_xpath(Log.getCurrentNode+"/error[last()]") timeN = Nokogiri::XML::Node.new("time", doc) timeN.content=Time.now.iso8601(3) log.add_child(timeN) = Nokogiri::XML::Node.new("details", doc) .content=details log.add_child() = Nokogiri::XML::Node.new("additional_details", doc) .content=caller.inspect log.add_child() pictureLocation = Nokogiri::XML::Node.new("picture", doc) pictureLocation.content=picture log.add_child(pictureLocation) rescue Exception => e return false ensure #$global_return = false f2 = File.open(@logFileName,"w") f2.write(doc) f1.close() f2.close() end |
.getCurrentNode ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/testlogger.rb', line 46 def self.getCurrentNode cursor_local = '' @nodeCursor.split("|").each do |i| cursor_local = cursor_local+"/"+i+"[last()]" end return cursor_local end |
.getResultLocation ⇒ Object
11 12 13 |
# File 'lib/testlogger.rb', line 11 def self.getResultLocation() puts "Find results at: "+@logFileName end |
.message(details = 'NA', picture = 'NA') ⇒ Object
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/testlogger.rb', line 174 def self.(details= 'NA',picture = 'NA') Log.createFileIfDoesnotExist f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) = Nokogiri::XML::Node.new("message", doc) log.add_child() log = doc.at_xpath(Log.getCurrentNode+"/message[last()]") timeN = Nokogiri::XML::Node.new("time", doc) timeN.content=Time.now.iso8601(3) log.add_child(timeN) = Nokogiri::XML::Node.new("details", doc) .content=details log.add_child() pictureLocation = Nokogiri::XML::Node.new("picture", doc) pictureLocation.content=picture log.add_child(pictureLocation) f2 = File.open(@logFileName,"w") rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() end |
.test_case(idValue = 'NA', nameValue = 'NA') ⇒ 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 |
# File 'lib/testlogger.rb', line 92 def self.test_case(idValue = 'NA',nameValue = 'NA') Log.createFileIfDoesnotExist() if @nodeCursor.include? "test-case" @nodeCursor = 'log|test-script' end f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) testCaseNode = Nokogiri::XML::Node.new("test-case", doc) testCaseNode['id'] = (idValue) testCaseNode['name'] = (nameValue) testCaseNode['start_time'] = Time.now.iso8601(3) f2 = File.open(@logFileName,"w") log.add_child(testCaseNode) rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = @nodeCursor+"|test-case" end |
.test_script(scriptValue = 'NA') ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/testlogger.rb', line 54 def self.test_script(scriptValue = 'NA') Log.createFileIfDoesnotExist() if @nodeCursor.include? "test-script" @nodeCursor = 'log' end f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) test_scriptNode = Nokogiri::XML::Node.new("test-script", doc) test_scriptNode['name'] = (scriptValue) test_scriptNode['start_time'] = Time.now.iso8601(3) f2 = File.open(@logFileName,"w") log.add_child(test_scriptNode) rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = @nodeCursor+"|test-script" end |
.test_step(idValue = 'NA', nameValue = 'NA') ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/testlogger.rb', line 134 def self.test_step(idValue = 'NA',nameValue = 'NA') Log.createFileIfDoesnotExist() if @nodeCursor.include? "test-step" @nodeCursor = 'log|test-script|test-case' end f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) testStepNode = Nokogiri::XML::Node.new("test-step", doc) testStepNode['id'] = (idValue) testStepNode['name'] = (nameValue) testStepNode['start_time'] = Time.now.iso8601(3) f2 = File.open(@logFileName,"w") log.add_child(testStepNode) rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = @nodeCursor+"|test-step" end |
.utility(message = 'NA') ⇒ Object
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/testlogger.rb', line 267 def self.utility( = 'NA') Log.createFileIfDoesnotExist() f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) utilityNode = Nokogiri::XML::Node.new("utility", doc) utilityNode['name'] = () f2 = File.open(@logFileName,"w") log.add_child(utilityNode) rescue Exception => e Log.error e ensure f2.write(doc) f1.close() f2.close() @nodeCursor = @nodeCursor+"|utility" end |
.warning(details = 'NA', picture = 'NA') ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/testlogger.rb', line 238 def self.warning(details='NA',picture = 'NA') Log.createFileIfDoesnotExist f1 = File.open(@logFileName) doc = Nokogiri::XML(f1) log = doc.at_xpath(Log.getCurrentNode) warning = Nokogiri::XML::Node.new("warning", doc) log.add_child(warning) log = doc.at_xpath(Log.getCurrentNode+"/warning[last()]") timeN = Nokogiri::XML::Node.new("time", doc) timeN.content=Time.now.iso8601(3) log.add_child(timeN) = Nokogiri::XML::Node.new("details", doc) .content=details log.add_child() pictureLocation = Nokogiri::XML::Node.new("picture", doc) pictureLocation.content= picture log.add_child(pictureLocation) rescue Exception => e Log.error e ensure f2 = File.open(@logFileName,"w") f2.write(doc) f1.close() f2.close() end |