Class: Report

Inherits:
Object
  • Object
show all
Defined in:
lib/common/atp_report.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.actual(title, value, filetype = nil) ⇒ Object

指定实际输出



243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
# File 'lib/common/atp_report.rb', line 243

def self.actual(title,value,filetype=nil)
  if ENV['AT_IN_STEP']!="1"
    self.stepBegin()
  end
  value = value.to_s
  #Tclerk.trace "Report Actual [#{title}], value=[#{value}] and filetype is [#{filetype}]"
	  title = "No Title" if title.length == 0
  title = CGI::escapeHTML(title)
  if filetype.nil?
    _append("<a title=\"#{title}\" type=\"text/plain\">\n#{Base64.encode64(value)}</a>\n")
  else
    # 测试文件存在与否
		if File.file? value
content = IO.read(value)
_append("<a title=\"#{title}\" type=\"#{filetype}\">\n#{Base64.encode64(content)}</a>\n")
		else
print "Error: Actual file not exists!\n"
		end
  end
end

.assertReturn(title, erc = 0, act = nil) ⇒ Object

判断返回值



271
272
273
274
275
276
277
278
279
# File 'lib/common/atp_report.rb', line 271

def self.assertReturn(title,erc=0,act=nil)
  act ||= $?.to_s
  act = act.to_s
  erc = erc.to_s
  stepBegin(title)
  expect("返回值",erc)
  actual("返回值",act)
  stepEnd
end

.assertTrue(title, cond) ⇒ Object



263
264
265
266
267
268
# File 'lib/common/atp_report.rb', line 263

def self.assertTrue(title,cond)
  stepBegin(title)
  expect(title,true.to_s)
  actual(title,cond.to_s)
  stepEnd
end

.caseBegin(title = "No Title", id = "") ⇒ Object

进入Case



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/common/atp_report.rb', line 161

def self.caseBegin(title="No Title", id="")
  if ENV['AT_IN_CASE']=="1"
    self.caseEnd
  end
 
  if ENV['AT_IN_SUITE']==nil
      if self.suiteBegin(title) == 1
	return 1
end
  end
    
	  title = "No Title" if title.length == 0
  title = CGI::escapeHTML(title)
	  if id.length > 0
 _append("<case title=\"#{title}\" id=\"#{id}\">\n<s>#{Time.now.to_i}</s>\n")
	  else
 _append("<case title=\"#{title}\">\n<s>#{Time.now.to_i}</s>\n")
	  end
  ENV['AT_IN_CASE']="1"
end

.caseEndObject

结束Case



183
184
185
186
187
188
189
190
191
192
# File 'lib/common/atp_report.rb', line 183

def self.caseEnd
  if ENV['AT_IN_CASE']=="1"
    if ENV['AT_IN_STEP']=="1"
        self.stepEnd
    end

    _append("<f>#{Time.now.to_i}</f>\n</case>\n")
    ENV['AT_IN_CASE']= nil
  end
end

.closeObject

关闭报告



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
# File 'lib/common/atp_report.rb', line 65

def self.close
	  # 恢复成打开报告前的状态
	  suite_level = 0
	  case_level = 0
	  step_level = 0

	  step_level = ENV['AT_IN_STEP'].to_i if ENV['AT_IN_STEP'] != nil
	  if $at_in_step < step_level
self.stepEnd
	  elsif $at_in_step > step_level
 self.stepBegin
	  end

	  case_level = ENV['AT_IN_CASE'].to_i if ENV['AT_IN_CASE'] != nil
	  if $at_in_case < case_level
self.caseEnd
	  elsif $at_in_case > case_level
 self.caseBegin
	  end
	  
	  suite_level = ENV['AT_IN_SUITE'].to_i if ENV['AT_IN_SUITE'] != nil
	  while $at_in_suite < suite_level
self.suiteEnd
		suite_level -= 1
	  end
	  while $at_in_suite > suite_level
 self.suiteBegin
		suite_level += 1
	  end

  #若尚未关闭报告
  if ENV['AT_IN_REPORT']=="1" and $at_in_report == 0
    _append("<f>#{Time.now.to_i}</f>\n</report>\n")
    ENV['AT_IN_REPORT'] = nil
		ENV['AT_LOGFILE'] = nil	if $logfile_is_existed == 0
  end
end

