码迷,mamicode.com
首页 > 编程语言 > 详细

python转化rebot的测试报告

时间:2017-08-18 19:52:25      阅读:307      评论:0      收藏:0      [点我收藏+]

标签:get   table   [1]   statistic   element   set   auto   uri   time   

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os,sys,time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys

class get_Trandlation(object):
def __int__(self,report_path):
self.report_path=report_path
def get_tran(self,report_path):
browser = webdriver.Chrome()
browser.get(report_path)
detailContent=browser.find_element_by_xpath("//table[@class=‘details‘]").text
totalContent=browser.find_element_by_id("total-stats").text
TagContent=browser.find_element_by_id("tag-stats").text
SuiteContent=browser.find_element_by_id("suite-stats").text
total=browser.find_element_by_xpath("//*[@id=‘total-stats‘]/tbody/tr[1]/td[2]").text
pass_t=browser.find_element_by_xpath("//*[@id=‘total-stats‘]/tbody/tr[1]/td[3]").text
details=‘%.2f%%‘ % (int(pass_t)/int(total)*100)
return detailContent,totalContent,TagContent,SuiteContent,total,pass_t,details
class createReport(get_Trandlation):
def __init__(self,report_path,reportSavePath):
self.report_path=report_path
s=self.get_tran(report_path)
print s[0] ,s[6]
detailContent=s[0]
totalContent=s[1]
TagContent=s[2]
SuiteContent=s[3]
total=s[4]
pass_t=s[5]
details=s[6]
self.detailContent=detailContent
self.totalContent=totalContent
self.TagContent=TagContent
self.bySuiteContent=SuiteContent
self.total=total
self.pass_t=pass_t
self.percentage=details
self.percentage=reportSavePath
def createReportContent(self,report_path,reportSavePath):
result=self.detailContent.split("\n")
sDetail=‘‘
for index in range(len(result)):
if(index!=len(result)):
sDetail=sDetail+result[index]+"<br>"
else:
sDetail=sDetail+result[index]
print result
print type(result)
print len(result)
detailTable="<font size=‘5‘ style=‘font-weight:bold‘>Summary Information</font><br><table width=‘1000‘ border=‘1‘ cellpadding=‘1‘ cellspacing=‘1‘><tr><td width=‘100%‘>"+‘Run Pass Rate: ‘+self.percentage+"</td></tr><tr><td width=‘100%‘>"+sDetail+"</td></tr></table>"

totalTable="<table width=‘1000‘ border=‘1‘ cellpadding=‘1‘ cellspacing=‘1‘><tr bgcolor=‘#DCDCDC‘><td width=‘40%‘‘>Total Statistics</td><td>Total</td><td>Pass</td><td>Fail</td><td>Elapsed</td><td>Pass/Fail</td></tr>"
result=self.totalContent.split("\n")
del result[0]
del result[0]
del result[0]
del result[0]
del result[0]
del result[0]
for index in range(len(result)):
if((index+1)%2==1):
totalTable=totalTable+"<tr><td>"+result[index]+"</td>"
else:
s=result[index]
items=s.split(" ")
for item in items:
totalTable=totalTable+"<td>"+item+"</td>"
sColor="";
if(items[2]=="0"):
sColor="green"
else:
sColor="red"
totalTable=totalTable+"<td><center><font style=‘font-weight:bold;color:green‘>"+items[1]+"/</font><font style=‘font-weight:bold;color:"+sColor+"‘>"+items[2]+"</font></center></td></tr>"
totalTable=totalTable+"</table>"
byTagTable="<table width=‘1000‘ border=‘1‘ cellpadding=‘1‘ cellspacing=‘1‘><tr bgcolor=‘#DCDCDC‘><td width=‘40%‘>Statistics by Tag</td><td>Total</td><td>Pass</td><td>Fail</td><td>Elapsed</td><td>Pass/Fail</td></tr>"
result=self.byTagContent.split("\n")
del result[0]
del result[0]
del result[0]
del result[0]
del result[0]
del result[0]
for index in range(len(result)):
if((index+1)%2==1):
byTagTable=byTagTable+"<tr><td>"+result[index]+"</td>"
else:
s=result[index]
items=s.split(" ")
for item in items:
byTagTable=byTagTable+"<td>"+item+"</td>"
sColor="";
if(items[2]=="0"):
sColor="green"
else:
sColor="red"
byTagTable=byTagTable+"<td><center><font style=‘font-weight:bold;color:green‘>"+items[1]+"/</font><font style=‘font-weight:bold;color:"+sColor+"‘>"+items[2]+"</font></center></td></tr>"
byTagTable=byTagTable+"</table>"
bySuiteTable="<table width=‘1000‘ border=‘1‘ cellpadding=‘1‘ cellspacing=‘1‘><tr bgcolor=‘#DCDCDC‘><td width=‘40%‘>Statistics by Suite</td><td>Total</td><td>Pass</td><td>Fail</td><td>Elapsed</td><td>Pass/Fail</td></tr>"
result=self.bySuiteContent.split("\n") del result[0] del result[0] del result[0] del result[0] del result[0] del result[0] for index in range(len(result)): if((index+1)%2==1): bySuiteTable=bySuiteTable+"<tr><td>"+result[index]+"</td>" else: s=result[index] items=s.split(" ") for item in items: bySuiteTable=bySuiteTable+"<td>"+item+"</td>" sColor=""; if(items[2]=="0"): sColor="green" else: sColor="red" bySuiteTable=bySuiteTable+"<td><center><font style=‘font-weight:bold;color:green‘>"+items[1]+"/</font><font style=‘font-weight:bold;color:"+sColor+"‘>"+items[2]+"</font></center></td></tr>" bySuiteTable=bySuiteTable+"</table>" html="<html> <head><title></title><meta http-equiv=‘Content-Type‘ content=‘text/html; charset=utf-8‘ /></head><body>"+detailTable+"<font size=‘5‘ style=‘font-weight:bold;‘>Test Statistics</font>"+totalTable+"<br>"+byTagTable+"<br>"+bySuiteTable+"<br><font size=‘5‘ style=‘font-weight:bold;‘>更多详情请查看邮件附件【report.html】和【log.html】!!!</font></body></html>" print html read = open(reportSavePath,‘w‘) read.write(html) read.closeif __name__==‘__main__‘: s=createReport("F:\\jekens\\workspace\\auto_test_regression\\default\\report.html","d:report_1.html") s.createReportContent("F:\\jekens\\workspace\\auto_test_regression\\default\\report.html","d:report_1.html")

python转化rebot的测试报告

标签:get   table   [1]   statistic   element   set   auto   uri   time   

原文地址:http://www.cnblogs.com/colin2012/p/7391073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!