亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源功能測試工具 > Selenium
簡易Selenium自動化測試框架(Python)
作者:網絡轉載 發布時間:[ 2016/6/14 11:42:10 ] 推薦標簽:自動化測試工具 Selenium

  用例執行模塊
  1. 借助外部文件記錄需要執行的用例
  testcases.txt(帶“#”標識的用例不會被執行):
  Test_Login.py
  Test_Login_2.py
  #Test_Login_3.py
  Test_Login_4.py
  2. 利用nose的nosetests命令執行各個用例:
  import subprocess
class RunTests(object):
"""description of class"""
def __init__(self):
self.testcaselistfile = "testcases.txt"
#use nosetests command to execute test case list
def LoadAndRunTestCases(self):
f = open(self.testcaselistfile)
testfiles = [test for test in f.readlines() if not test.startswith("#")]
f.close()
for item in testfiles:
subprocess.call("nosetests "+str(item).replace("\n",""),shell = True)
if __name__ == "__main__":
newrun = RunTests()
newrun.LoadAndRunTestCases()
  測試結果報表生成模塊
  測試報表模塊寫了兩種格式:xml和html
  TestReport.py
from xml.etree import ElementTree as ET
import os
import lxml.etree as mytree
from lxml import html
class TestReport(object):
"""description of class"""
def __init__(self):
self.testreport = "TestResult.xml"
#If there is no "TestResult.xml", then create one
def CreateTestResultFile(self):
if os.path.exists(self.testreport) == False:
newElem = ET.Element("TestCases")
newTree = ET.ElementTree(newElem)
newTree.write(self.testreport)
#Write test result to xml
def WriteResult(self,testcaseInfo):
self.CreateTestResultFile()
testResultFile = ET.parse(self.testreport)
root = testResultFile.getroot()
newElem = ET.Element("TestCase")
newElem.attrib = {
"ID":testcaseInfo.id,
"Name":testcaseInfo.name,
"Owner":testcaseInfo.owner,
"Result":testcaseInfo.result,
"StartTime":testcaseInfo.starttime,
"EndTime":testcaseInfo.endtime,
"ErrorInfo":testcaseInfo.errorinfo
}
root.append(newElem)
testResultFile.write(self.testreport)
#If there is no "TestResult.html" file exists, then create one with default style
def CreateHtmlFile(self):
if os.path.exists("TestResult.html") == False:
f = open("TestResult.html",'w')
message = """<html>
<head>
<title>Automation Test Result</title>
<style>
table {
border-collapse: collapse;
padding: 15px;
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
th{
background-color: green;
color: white;
border: 1px solid #ddd;
padding-bottom: 15px;
padding-top: 15px;
}
tr{
border: 1px solid #008000;
padding-bottom: 8px;
padding-top: 8px;
text-align: left;
}
td{
border: 1px solid #008000;
}
</style>
</head>
<body>
<h1>Automation Test Result</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Owner</th>
<th>Result</th>
<th>StartTime</th>
<th>EndTime</th>
<th>ErrorMessage</th>
</tr>
</table>
</body>
</html>
"""
f.write(message)
f.close()
#append new test result to testresult file
def WriteHTML(self,testcaseinfo):
self.CreateHtmlFile()
f = open("TestResult.html","r")
htmlcontent = f.read()
f.close()
tree = html.fromstring(htmlcontent)
tableElem = tree.find(".//table")
if testcaseinfo.result == "Failed":
mytablerow = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td bgcolor="#FF0000">{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>".format(testcaseinfo.id,testcaseinfo.name,testcaseinfo.owner,testcaseinfo.result,testcaseinfo.starttime,testcaseinfo.endtime,testcaseinfo.errorinfo)
else:
mytablerow = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td></tr>".format(testcaseinfo.id,testcaseinfo.name,testcaseinfo.owner,testcaseinfo.result,testcaseinfo.starttime,testcaseinfo.endtime,testcaseinfo.errorinfo)
tableElem.append(mytree.HTML(str(mytablerow)))
f = open("TestResult.html","w")
#html.tostring
newContent = repr(html.tostring(tree,method="html",with_tail=False))
newContent = newContent.replace(r" ","").replace(r" ","").replace('b'',"")
newContent = newContent[:len(newContent)-1]
f.write(newContent)
f.close()
  ok,后看一下生成的測試報表:

  總結
  在網上有很多關于Selenium自動化的Best Practice,當然大家也可以根據自己的需求來DIY自己的框架,不管簡陋與否,好用才是硬道理

上一頁12下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 天天狠狠 | 一级日韩一级欧美 | 亚洲jjzzjjzz在线观看 | 黄色短视频免费 | 国产丝袜在线视频 | 欧美日韩专区国产精品 | 2021国产精品自拍 | 成年人在线观看免费视频 | 亚洲成人黄色片 | 精品99视频| 朝鲜free嫩白的18sex性 | 国产婷婷色一区二区三区深爱网 | 东京一本热 | 国产一区精品 | 午夜在线免费观看视频 | 涩涩色视频在线播放 | 成人在线视频在线观看 | 中文字幕2019年中文字幕 | 新久草| 国产精品福利在线观看秒播 | 欧美日在线 | 色秀视频在线 | 丁香综合 | 国产第四页 | 污香蕉 | 欧美日韩一区二区在线 | 日本aⅴ在线不卡免费观看 日本aaa大片 | 中国在线播放精品区 | 成人国内精品久久久久影 | 波多野结衣在线观看一区二区三区 | 老司机成人午夜精品福利视频 | 亚洲美女操 | 福利所导航导航导航导航 | 亚洲一区欧美日韩 | 欧美精品亚洲精品日韩专区va | 欧美国产三级 | 成人在线免费网站 | 国产高清视频 | 日韩欧美在线免费观看 | h国产视频| 日韩三级中文字幕 |