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 ...
随机推荐
- .Net用户控件
用户控件用户控件是个什么东西?自定义的反复重用的控件集合 好处?1.代码重用2.结构良好3.分工开发4.局部缓存 难点:一.交换信息: 注意信息的交换只在相邻层之间进行交换,如果是嵌套交换信息除Ses ...
- 【leetcode❤python】242. Valid Anagram
class Solution(object): def isAnagram(self, s, t): if sorted(list(s.lower()))==sorted(list ...
- Android 内部存储和外部存储
应用程序的一些配置文件需要存储在手机上.一般分为内部存储和SD卡存储. 一. 内部存储 ,以 FileOutputStream File file = new File(getFilesDir(),& ...
- VMware ESXI5.0的安装配置 zz
http://www.hotxf.com/thread-297-1-1.html 1, Vmware ESXI 光盘一张文件大小290M,本教程是以 5.0为案例. 2, 所需要安装的操作 ...
- jQuery插件之jquery editable plugin--点击编辑文字插件
jeditable是一个jquery插件,它的优点是可以就地编辑,并且提交到服务器处理,是一个不可多得的就地编辑插件.(注: 就地编辑,也有称即时编辑?一般的流程是这样的,当用户点击网页上的文字时,该 ...
- 2016ACM/ICPC亚洲区大连站-重现赛
题目链接:http://acm.hdu.edu.cn/search.php?field=problem&key=2016ACM%2FICPC%D1%C7%D6%DE%C7%F8%B4%F3%C ...
- py延迟注入SQL脚本
延迟注入工具(python) #!/usr/bin/env python # -*- coding: utf-8 -*- # 延迟注入工具 import urllib2 import time imp ...
- 在服务器上log4net没写日志
登录到服务器上,发现log4net没写日志 在相应文件夹加上User用户的写权限后恢复正常了.
- c++实现两个文件的拼接。
问题描述: 要求把第二个文件拼接到第一个文件的末尾. 如把file2 拼接到 file末尾. (直接复制一下不就行了嘛! 但是老师非让编程, 真是蛋疼!!,而且是闲的蛋疼!!!).例如: file1: ...
- android tablelayout 显示图片
当在tablelayout中显示图片时,设置imageView为固定大小时,会出现divide by zero 错误 将LayoutParams 改为 TableRow.LayoutParams即可 ...