作者在 2016-03-28 14:18:23 发布以下内容
在used包中新建suckpy文件,次为被调py文件(函数库)
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'suck'
from selenium import webdriver
class Login():
def BrowOpen(self,url): #定义浏览器登录动作
global bruce
bruce = webdriver.Firefox()
bruce.maximize_window() # max windows
bruce.get(url) # url是一个参数
def BrowClose(self):
bruce.close()
def LoginAct(self,revName,revPass,rePass8): #浏览器注册动作
bruce.find_element_by_link_text(u"注册").click()
bruce.find_element_by_id("email").send_keys(revName)
bruce.find_element_by_name("password").send_keys(revPass)
bruce.find_element_by_name("repassword").send_keys(rePass8)
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
def getElementValue(self,getType,getValue):#因为我们不知道具体的值是什么类型,所以if寻找
if getType == "id":
return bruce.find_element_by_id(getValue).text #得到id的数值,所以需要text
elif getType == "name":
return bruce.find_element_by_name(getValue).text
elif getType == "link_text":
return bruce.find_element_by_link_text(getValue).text
elif getType == "xpath":
return bruce.find_element_by_xpath(getValue).text
在use包中新建diaoyong模块
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'poptest'
import unittest,time
from used import Suck
s = Suck.Login()
class useLei(unittest.TestCase):
def setUp(self):
s.BrowOpen("http://192.168.242.128:8088/Tinyshop/")
def tearDown(self):
s.BrowClose()
def testCase1(self):
s.LoginAct("55464196939@qq.com","123456","123456")
ActValue = s.getElementValue("xpath",".//*[@id='content']/div/div/div[1]")
time.sleep(2)
self.assertEqual(ActValue,u"恭喜您,注册成功!")
def testCase2(self):
s.LoginAct("55464683@qq.com","123456","123456")
ActValue1 = s.getElementValue("xpath",".//*[@id='content']/div/div[1]/div[2]/form/dl[1]/dd/label")
self.assertEqual(ActValue1,u"此用户已经注册")
unittest.main()