作者在 2016-04-27 13:43:44 发布以下内容
#-*- coding:UTF-8 -*-
import time
from selenium import webdriver
import unittest
import traceback
class TestLoginModle(unittest.TestCase):
def setUp(self):
global driver
driver = webdriver.Firefox()
driver.get("http://192.168.90.128/tinyshop/")
driver.maximize_window()
def tearDown(self):
driver.quit()
time.sleep(2)
#注册成功
def testLogin001(self):
driver.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[2]/a").click()
driver.find_element_by_id("email").send_keys("111111@qq.com")
driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/input").send_keys("111111")
driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[3]/dd/input").send_keys("111111")
driver.find_element_by_xpath(".//*[@id='readme']").click()
driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[6]/dd/input").click()
time.sleep(3)
actValue = driver.find_element_by_xpath(".//*[@id='content']/div/div/div[1]").text
print actValue
#断言
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 testLogin002(self):
driver.find_element_by_xpath(".//*[@id='header']/div[1]/div/ul/li[2]/a").click()
driver.find_element_by_id("email").send_keys("")
driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[2]/dd/input").send_keys("111111")
driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[3]/dd/input").send_keys("111111")
driver.find_element_by_xpath(".//*[@id='readme']").click()
driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[6]/dd/input").click()
time.sleep(3)
actValue = driver.find_element_by_xpath(".//*[@id='content']/div/div[1]/div[2]/form/dl[1]/dd/label").text
print actValue
#断言
try:
self.assertEqual(actValue,u"邮箱(例如:demo@tinyx.com)")
except:
f=open("../TestShopLog/login.txt", 'a')
traceback.print_exc(file=f)
f.flush()
f.close()
print u"第一条实际结果为:",actValue,u"实际结果与预期结果不符"
if __name__ == '__main__':
unittest.main()