.expect(title, value, filetype = nil) ⇒ Object

指定预期输出



221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/common/atp_report.rb', line 221

def self.expect(title,value,filetype=nil)
  if ENV['AT_IN_STEP']!="1"
    self.stepBegin()
  end
  value = value.to_s
  #Tclerk.trace "Report Expect [#{title}], value=[#{value}] and filetype is [#{filetype}]"
	  title = "No Title" if title.length == 0
  title = CGI::escapeHTML(title)
  if filetype.nil?
    _append("<e title=\"#{title}\" type=\"text/plain\">\n#{Base64.encode64(value)}</e>\n")
  else
    # 测试文件存在与否
		if File.file? value
content = IO.read(value)
_append("<e title=\"#{title}\" type=\"#{filetype}\">\n#{Base64.encode64(content)}</e>\n")
		else
print "Error: Expect file not exists!\n"
		end
  end
end

.more(title, value, filetype = nil) ⇒ Object

其他附件信息



282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/common/atp_report.rb', line 282

def self.more(title,value,filetype=nil)
  if ENV['AT_IN_REPORT']== nil
      self.open()
  end
  value = value.to_s
  #Tclerk.trace "{report} More [#{title}], value=[#{value}] and filetype is [#{filetype}]"
	  title = "No Title" if title.length == 0
  title = CGI::escapeHTML(title)
  if filetype.nil?
    _append("<more title=\"#{title}\" type=\"text/plain\">\n#{Base64.encode64(value)}</more>\n")
  else
    # 测试文件存在与否
		if File.file? value
content = IO.read(value)
_append("<more title=\"#{title}\" type=\"#{filetype}\">\n#{Base64.encode64(content)}</more>\n")
		else
print "Error: More file not exists!\n"
		end
  end
end

.open(owner = nil, title = "No Title", filename = "report.xml", encoding = "gb2312") ⇒ Object

打开报告



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
# File 'lib/common/atp_report.rb', line 20

def self.open(owner=nil,title="No Title",filename="report.xml",encoding="gb2312")
  #若尚未打开报告
  if ENV['AT_IN_REPORT']!="1"
		$logfile_is_existed = 1
		if ENV['AT_LOGFILE'] == nil
			path = Pathname.new(filename)
			filename = "#{Dir.pwd}/#{filename}" if path.relative?
			FileUtils.mkpath(File.dirname(filename))
			ENV['AT_LOGFILE'] = filename
			$logfile_is_existed = 0
		end
    # 设置环境变量
		ENV['AT_IN_SUITE'] = nil
		ENV['AT_IN_CASE'] = nil
		ENV['AT_IN_STEP'] = nil
    ENV['AT_IN_REPORT']="1"
    
		if owner.nil? 
      if  ENV['OS'] =~ /windows/i
        owner = "#{ENV['USERNAME']}@#{ENV['COMPUTERNAME']}"
      else
        owner = "#{ENV['USER']}@#{ENV['HOSTNAME']}"
      end
    end 
    
		File.open(ENV['AT_LOGFILE'],'w') do |f|
      f.write <<-endblock
<?xml version="1.0" encoding="#{encoding}"?>
<report>
<schemaversion>2.0.0</schemaversion>
<owner>#{owner}</owner>
<title>#{CGI::escapeHTML(title)}</title>
<s>#{Time.now.to_i}</s>
    endblock
    end
  #若已经打开报告
	  else
		$at_in_report = 1
		$at_in_suite = ENV['AT_IN_SUITE'].to_i if ENV['AT_IN_SUITE'] != nil
		$at_in_case = ENV['AT_IN_CASE'].to_i if ENV['AT_IN_CASE'] != nil
		$at_in_step = ENV['AT_IN_STEP'].to_i if ENV['AT_IN_STEP'] != nil
  end
end

.re_openObject

add by hanyu



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/common/atp_report.rb', line 104

def self.re_open
	#去除末尾4行
	lines = nil
    File.open ENV['AT_LOGFILE'],"r" do |file|
		lines = file.readlines
		lines = lines[0,lines.size-2]
	end

	File.open ENV['AT_LOGFILE'],"w" do |file|
		file.puts lines
	end
	
	ENV['AT_IN_REPORT'] = "1"
	ENV['AT_IN_SUITE'] = "1"
end

.stepBegin(title = "No Title") ⇒ Object

