作者在 2016-04-28 16:41:57 发布以下内容
<?xml version="1.0" encoding="UTF-8"?>
<LoginDate>
<Login001>
<URL>http://192.168.90.128/tinyshop/</URL>
<name1>222@qq.com</name1>
<password1>111111</password1>
<!-- 实际的类型-->
<type>xpath</type>
<!--实际 -->
<value1>.//*[@id='header']/div[1]/div/ul/li[1]/a</value1>
</Login001>
<Login002>
<URL>http://192.168.90.128/tinyshop/</URL>
<name2>123532@qq.com</name2>
<password2>111111</password2>
<repassword2>111111</repassword2>
<type>xpath</type>
<value2>.//*[@id='content']/div/div/div[1]</value2>
<exp2>恭喜您,注册成功!</exp2>
</Login002>
</LoginDate>
'''
Created on 2016-4-27
@author: ydz
'''
#导入读取xml文件的驱动
from xml.dom import minidom
class ReadXmlDriver(object):
def RXmlTet(self,filename,firstnode,secondnode):
fileXml = minidom.parse('../TestShopDate/'+filename)
OneNode = fileXml.getElementsByTagName(firstnode)[0]
twoNode = OneNode.getElementsByTagName(secondnode)[0].childNodes[0].nodeValue
return twoNode
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'poptest'
import time,unittest
from selenium import webdriver
class CommomFunction(object):
def browserInit(self,revUrl):
global driver
driver = webdriver.Firefox()
driver.get(revUrl)
driver.maximize_window()
def browserDown(self):
driver.quit()
def clickElement(self,testType1,textValue1):
if testType1 == "link":
driver.find_element_by_link_text(textValue1).click()
elif testType1 == "id":
driver.find_element_by_id(textValue1).click()
elif testType1 == "name":
driver.find_element_by_name(textValue1).click()
elif testType1 == "xpath":
driver.find_element_by_xpath(textValue1).click()
#文本类型,文本值,变量name/passwd
def sendElementValue(self,textType2,textValue2,textValue3):
if textType2 == "link":
driver.find_element_by_link_text(textValue2).send_keys(textValue3)
elif textType2 == "id":
driver.find_element_by_id(textValue2).send_keys(textValue3)
elif textType2 == "name":
driver.find_element_by_name(textValue2).send_keys(textValue3)
elif textType2 == "xpath":
driver.find_element_by_xpath(textValue2).send_keys(textValue3)
def RegistModel(self,revname,revpasswd):
#点击登录
self.clickElement("link","登录")
#输入用户名
self.sendElementValue("id","email",revname)
self.sendElementValue("name","password",revpasswd)
self.clickElement("xpath",".//*[@id='content']/div/div/div[2]/form/dl[4]/dd/input")
time.sleep(3)
#获取实际结果
self.getElementText("xpath",".//*[@id='header']/div[1]/div/ul/li[1]/a")
def loginModle(self,revname,revpassword,revrepassword):
#点击注册
self.clickElement("xpath",".//*[@id='header']/div[1]/div/ul/li[2]/a")
self.sendElementValue("xpath",".//*[@id='email']",revname)
self.sendElementValue("name","password",revpassword)
self.sendElementValue("name","repassword",revrepassword)
self.clickElement("id","readme")
self.clickElement("class","btn")
time.sleep(2)
#获取文本值
def getElementText(self,textType,textValue):
if textType == "link":
return driver.find_element_by_link_text(textValue).text
if textType == "id":
return driver.find_element_by_id(textValue).text
if textType == "name":
return driver.find_element_by_name(textValue).text
if textType == "xpath":
return driver.find_element_by_xpath(textValue).text
if textType == "class":
return driver.find_element_by_class_name(textValue).text
#-*- coding:UTF-8 -*-
import time,unittest,traceback
from TestShareLib import ReadXmlDriver
from TestShareLib import ConmomFunction1
p = ConmomFunction1.CommomFunction()
M = ReadXmlDriver.ReadXmlDriver()
class TestRegistModel(unittest.TestCase):
def setUp(self):
p.browserInit(M.RXmlTet("TestLoginModel.xml","Login001","URL"))
def tearDown(self):
p.browserDown()
def testRegist001(self):
#p.RegistModel(M.RXmlTet("TestLoginModel.xml","Login001","name1"),M.RXmlTet("TestLoginModel.xml","Login001","password1"))
a = M.RXmlTet("TestLoginModel.xml","Login001","name1")
b = M.RXmlTet("TestLoginModel.xml","Login001","password1")
#传参a,b
p.RegistModel(a,b)
#接收实际结果
c = M.RXmlTet("TestLoginModel.xml","Login001","value1")
actValue = p.getElementText("xpath",c)
#断言
try:
self.assertEqual(actValue,u"安全退出")
except:
f=open("../TestShopLog/login.txt", 'a')
traceback.print_exc(file=f)
f.flush()
f.close()
print u"第一条实际结果为:",actValue,u"实际结果与预期结果不符"
def testloginModle(self):
#p.loginModle(M.RXmlTet("TestLoginModel.xml","Login002","name2"),M.RXmlTet("TestLoginModel.xml","Login002","password2"),M.RXmlTet("TestLoginModel.xml","Login002","revpassword2"))
e = M.RXmlTet("TestLoginModel.xml","Login002","name2")
f = M.RXmlTet("TestLoginModel.xml","Login002","password2")
g = M.RXmlTet("TestLoginModel.xml","Login002","repassword2")
#调用e,f
p.loginModle(e,f,g)
#接收实际结果
d = M.RXmlTet("TestLoginModel.xml","Login002","value2")
actValue = p.getElementText("xpath",d)
#断言
try:
self.assertEqual(d,u"恭喜您,注册成功!")
except:
f=open("../TestShopLog/login.txt", 'a')
traceback.print_exc(file=f)
f.flush()
f.close()
print u"第一条实际结果为:",d,u"实际结果与预期结果不符"
if __name__ == '__main__':
unittest.main()