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. 深度学习Anchor Boxes原理与实战技术

    深度学习Anchor Boxes原理与实战技术 目标检测算法通常对输入图像中的大量区域进行采样,判断这些区域是否包含感兴趣的目标,并调整这些区域的边缘,以便更准确地预测目标的地面真实边界框.不同的模型 ...

  2. 单点突破:Set

    HashSet HashSet存放的是散列值,它是按照元素的散列值来存取元素的. 元素的散列值通过hashCode方法计算 HashSet通过判断两个元素的Hash值是否相等,如果相等就会用equal ...

  3. 在Visual Studio 中使用git——标记(Tag)管理(十)

    在Visual Studio 中使用git--什么是Git(一) 在Visual Studio 中使用git--给Visual Studio安装 git插件(二) 在Visual Studio 中使用 ...

  4. 「题解」NWRRC2017 Joker

    本文将同步发布于: 洛谷博客: csdn: 博客园: 简书. 题目 题目链接:洛谷 P7028.gym101612J. 题意概述 有一个长度为 \(n\) 的数列,第 \(i\) 个元素的值为 \(a ...

  5. 「题解」USACO15FEB Fencing the Herd G

    本文将同步发布于: 洛谷博客: csdn: 博客园: 简书: 题目 题目链接:洛谷 P3122.USACO 官网. 题意概述 给你平面上的一些点和直线,有两种操作: 新加入一个点 \((x,y)\): ...

  6. docker 自定义部署Springboot——依赖与代码分离部署

    第一步:执行mvn package 命令打出jar包,然后解压jar包,把lib放到服务器合适的目录下面 第二步:打出不带jar包的SpringBoot工程 首先配置pom.xml文件 <bui ...

  7. 【dp】10-8题解 vacation

    vacations 原题codeforeces round 363 (Div2) c 题目描述 暑假到了, Pb 正在计划他的假期. Pb 准备假期去体育馆锻炼或看电影.但体育馆和电影院都有可能当天不 ...

  8. Python 机器学习实战 —— 监督学习(下)

    前言 近年来AI人工智能成为社会发展趋势,在IT行业引起一波热潮,有关机器学习.深度学习.神经网络等文章多不胜数.从智能家居.自动驾驶.无人机.智能机器人到人造卫星.安防军备,无论是国家级军事设备还是 ...

  9. Java知识复习(四)

    最近准备跳槽,又要好好复习基本知识了.过了个年,前面刚接触的springboot也只能先放放了.就先把自己复习了哪些罗列出来吧. Set里的元素是不能重复的,那么用什么方法来区分重复与否呢? 是用== ...

  10. 555定时器(1)单稳态触发器电路及Multisim实例仿真

    555定时器(Timer)因内部有3个5K欧姆分压电阻而得名,是一种多用途的模数混合集成电路,它能方便地组成施密特触发器.单稳态触发器与多谐振荡器,而且成本低,性能可靠,在各种领域获得了广泛的应用. ...