#!/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. MySQL基础(五)——视图

    MySQL基础(五)--视图

  2. 友情提醒:欲开发android5.0以上应用,请全部更新开发工具至最新

    周末帮人完成一个项目,android5.0以上版本,谁知道被开发工具折腾的死去活来.我的开发环境是adt-bundle-windows-x86-20140702.zip版本,也是目前能找到的adt-b ...

  3. js计时器的问题

    不说话直接上代码了 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> & ...

  4. [转]SIP穿越NAT&FireWall解决方案

    原文链接(也是转载)http://blog.csdn.net/yetyongjin/article/details/6881491.我修改了部分错字.   SIP从私网到公网会遇到什么样的问题呢? 1 ...

  5. ARM寻址方式

    寻址方式: 所谓寻址方式就是处理器根据指令中给出的信息来找到指令所需操作数的方式. 1.立即数寻址 2.寄存器寻址 3.寄存器间接寻址 就是寄存器中存放的是操作数在内存中的地址 例如以下指令: LDR ...

  6. iOS添加广告的主要方法

    //用户取消正在执行的广告时 调用 - (void)cancelBannerViewAction { NSLog(@"Banner was cancelled!"); self.a ...

  7. Sbt的使用初步和用sbt插件生成eclipse工程

    以前一直是用maven去管理java项目,现在开始写scala项目了但是在scala-ide中去编译scala项目和sbt的区别一直没弄清楚受到文章:http://my.oschina.net/yjw ...

  8. x名称空间

    XAML代码的WPF程序都需要通过语句:xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml",x就是用来映射xmlns:x= ...

  9. css position 绝对定位和相对定位

    position:absolute这个是绝对定位:是相对于浏览器的定位.比如:position:absolute:left:20px;top:80px; 这个容器始终位于距离浏览器左20px,距离浏览 ...

  10. 一个js(javascript)使用案例

    <script type="text/javascript"> var Row; $(function () { // $("#Sel").clic ...