#!/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的更多相关文章

  1. selenium+python笔记11

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: search in mail box "&qu ...

  2. selenium+python笔记10

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ 我们多添加一些测试场景,比如:删除邮件,查找邮件,发送邮件等等 &qu ...

  3. selenium+python笔记9

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: delete mail 我们多添加一些测试场景,比如:删 ...

  4. selenium+python笔记8

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 定制浏览器 """ imp ...

  5. selenium+python笔记6

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 将登陆动作封装成function "" ...

  6. selenium+python笔记5

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 登陆126邮箱 """ f ...

  7. selenium+python笔记4

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 使用unittest组织用例 ""& ...

  8. selenium+python笔记3

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc:学习unittest的用法 注意setUp/setUpCl ...

  9. selenium+python笔记2

    #!/usr/bin/env python # -*- coding: utf-8 -*- """ @desc: 操作浏览器 """ fro ...

随机推荐

  1. SqlSever基础 有over函数时,用as为新列起名

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  2. Android-表格布局 计算器 修改版

    <?xml version="1.0" encoding="utf-8"?> <TableLayout xmlns:android=" ...

  3. window server开发

    代码部分: public partial class tv : ServiceBase { public tv() { InitializeComponent(); ServiceName = &qu ...

  4. require或include相对路径多层嵌套引发的问题

    require或include相对路径多层嵌套引发的问题   php中require/include 包含相对路径的解决办法 在PHP中require,include一个文件时,大都是用相对路径,是个 ...

  5. CA*Layer(CAShapeLayer--CATextLayer)

    CAShapeLayer CAShapeLayer是一个通过矢量图形而不是bitmap来绘制的图层子类.你指定诸如颜色和线宽等属性,用CGPath来定义想要绘制的图 形,最后CAShapeLayer就 ...

  6. kakfa的常用命令总结

    Kafka的版本间差异较大,下面是0.8.2.1的操作方法 首先cd到kafaka的bin目录下;   #step1启动zookeeper服务 nohup bin/zookeeper-server-s ...

  7. C#正则表达式编程(二):Regex类用法

    上一篇讲述了在C#中有关正则表达式的类之间的关系,以及它们的方法,这一篇主要是将Regex这个类的用法的,关于Match及MatchCollection类会在下一篇讲到.对于正则表达式的应用,基本上可 ...

  8. ZOJ-3725 Painting Storages 动态规划

    题意:给定一个数N,表示有N个位置,要么放置0,要么放置1,问至少存在一个连续的M个1的放置方式有多少? 分析:正面求解可能还要考虑到重复计算带来的影响,该题适应反面求解.设dp[i][j]表示到前 ...

  9. iOS - Swift NSValue 值

    前言 public class NSValue : NSObject, NSCopying, NSSecureCoding 将任意数据类型包装成对象. 1.比较两个 NSValue 类型数据的大小 l ...

  10. iOS - AutoLayout

    前言 NS_CLASS_AVAILABLE_IOS(6_0) @interface NSLayoutConstraint : NSObject @available(iOS 6.0, *) publi ...