进入Step



195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/common/atp_report.rb', line 195

def self.stepBegin(title="No Title")
  if ENV['AT_IN_STEP']=="1"
          self.stepEnd
  end 

  if ENV['AT_IN_CASE']==nil
      if self.caseBegin(title) == 1
	return 1
end
  end  

	  title = "No Title" if title.length == 0
  title = CGI::escapeHTML(title)
  _append("<step title=\"#{title}\">\n<s>#{Time.now.to_i}</s>\n")
  ENV['AT_IN_STEP']="1"
end

.stepEndObject

结束Step



213
214
215
216
217
218
# File 'lib/common/atp_report.rb', line 213

def self.stepEnd
  if ENV['AT_IN_STEP']=="1"
    _append("<f>#{Time.now.to_i}</f>\n</step>\n")
    ENV['AT_IN_STEP']=nil
  end
end

.suiteBegin(title = "No Title") ⇒ Object

进入Suite



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/common/atp_report.rb', line 121

def self.suiteBegin(title="No Title")
  if ENV['AT_IN_REPORT']== nil
      self.open()
  end
  if ENV['AT_IN_CASE']=="1"
      self.caseEnd
  end
	  title = "No Title" if title.length == 0

	  if title.include? "/"
if ! title.include? ":"
print "absolute suite syntax error: #{title}\n"
return 1
		end
	  end

  title = CGI::escapeHTML(title)
   _append("<suite title=\"#{title}\">\n<s>#{Time.now.to_i}</s>\n")
  t=ENV['AT_IN_SUITE'].to_i
  t+=1
  ENV['AT_IN_SUITE']=t.to_s
end

.suiteEndObject

结束Suite



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/common/atp_report.rb', line 145

def self.suiteEnd
	  t = ENV['AT_IN_SUITE'].to_i
  if t > 0
    if ENV['AT_IN_CASE']=="1"
      self.caseEnd
    end
    _append("<f>#{Time.now.to_i}</f>\n</suite>\n")
    if t > 1
      ENV['AT_IN_SUITE'] = (t - 1).to_s
		else
ENV['AT_IN_SUITE'] = nil
		end
  end
end

Instance Method Details

#actual(title = "No Title", value = "", filetype = nil) ⇒ Object



331
332
333
# File 'lib/common/atp_report.rb', line 331

def actual(title="No Title",value="",filetype=nil)
  Report.actual(title,value,filetype)
end

#assert_return(title, erc = 0, act = nil) ⇒ Object



325
326
327
# File 'lib/common/atp_report.rb', line 325

def assert_return(title,erc=0,act=nil)
  Report.assertReturn(title,erc,act)
end

#assert_true(title, cond) ⇒ Object



322
323
324
# File 'lib/common/atp_report.rb', line 322

def assert_true(title,cond)
  Report.assertTrue(title,cond)
end

#case_begin(title = "No Title") ⇒ Object



310
311
312
# File 'lib/common/atp_report.rb', line 310

def case_begin(title="No Title")
  Report.caseBegin(title)
end

#case_endObject



313
314
315
# File 'lib/common/atp_report.rb', line 313

def case_end
  Report.caseEnd
end

#expect(title = "No Title", value = "", filetype = nil) ⇒ Object



328
329
330
# File 'lib/common/atp_report.rb', line 328

def expect(title="No Title",value="",filetype=nil)
  Report.expect(title,value,filetype)
end

#more(title, value = "", filetype = nil) ⇒ Object



334
335
336
# File 'lib/common/atp_report.rb', line 334

def more(title,value="",filetype=nil)
  Report.more(title,value,filetype)
end

#step_begin(title = "No Title") ⇒ Object



316
317
318
# File 'lib/common/atp_report.rb', line 316

def step_begin(title="No Title")
  Report.stepBegin(title)
end

#step_endObject



319
320
321
# File 'lib/common/atp_report.rb', line 319

def step_end
  Report.stepEnd
end

#suite_begin(title = "No Title") ⇒ Object

为了兼容,定义一堆别名



304
305
306
# File 'lib/common/atp_report.rb', line 304

def suite_begin(title="No Title")
  Report.suiteEnd(title)
end

#suite_endObject



307
308
309
# File 'lib/common/atp_report.rb', line 307

def suite_end
  Report.suiteEnd
end