import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
import unittest,time
from parameterized import parameterized

#安装 : pip install parameterized

#数据驱动模型
# ddt excel+ddt yaml+ddt txt+ddt

#@unpack 表示用来解压元组到多个参数
#应用:ui级别的自动化测试中可以实现编写一个测试用例实现多个不同的测试点验证
#例如在163邮箱登录页面中,存在多种测试情况,如用户名和密码为空,用户名为空密码不为空,密码为空用户名不为空返回的错误提示信息

class Mail_163(unittest.TestCase):
def setUp(self) -> None:
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.implicitly_wait(5)
self.driver.get("https://mail.163.com/")

def tearDown(self) -> None:
self.driver.quit()

def login_163(self,username,password):
#验证登录163邮箱N中情况
self.driver.find_element(By.ID,"switchAccountLogin").click()
iframe = self.driver.find_element(By.TAG_NAME,'iframe')
self.driver.switch_to_frame(iframe)
self.driver.find_element(By.NAME,'email').send_keys(username)
self.driver.find_element(By.NAME,'password').send_keys(password)
time.sleep(1)
self.driver.find_element(By.ID,"dologin").click()

#只有一个列表,列表里面有元组
@parameterized.expand(
[('', '', '请输入帐号'),
('admin', '', '请输入密码'),
('', 'admin', '请输入帐号'),
('^^^', '', '帐号格式错误')])
def test_login(self,username,password,result):
#登录163 --异常处理
self.login_163(username,password)
time.sleep(2)
try:
divtext = self.driver.find_element(By.CSS_SELECTOR, 'div.ferrorhead').text
print("错误信息:", divtext)
self.assertEqual(divtext, result)
except Exception as msg:
print("断言失败{}".format(msg))
self.driver.switch_to_default_content()

if __name__ == '__main__':
unittest.main(verbosity=2)

python之数据驱动ddt操作(方法三)的更多相关文章

  1. python之数据驱动ddt操作(方法四)

    from ddt import ddt,data,unpackfrom selenium import webdriverfrom selenium.webdriver.common.by impor ...

  2. python之数据驱动ddt操作(方法二)

    import unittestfrom ddt import ddt,unpack,datafrom selenium import webdriverfrom selenium.webdriver. ...

  3. python之数据驱动ddt操作(方法一)

    下载ddt并安装 Pip install ddt 或者官网下载安装 http://ddt.readthedocs.io/en/latest/ https://github.com/txels/ddt ...

  4. python对mysql数据库操作的三种不同方式

    首先要说一下,在这个暑期如果没有什么特殊情况,我打算用python尝试写一个考试系统,希望能在下学期的python课程实际使用,并且尽量在此之前把用到的相关技术都以分篇博客的方式分享出来,有想要交流的 ...

  5. python之数据驱动ddt

    下载ddt并安装 Pip install ddt 或者官网下载安装 http://ddt.readthedocs.io/en/latest/ https://github.com/txels/ddt ...

  6. 03 python学习笔记-文件操作(三)

    本文内容主要包括以下方面: 1. 文件操作基本认识2. 只读(r, rb)3. 只写(w, wb)4. 追加(a, ab)5. r+读写6. w+写读7. a+写读(追加写读)8. 文件的修改 一.文 ...

  7. python接口测试-数据驱动-DDT

    DDT是python的第三方库,全名称为:Data-Driven/Decorated Tests. ddt安装 通过pip安装ddt模块,安装Python后,Python自带pip功能包 切换到Pyt ...

  8. python之数据驱动Txt操作

    一.新建数据Mail163.txt文本 二.Txt_Mail163.py脚本如下: import unittestfrom selenium import webdriverfrom selenium ...

  9. python之数据驱动Excel操作(方法一)

    一.Mail163.xlsx数据如下: 二.Mail163.py脚本如下 import xlrdimport unittestfrom selenium import webdriverfrom se ...

随机推荐

  1. GPU虚拟化技术详解

    GPU虚拟化技术详解 GPU英文名称为Graphic Processing Unit,GPU中文全称为计算机图形处理器,1999年由NVIDIA公司提出. 一.GPU概述 GPU这一概念也是相对于计算 ...

  2. Numba实时变量分析

    Numba实时变量分析 Numba使用引用计数进行垃圾回收,这是一种需要编译器配合的技术.Numba IR对必须插入decref的位置进行编码.这些位置通过实时变量分析确定.相应的源代码是https: ...

  3. 10: java数据结构和算法: 构建哈夫曼树, 获取哈夫曼编码, 使用哈夫曼编码原理对文件压缩和解压

    最终结果哈夫曼树,如图所示: 直接上代码: public class HuffmanCode { public static void main(String[] args) { //获取哈夫曼树并显 ...

  4. ipconfig提示不是内部或外部命令

    昨天因为公司断网,重新连上之后ip地址变了,于是就想看看现在的ip是什么 输入ipconfig,回车 提示不是外部和内部命令,是因为系统在本路径下未找到ipconfig.exe系统,所以无法识别ipc ...

  5. SpringBoot线程池的创建、@Async配置步骤及注意事项

    最近在做订单模块,用户购买服务类产品之后,需要进行预约,预约成功之后分别给商家和用户发送提醒短信.考虑发短信耗时的情况所以我想用异步的方法去执行,于是就在网上看见了Spring的@Async了. 但是 ...

  6. 办公利器!用Python快速将任意文件转为PDF

    痛点: 相信大家都会遇到一种场景.老师/上司要求你把某个文件转为pdf,并且是一批(不止一个,一个的话手动就可以搞定),并且这种是枯燥无聊的工作,既没有什么技术含量又累. 试想一下,如果我把这些文件放 ...

  7. VisualEffectGraph概述

    Visual Effect Graph 由来: Visual Effect Graph 是2018.3 以后版本,出的新的粒子特效技术.它是用显卡渲染特效,区别于传统的Patical system 的 ...

  8. UnityBug之KeyStore

    UnityException: Can not sign the applicationUnable to sign the application; please provide passwords ...

  9. <5人公司极简研发方案

    人过35,被年轻人卷走了一大半,还停留在这个行业的,不是在创业,就是在创业的路上. 创业很难,刚开始没钱没人,啥都要自己干,一个字累.好处是地基是自己搭的,心里有底.不过博主最近健忘的毛病愈发严重了, ...

  10. layui checkbox 样式

    layui  checkbox扩展插件:  一.新建  checkbox.css 样式文件 .checkBox .block{float:left; margin:5px;padding:6px 6p ...