作者在 2016-04-28 16:12:55 发布以下内容
#-*- 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,revpassword):
#点击登录
self.clickElement("link","登录")
#输入用户名
self.sendElementValue("id","email",revname)
self.sendElementValue("name","password","revpassword",)
self.clickElement("xpath",".//*[@id='content']/div/div/div[2]/form/dl[4]/dd/input")
time.sleep(3)
#z注册
def loginModle(self,revname,password,revpassword):
#点击注册
self.clickElement("xpath",".//*[@id='header']/div[1]/div/ul/li[2]/a")
self.sendElementValue("xpath",".//*[@id='email']",revname)
self.sendElementValue("name","password",password)
self.sendElementValue("name","repassword",revpassword)
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
from TestShareLib import ConmomFunction1
p = ConmomFunction1.CommomFunction()
class TestRegistModel(unittest.TestCase):
def setUp(self):
p.browserInit("http://192.168.90.128/tinyshop/")
def tearDown(self):
p.browserDown()
def testRegist001(self):
p.RegistModel("111@qq.com","111111")
def testRegist002(self):
p.loginModle("12152@qq.com","111111","111111")
if __name__ == '__main__':
unittest.main()