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. 向量算子优化Vector Operation Optimization

    向量算子优化Vector Operation Optimization 查看MATLAB命令View MATLAB Command 示例显示Simulink编码器 ,将生成向量的块输出,设置为标量,优 ...

  2. JavaScript 中精度问题以及解决方案

    JavaScript 中的数字按照 IEEE 754 的标准,使用 64 位双精度浮点型来表示.其中符号位 S,指数位 E,尾数位M分别占了 1,11,52 位,并且在 ES5 规范 中指出了指数位E ...

  3. eclipse解决中文乱码

    参考链接:https://blog.csdn.net/lzc2644481789/article/details/97244261

  4. Linux学习笔记:用户与用户组

    基本概念 Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统. 用户 也就是说任何需要使用操作系统的用户,都 ...

  5. 如何基于 String 实现同步锁?

    如何基于String实现同步锁? 在某些时候,我们可能想基于字符串做一些事情,比如:针对同一用户的并发同步操作,使用锁字符串的方式实现比较合理. 因为只有在相同字符串的情况下,并发操作才是不被允许的. ...

  6. 打开黑盒:从 MySQL架构设计出发,看它是如何执行一条 SQL语句的

    1.把MySQL当个黑盒子一样执行SQL语句 我们的系统采用数据库连接池的方式去并发访问数据库,然后数据库自己其实也会维护一个连接池,其中管理了各种系统跟这台数据库服务器建立的所有连接 当我们的系统只 ...

  7. C#WebService的创建与发布

    VS中新建项目-Web-ASP.NET Web应用程序 然后确定,选择空模版就可以了 其中CRMService.asmx是点击项目新建Web服务(asmx) 这样基本的功能就能用了,然后就是发布 点击 ...

  8. Golang编写Windows动态链接库(DLL)及C调用范例

    一.准备. 1.GoLang在1.10版本之后开始支持编译windows动态链接库,可以打开命令行工具使用go version 查看自己的go版本. 2.你的电脑上需要gcc,如果没有的话[点击这里] ...

  9. 把 STM32 bluepill 变成调试器(daplink)

    在调一块 ARM M0 内核的板子,使用官方的 DEMO 板子来调,板子上集成了 daplink 调试器. 为了方便使用,我把目标板跟 daplink 剪开了,然后用杜邦线把 daplink 跟目标板 ...

  10. js笔记21

    1.解决函数内的this指向 (1)可以在函数外提前声明变量  _this/=this (2)通过apply和call来修改函数内的this指向 二者的区别: 二者的用法不一样,就是参数形式不一样   ...