Test report:
Load the Minitest-reporters library and set the relevant parameters. You can generate a test report of the response after each run of the test.
A copy of the HTML report is generated by default in the test directory of the current directory
We can specify parameters to set the title of the report, the report directory, and the file name of the HTML.
#测试报告标题
$testReportTitle = "Crowdsysautotestresults (#{time.now.strftime ("%m%d%h%m ")})"
#测试报告目录
$testReportDir = ' C:\AutoTest\rails\testReport\app\views\reports '
' index_new.html ')]
- Build a Web server to provide reports to company owner Access
Now that we are automating with Ruby, we can build a simple rails. The construction process is slightly. Please refer to (http://guides.ruby-china.org/getting_started.html)
Rails builds up after normal operation.
We set the build directory for the test report to rails: \app\views\reports
Then everyone can access the test report via the Rails service port.
When the test is complete, auto-send mail will push the test results to the person concerned. Related Code snippet:
############## start sending mail ###########获取执行结果数据File.readlines ($testReportDir +'\index.html'). each{|line|$testCaseNum= Line.force_encoding ('Utf-8'). Scan (/\d+\s*tests/)ifLine.force_encoding ('Utf-8') =~/spanclass=".*">\d+\s*tests/$assertionsNum= Line.force_encoding ('Utf-8'). Scan (/\d+\s*assertions/)ifLine.force_encoding ('Utf-8') =~/spanclass=".*">\s*\d+\sassertions/$failuresNum= Line.force_encoding ('Utf-8'). Scan (/\d+\s*failures/)ifLine.force_encoding ('Utf-8') =~/spanclass=".*">\s*\d+\s*failures/$errorsNum= Line.force_encoding ('Utf-8'). Scan (/\d+\s*errors/)ifLine.force_encoding ('Utf-8') =~/spanclass=".*">\s*\d+\s*errors/$skipsNum= Line.force_encoding ('Utf-8'). Scan (/\d+\s*skips/)ifLine.force_encoding ('Utf-8') =~/spanclass=".*">\s*\d+\s*skips/$finishTime= Line.force_encoding ('Utf-8'). Scan (/finishedinch. +?s/). To_s.sub ('["',"'). Sub ('"]',"')ifLine.force_encoding ('Utf-8') =~/finishedinch/} $pwd= Pathname.new (__file__). Realpath.dirnameFile.readlines ("#{$pwd}/starttest.ini"). each{|line|@username= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/username\s*=/@passwd= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/passwd\s*=/@smtpaddress= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/smtpaddress\s*=/@port= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/port\s*=/@domain= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/domain\s*=/ $ from= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/ from\s*=/$to= Line.sub (/.+\s*=\s*/,"'). Chompifline=~/to\s*=/}SMTP= {: Address = @smtpaddress,:p ort = @port,:d omain = @domain,: user_name = @username,:p assword + @pa SSWD,: Enable_starttls_auto = True,: Openssl_verify_mode ='None'}mail.defaults {delivery_method:smtp, SMTP}mail=mail.new Do from$ fromTo $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} "endmail.deliver!
Mail:
Web Automation test: watir+minitest (Fri)