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


    测试报告:

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

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

    image

    image

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

    #测试报告标题
    $testReportTitle = "CrowdSysAutoTestResults(#{Time.now.strftime("%m%d%H%M")})"
    #测试报告目录
    $testReportDir = 'C:AutoTest ails estReportappviews eports'

    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的:appviews eports

    然后所有人就可以通过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=~/usernames*=/
        @passwd = line.sub(/.+s*=s*/,'').chomp if line=~/passwds*=/
        @smtpaddress = line.sub(/.+s*=s*/,'').chomp if line=~/smtpaddresss*=/
        @port = line.sub(/.+s*=s*/,'').chomp if line=~/ports*=/
        @domain = line.sub(/.+s*=s*/,'').chomp if line=~/domains*=/
        $from = line.sub(/.+s*=s*/,'').chomp if line=~/froms*=/
        $to = line.sub(/.+s*=s*/,'').chomp if line=~/tos*=/
        }
    
    
    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 "
    
    Automation test #{$finishTime}.
    
    
    
    #{$testCaseNum},#{$assertionsNum},#{$failuresNum},#{$errorsNum},#{$skipsNum}
    
    
    
    Detail reports: http://172.17.2.44:9527/reports/index
    
    
    
    System under test: #{$crowdSysURL}"
    end
    mail.deliver!

    邮件效果图:

  • 相关阅读:
    【物联网】传感器+wifi传输+回复+显示
    【物联网】esp8266+LCD
    【物联网】esp8266
    windows渗透被人忽视的一些小命令
    一段刻骨铭心的爱
    网站安全狗最新版绕过测试
    Coremail邮件系统存储型XSS两个
    ......
    一个钓鱼站爆裤小记
    ASPX版菜刀一句话,留后门专用
  • 原文地址:https://www.cnblogs.com/fithon/p/6689495.html
Copyright © 2020-2023  润新知