selenium+python笔记7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@desc: 测试126邮箱的登陆功能
1.使用公共方法public.login
2.将测试数据放在xml文件中,使用数据驱动(/test_data/login.xml)
3.这里使用xml.dom.minidom读取xml数据
"""
import unittest
import xml.dom.minidom
import os
import sys
from selenium import webdriver cur_dir = os.getcwd()
sys.path.append(cur_dir.split(r'\test_case')[0]) from public import login fpath = cur_dir.split('test_case')[0] + 'test_data' + os.path.sep + 'login.xml' # 打开 xml 文档
dom = xml.dom.minidom.parse(fpath) # 得到文档元素对象
root = dom.documentElement class TestLogin(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
logins = root.getElementsByTagName('url')
self.base_url = logins[0].firstChild.data
self.verificationErrors = [] # 用例1:用户名、密码为空
def test_null(self):
driver = self.driver
driver.get(self.base_url)
# 读取xml中的数据
logins = root.getElementsByTagName('null')
# 获得 null 标签的 username、password 属性值
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
# 登录
login.login(self, username, password)
# 获取断言信息进行断言
text = driver.find_element_by_xpath("//div[@class='error-tt']/p").text
self.assertEqual(text, prompt_info) # 用例2:用户名为空
def test_user_null(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('user_null')
# 获得 user_null 标签的 username、passwrod 属性值
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
# 登录
login.login(self, username, password)
# 获取断言信息进行断言
text = driver.find_element_by_xpath("//div[@class='error-tt']/p").text
self.assertEqual(text, prompt_info) # 用例3:密码为空
def test_pwd_null(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('pwd_null')
# 获得 pwd_null 标签的 username、passwrod 属性值
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
# 登录
login.login(self, username, password)
# 获取断言信息进行断言
text = driver.find_element_by_xpath("//div[@class='error-tt']/p").text
self.assertEqual(text, prompt_info) # 用例4:错误的用户名和密码
def test_error(self):
driver = self.driver
driver.get(self.base_url)
logins = root.getElementsByTagName('error')
# 获得 error 标签的 username、passwrod 属性值
username = logins[0].getAttribute("username")
password = logins[0].getAttribute("password")
prompt_info = logins[0].firstChild.data
# 登录
login.login(self, username, password)
# 获取断言信息进行断言
text = driver.find_element_by_xpath("//div[@class='error-tt']/p").text
self.assertEqual(text, prompt_info) def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors) if __name__ == "__main__":
unittest.main()
selenium+python笔记7的更多相关文章
- selenium+python笔记11
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...
- selenium+python笔记10
#!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 &qu ...
- selenium+python笔记9
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删 ...
- selenium+python笔记8
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...
- selenium+python笔记6
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 将登陆动作封装成function "" ...
- selenium+python笔记5
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 登陆126邮箱 """ f ...
- selenium+python笔记4
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...
- selenium+python笔记3
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc:学习unittest的用法 注意setUp/setUpCl ...
- selenium+python笔记2
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 操作浏览器 """ fro ...
随机推荐
- KEIL MDK 5.12帮你快速建工程模板的技巧
KEIL 5帮你快速建工程模板的技巧 本人使用keil mdk 5.12有一段时间了,发现keil mdk 5.12里面驱动库比较方便.这个新功能可以节省我们的时间,也可以让初学者能尽快上手和掌握这个 ...
- Android 进度条
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- ProgressDialog 的 使用
一 . ProgressDialog ProgressDialog是AlertDialog类的一个扩展,可以为一个未定义进度的任务显示一个旋转轮形状的进度动画,或者为一个指定进度的任务显示一个进度条. ...
- 【转载】图解:二叉搜索树算法(BST)
原文:图解:二叉搜索树算法(BST) 摘要: 原创出处:www.bysocket.com 泥瓦匠BYSocket 希望转载,保留摘要,谢谢!“岁月极美,在于它必然的流逝”“春花 秋月 夏日 冬雪”— ...
- 【转载】nedmalloc结构分析
原文:nedmalloc结构分析 nedmalloc是一个跨平台的高性能多线程内存分配库,很多库都使用它,例如:OGRE.现在我们来看看nedmalloc的实现 (以WIN32部分为例) 位操作 ...
- jQuery函数attr()和prop()的区别,val()
[自己总结,详情见下面转录的文章]: attr()用于操作html属性,prop()属性用于操作DOM属性 ①: 很多情况下可以互用 ②:attr()独自适用的情况,自定义的html属性,html属性 ...
- GCC编译器代码优化
代码优化是指编译器通过分析源代码,找出其中尚未达到最优的部分,然后对其重新进行组合,目的是改善程序的执行性能.GCC提供的代码优化功能非常强大,它通过编译选项-On来控制优化代码的生成,其中n是一个代 ...
- Oracle重置过期的密码
过期的原因一般有两种可能: 一.由于Oracle 11g在默认的default概要文件中设置了“PASSWORD_LIFE_TIME=180”天导致: 这种情况的解决办法: 1.查看用户的proi ...
- SQL——连接查询
以mysql为例: 新建两张表table1和table2 CREATE TABLE `table1` ( `id` ) NOT NULL auto_increment, `name` ) defaul ...
- BeanUtils框架的简单运用
Sun公司的内省API过于繁琐,所以Apache组织结合很多实际开发中的应用场景开发了一套简单.易用的API操作Bean的属性——BeanUtils Beanutils工具包的常用类: •BeanUt ...