作者在 2016-03-27 18:40:24 发布以下内容
#-*- coding:UTF-8 -*- # 解码方式
__author__ = 'poptest'
import unittest
import time
from selenium import webdriver
class RegUser(unittest.TestCase):
def setUp(self):
global bruce
bruce = webdriver.Firefox() #start firfox brower .bruce定义为火狐浏览器
bruce.maximize_window() # max windows
bruce.get("http://192.168.242.128:8088/Tinyshop/") # url
#bruce.find_element_by_link_text("注册").click()
def teardown(self):
bruce.close()
bruce.exit()
def testUser1(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("55464683qq.com")
bruce.find_element_by_name("password").send_keys("123456")
bruce.find_element_by_name("repassword").send_keys("123456")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[1]/dd/label").text
self.assertEqual(actvalue,u"邮箱(例如:demo@tinyx.com)") #断言
time.sleep(2)
def testUser2(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("554646834@qq.com")
bruce.find_element_by_name("password").send_keys("123456")
bruce.find_element_by_name("repassword").send_keys("123456")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div/div[1]").text
self.assertEqual(actvalue,u"恭喜您,注册成功!")
time.sleep(2)
def testUser3(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("554646834@qq.com")
bruce.find_element_by_name("password").send_keys("123456")
bruce.find_element_by_name("repassword").send_keys("123456")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[1]/dd/label").text
self.assertEqual(actvalue,u"此用户已经注册")
time.sleep(2)
def testUser4(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("5546@qq.com")
bruce.find_element_by_name("password").send_keys("")
bruce.find_element_by_name("repassword").send_keys("")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/label").text
self.assertEqual(actvalue,u"6-20任意字符组合")
time.sleep(2)
def testUser5(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("5546@qq.com")
bruce.find_element_by_name("password").send_keys("12345")
bruce.find_element_by_name("repassword").send_keys("12345")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/label").text
self.assertEqual(actvalue,u"6-20任意字符组合")
time.sleep(2)
def testUser6(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("5546@qq.com")
bruce.find_element_by_name("password").send_keys("123456789012345678901")
bruce.find_element_by_name("repassword").send_keys("123456789012345678901")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/label").text
self.assertEqual(actvalue,u"6-20任意字符组合")
def testUser7(self):
bruce.find_element_by_link_text("注册").click()
bruce.find_element_by_id("email").send_keys("5543242@qq.com")
bruce.find_element_by_name("password").send_keys("123456")
bruce.find_element_by_name("repassword").send_keys("1234567")
bruce.find_element_by_name("verifyCode").send_keys("1111")
bruce.find_element_by_id("readme").click()
bruce.find_element_by_class_name("btn").click()
actvalue = bruce.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[3]/dd/label").text
self.assertEqual(actvalue,u"两次输入密码不一致")
# 执行全部用例
unittest.main()
#****************************
#下面为执行选择用例
caselist = ("testUser6","testUser7") # 将需要测试的case加入到caselist中
regSuite = unittest.TestSuite() # 声明测试套
for tmpcase in caselist: # 循环case,找到需要测试的用例
regSuite.addTest(RegUser(tmpcase)) # 添加用例到测试套,addTest(类名(方法名))
unittest.TextTestRunner().run(regSuite) # 执行测试套
regSuite = unittest.TestSuite()
regSuite.addTest(useLei("testUser6"))
unittest.TextTestRunner().run(regSuite) # 执行固定测试套