web自动化测试:watir+minitest(五)

测试报告:

加载minitest-reporters库,并设置相关的参数。既可以在每次运行测试后生成响应的测试报告。

默认会生成一份html的报告在当前目录的test目录下

image

 

image

 

我们可以指定参数对报告的标题、报告存放目录、html的文件名进行设置。

 

#测试报告标题
$testReportTitle = "CrowdSysAutoTestResults(#{Time.now.strftime("%m%d%H%M")})"
#测试报告目录
$testReportDir = 'C:\AutoTest\rails\testReport\app\views\reports'

 

Minitest::Reporters.use! [Minitest::Reporters::HtmlReporter.new(:title => $testReportTitle,:reports_dir => $testReportDir,:output_filename => 'index_new.html')]

 

  • 搭建web服务器提供报告给公司所有人访问

既然是使用ruby做的自动化,我们搭建一个简单的rails即可。搭建过程略。请参考(http://guides.ruby-china.org/getting_started.html

rails搭建正常运行起来后。

我们将测试报告的生成目录设置为rails的:\app\views\reports

然后所有人就可以通过rails的服务端口来访问测试报告了

image

 

 

  • 邮件推送 

测试完成后,自动发送邮件将测试结果推送给相关人。相关代码片段:

############## 开始发送邮件 #########
##获取执行结果数据
File.readlines($testReportDir+'\index.html').each{ |line|    
    $testCaseNum = line.force_encoding('utf-8').scan(/\d+\s*tests/) if line.force_encoding('utf-8')=~/span class=".*">\d+\s*tests/
    $assertionsNum = line.force_encoding('utf-8').scan(/\d+\s*assertions/) if line.force_encoding('utf-8')=~/span class=".*">\s*\d+\sassertions/
    $failuresNum = line.force_encoding('utf-8').scan(/\d+\s*failures/) if line.force_encoding('utf-8')=~/span class=".*">\s*\d+\s*failures/
    $errorsNum = line.force_encoding('utf-8').scan(/\d+\s*errors/) if line.force_encoding('utf-8')=~/span class=".*">\s*\d+\s*errors/
    $skipsNum = line.force_encoding('utf-8').scan(/\d+\s*skips/) if line.force_encoding('utf-8')=~/span class=".*">\s*\d+\s*skips/
    $finishTime = line.force_encoding('utf-8').scan(/finished in .+?s/).to_s.sub('["','').sub('"]','') if line.force_encoding('utf-8')=~/finished in/
    }
    
$pwd = Pathname.new(__FILE__).realpath.dirname
File.readlines("#{$pwd}/startTest.ini").each{ |line|
    @username = line.sub(/.+\s*=\s*/,'').chomp if line=~/username\s*=/
    @passwd = line.sub(/.+\s*=\s*/,'').chomp if line=~/passwd\s*=/
    @smtpaddress = line.sub(/.+\s*=\s*/,'').chomp if line=~/smtpaddress\s*=/
    @port = line.sub(/.+\s*=\s*/,'').chomp if line=~/port\s*=/
    @domain = line.sub(/.+\s*=\s*/,'').chomp if line=~/domain\s*=/
    $from = line.sub(/.+\s*=\s*/,'').chomp if line=~/from\s*=/
    $to = line.sub(/.+\s*=\s*/,'').chomp if line=~/to\s*=/
    }


smtp = { :address => @smtpaddress, :port => @port, :domain => @domain, :user_name => @username, :password => @passwd, :enable_starttls_auto => true, :openssl_verify_mode => 'none' }
Mail.defaults { delivery_method :smtp, smtp }
mail = Mail.new do
  from $from
  to $to
  subject "【#{$crowdSysVersionNum}】Crowd System AutomationTest Reports #{curr_time}."
  body "\n\nAutomation test #{$finishTime}.\n\n\n\n#{$testCaseNum},#{$assertionsNum},#{$failuresNum},#{$errorsNum},#{$skipsNum}\n\n\n\nDetail reports: http://172.17.2.44:9527/reports/index\n\n\n\nSystem under test: #{$crowdSysURL}"
end
mail.deliver!

邮件效果图:

 

posted @ 2017-04-10 16:04  Fithon  阅读(425)  评论(0编辑  收藏  举报