#coding=utf-8
#编写测试脚本:以163邮箱登录功能为例
from selenium import webdriver
import unittest,time
#导入login文件
from public import login
#打开xml文件
import xml.dom.minidom
dom = xml.dom.minidom.parse('D:\\python\\test_163email\\login.xml')#打开xml文档
root = dom.documentElement#获得文档元素对象
class Test163email(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(10)
self.base_url = "https://mail.163.com/"
self.verificationErrors = []
'''
#用户名、密码为空
def test_null(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('null')
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
#登录
login.login(self,username,password)
#获取断言信息并断言
self.xpath = driver.find_element_by_xpath('//*[@id="loginDiv"]/iframe')
driver.switch_to.frame(self.xpath) #切换到frame
text = driver.find_element_by_class_name('ferrorhead').text
self.assertEqual(text,prompt_info)
driver.switch_to.default_content()#退出iframe
#输入用户名、密码为空
def test_pawd_null(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('pawd_null')
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
#登录
login.login(self,username,password)
#获取断言信息并断言
self.xpath = driver.find_element_by_xpath('//*[@id="loginDiv"]/iframe')
driver.switch_to.frame(self.xpath) #切换到frame
text = driver.find_element_by_class_name('ferrorhead').text
self.assertEqual(text,prompt_info)
driver.switch_to.default_content()#退出iframe
#输入密码、用户名为空
def test_user_null(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('user_null')
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
#登录
login.login(self,username,password)
#获取断言信息并断言
self.xpath = driver.find_element_by_xpath('//*[@id="loginDiv"]/iframe')
driver.switch_to.frame(self.xpath) #切换到frame
text = driver.find_element_by_class_name('ferrorhead').text
self.assertEqual(text,prompt_info)
driver.switch_to.default_content()#退出iframe
#用户名、密码错误
def test_error(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('error')
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
#登录
login.login(self,username,password)
#获取断言信息并断言
self.xpath = driver.find_element_by_xpath('//*[@id="loginDiv"]/iframe')
driver.switch_to.frame(self.xpath) #切换到frame
text = driver.find_element_by_class_name('ferrorhead').text
self.assertEqual(text,prompt_info)
driver.switch_to.default_content()#退出iframe
'''
#账号和密码正确
def test_login(self):
driver = self.driver
driver.get(self.base_url)
#登录
login.login(self,'alyna_cai','QQqq1122369')
#获取断言信息进行断言
time.sleep(3)
text = driver.find_element_by_id("spnUid").text
self.assertEqual(text,"alyna_cai@163.com")
#退出
login.logout(self)
def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__ == "__main__":
unittest.main()
网友评论