Mail163.yaml配置文件如下:

login_data:
url : 'https://mail.163.com/'

case1:
user : ''
passwd : ''
errorText : '请输入帐号'

case2:
user : 'admin'
passwd : ''
errorText : '请输入密码'

case3:
user : ''
passwd : 'admin'

case4:
user : '&&&^^^'
passwd : ''
errorText : '帐号格式错误'

import yaml
import unittest
from selenium import webdriver
from selenium.webdriver.common.by import By
import time

#yaml简介 https://www.ibm.com/developerworks/cn/xml/x-cn-yamlintro/index.html

#安装:pip install yaml

def getdata():
# 读取yaml的值
yamlindex = open('Mail163.yaml','r',encoding='utf-8')
# 把文件内容读取出来
data = yaml.load(yamlindex)
return data

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()

def Assert_Text(self):
#断言 :文本断言
try:
divtext = self.driver.find_element(By.CSS_SELECTOR, 'div.ferrorhead').text
return divtext
except Exception as msg:
print("断言失败{}".format(msg))
self.driver.switch_to_default_content()

def test_username_password_null(self):
'''验证:用户名和密码为空的错误信息提示'''
self.login_163(getdata()['case1']['user'],getdata()['case1']['passwd'])
self.assertEqual(self.Assert_Text(),getdata()['case1']['errorText'])

def test_username_null(self):
'''验证:用户名为空密码不为空的错误信息提示'''
self.login_163(getdata()['case2']['user'], getdata()['case2']['passwd'])
self.assertEqual(self.Assert_Text(), getdata()['case2']['errorText'])

def test_passwd_null(self):
'''验证:用户名不为空密码为空的错误信息提示'''
self.login_163(getdata()['case3']['user'], getdata()['case3']['passwd'])
self.assertEqual(self.Assert_Text(), getdata()['case1']['errorText'])

def test_username_input_format(self):
'''验证:用户名输入非法字符的错误信息提示'''
self.login_163(getdata()['case4']['user'], getdata()['case4']['passwd'])
self.assertEqual(self.Assert_Text(), getdata()['case4']['errorText'])

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

python之数据驱动yaml操作的更多相关文章

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

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

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

    import unittestfrom selenium import webdriverfrom selenium.webdriver.common.by import Byimport unitt ...

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

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

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

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

  5. python之数据驱动Txt操作

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

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

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

  7. 基于Python+Requests+Pytest+YAML+Allure实现接口自动化

    本项目实现接口自动化的技术选型:Python+Requests+Pytest+YAML+Allure ,主要是针对之前开发的一个接口项目来进行学习,通过 Python+Requests 来发送和处理H ...

  8. Python开发【第三篇】:Python基本之文件操作

    Python基本之文本操作 一.初识文本的基本操作 在python中打开文件有两种方式,即:open(...) 和  file(...) ,本质上前者在内部会调用后者来进行文件操作,推荐使用 open ...

  9. 【Python数据分析】Python3操作Excel(二) 一些问题的解决与优化

    继上一篇[Python数据分析]Python3操作Excel-以豆瓣图书Top250为例 对豆瓣图书Top250进行爬取以后,鉴于还有一些问题没有解决,所以进行了进一步的交流讨论,这期间得到了一只尼玛 ...

随机推荐

  1. 浪潮 ClusterEngineV4.0 任意命令执行

    1.浪潮ClusterEngineV4.0 任意命令执行 影响版本 ClusterEngineV4.0 2.漏洞影响 远程代码执行 3.复现 fofa语句 title='TSCEV4.0' 抓包构造e ...

  2. MapReduce —— MapTask阶段源码分析(Input环节)

    不得不说阅读源码的过程,极其痛苦 .Dream Car 镇楼 ~ ! 虽说整个MapReduce过程也就只有Map阶段和Reduce阶段,但是仔细想想,在Map阶段要做哪些事情?这一阶段具体应该包含数 ...

  3. JUC 并发编程--11, AQS源码原理解析, ReentrantLock 源码解读

    这里引用别人博客,不重复造轮子 https://blog.csdn.net/u012881584/article/details/105886486 https://www.cnblogs.com/w ...

  4. VNC 相关

    vncserver启动报错root A VNC server is already running as :1 [root@42 ~]# service vncserver startStarting ...

  5. Java IO学习笔记六:NIO到多路复用

    作者:Grey 原文地址:Java IO学习笔记六:NIO到多路复用 虽然NIO性能上比BIO要好,参考:Java IO学习笔记五:BIO到NIO 但是NIO也有问题,NIO服务端的示例代码中往往会包 ...

  6. Django基础之视图层

    内容概要 小白必会三板斧 request对象方法初识 form表单上传文件 Jsonresponse FBV与CBV 内容详细 1 小白必会三板斧 HttpResponse render redire ...

  7. JVM学习第一篇思考:一个Java代码是怎么运行起来的-上篇

    JVM学习第一篇思考:一个Java代码是怎么运行起来的-上篇 作为一个使用Java语言开发的程序员,我们都知道,要想运行Java程序至少需要安装JRE(安装JDK也没问题).我们也知道我们Java程序 ...

  8. RPM安装MySQL5.7并更改数据目录

    RPM安装MySQL5.7并更改数据目录 文末附MySQL完整配置文件 官网地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads 注意 ...

  9. 温故知新,.Net Core遇见Blazor(FluentUI),属于未来的SPA框架

    什么是Blazor Blazor是一个使用.NET生成交互式客户端WebUI的框架: 使用C#代替JavaScript来创建信息丰富的交互式UI. 共享使用.NET编写的服务器端和客户端应用逻辑. 将 ...

  10. .net core 支付宝,微信支付 一

    源码: https://github.com/aspros-luo/Qwerty.Payment/tree/develop 支付宝支付:参考支付宝sdk及文档,https://docs.open.al ...