一个菜鸟测试工程师的简易自动化测试框架

发表于:2012-9-06 10:39

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:AskaNeverEnd    来源:51Testing软件测试网采编

分享:

  读取 xml 的内容。这段代码属于我现学现卖,直接看了一下 python 对 xml 的支持,然后自己捣鼓了一下就写出来了,可以获取自己需要的 xml 里面的数据。

from xml.dom import minidom
class PageData():
def __init__(self, page_name, file):
self.name = page_name
self.data = minidom.parse(file)
self.xpth_dict = self.XML_Dict()
def XML_Dict(self):
xpath_dict = {}
for i in self.data.getElementsByTagName(self.name):
xpath_dict[str(i.childNodes[1].firstChild.nodeValue)] = \
[str(i.childNodes[5].firstChild.nodeValue),\
str(i.childNodes[7].firstChild.nodeValue)]
return xpath_dict
def GetLocator(self, object_name):
return self.xpth_dict[object_name][0]
def GetValue(self, object_name):
return self.xpth_dict[object_name][1]

  最后,主程序里面,我们就能用下面的方式,执行我们本来已经设计好的案例。

def testAutoCompleteFunctionMouseMove(self):
'''test the function of auto complete. case 2: when user move mouse to the suggestion, there will be a link '''
self.initTest("testAutoCompleteFunctionMouseMove")
self.open('http://www.google.com/ncr')
GoogleHomePage = data_parser.PageData("GoogleHomePage", self.data_file)
self.Type(GoogleHomePage.GetLocator('SEARCHTEXT'), 's')
GoogleAutoComplete = data_parser.PageData("AutoCompleteCase", self.data_file)
self.isElementPresent(GoogleAutoComplete.GetLocator("SUGGESTIONFIELD"))
time.sleep(10)
self.MouseMove(GoogleAutoComplete.GetLocator("SUGGESTIONONEFORS"))
expect_text = "I'm Feeling Lucky ?"
self.assertLogTrue(self.isTextPresent(expect_text), "The text %s has been displayed" %expect_text)
self.MouseMove(GoogleAutoComplete.GetLocator("SUGGESTIONTWOFORS"))
time.sleep(10)
self.assertLogTrue(self.isTextPresent(expect_text), "The text %s has been displayed" %expect_text)
self.endTest()

  这样,一个相当简易的自动化测试框架基本完工。可以完善的地方实在太多了,希望有志之士去完善吧,加入些新功能,譬如错误出现的时候截图,然后统计测试用例总数以及通过的数量。

  后记

  作为一个菜鸟测试工程师,没有任何的开发经验,搞出这个东西还是有点小激动的,也激发了本人对许多事情的兴趣。 以后希望能有更好的 test frame 去学习去创造。

33/3<123
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • d悠然夏天
    2015-10-16 10:17:07

    +1

  • fnngj
    2013-6-26 17:13:01

    求作者联系方式

  • TesterChen
    2012-9-21 13:16:13

    敢于动手去做,就是好的!

  • TesterChen
    2012-9-21 13:16:09

    敢于动手去做,就是好的!

  • pengpengfly
    2012-9-21 11:40:19

    不错,比那些瞎扯的强多了

  • dengwei729
    2012-9-19 11:06:19

    给力,好厉害

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号