作者在 2016-06-22 23:17:09 发布以下内容
from xml.dom import minidom
import unittest
#######################################################################
class ReadXml(object):
def ReadXml(self,filename,elementfirstnode,num,elementsecondnode):
dom = minidom.parse(filename)
root = dom.documentElement
parnote = root.getElementsByTagName(elementfirstnode)[num]
secondnote = parnote.getElementsByTagName(elementsecondnode)[0].childNodes[0].nodeValue
return secondnote
#def Send(self,send_cmd): 發送命令,表示發送這個命令
#a,b = server.send_cmd(send_cmd)
#
#val[] = b[val]
#return a,b
#P = ReadXml()
#m = P.ReadXml("/home/sct/s.xml", "testdata", 0, "send_cmd0")
#print m
class bruceLee(unittest.TestCase):
def setUp(self):
global P
P = ReadXml()
print "start"
def tearDown(self):
print "exit"
def testA(self):
self.assertEqual("OK",P.ReadXml("/home/sct/s.xml", "testdata", 0, "act0"))
#self.assertTrue(m.lujingzhi("id",yang.denglu2("xml.xml", "kejian1", 0,"shuxing0")).is_displayed())
unittest.main()
<?xml version="1.0" encoding="utf-8"?>
<api>
<testdata>
<send_cmd0></send_cmd0>
<act0>OK</act0>
<send_cmd1></send_cmd1>
<act1>OK</act1>
<send_cmd2></send_cmd2>
<act2>OK</act2>
<send_cmd3></send_cmd3>
<act3>OK</act3>
<send_cmd4></send_cmd4>
<act4>OK</act4>
<send_cmd5></send_cmd5>
<act5>OK</act5>
<send_cmd6></send_cmd6>
<act6>OK</act6>
</testdata>
</api>