天天热消息:python检查Robot执行结果
1.解析Robot执行结果的python文件如下:
#coding:utf-8
import sys
(相关资料图)
import getopt
import xml.etree.ElementTree as ET
def print_node(node):
print "=============================================="
print "node.attrib:%s" % node.attrib
print "node.tag:%s" % node.tag
print "node.text:%s" % node.text
if node.attrib.has_key("name"):
print "node.attrib["rank"]:%s" % node.attrib["name"]
def checkRes(aFile):
failNum=0
tree = ET.parse(aFile)
root = tree.getroot()
first_node = root.getiterator("total")
first_node_child = first_node[0].getchildren()[1]
print_node(first_node_child)
if first_node_child.attrib.has_key("fail"):
failNum=first_node_child.attrib["fail"]
if int(failNum) > 0:
print ("API test fail. Failed Case Num:%s"%failNum)
sys.exit(-1)
else:
print ("API test Pass")
sys.exit(0)
if __name__=="__main__":
argv=sys.argv[1:]
inputfile = ""
try:
opts, args = getopt.getopt(argv,"i:")
except getopt.GetoptError:
sys.exit(-1)
for opt, arg in opts:
if opt =="-i":
inputfile = arg
print "Input log file", inputfile
checkRes(inputfile)
2.Jenkins job shell脚本如下:
python ./parse_xml.py -i ./testresult/output.xml
if [ $?==0 ];then
echo "Test Pass"
exit
else
echo "Test Fail"
exit 1
fi
责任编辑:
标签: exit node print python failNum attrib Robot