一、新建数据Mail163.txt文本

二、Txt_Mail163.py脚本如下:

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

#未封装的读取文本信息方法
# with open('Mail163.txt', 'r', encoding='utf-8') as fp:
# file = fp.readlines()
# aa = ''.join(file).split('\n')
# print(aa[2],type(aa[2]))

def MailInfo(index):
'''封装读取文本信息方法,index为读取的行数'''
with open('Mail163.txt','r',encoding='utf-8') as fp:
file = fp.readlines()
aa = "".join(file).split('\n')
return aa[index]

#报错信息 --添加encoding='utf-8'
#UnicodeDecodeError: 'gbk' codec can't decode byte 0xb7 in position 29: illegal multibyte sequence
# print(MailInfo(2))
#字符串切割\n -->用split('\n')
#['\n', 'admin\n', '^^^^\n', '请输入帐号\n', '请输入密码\n', '帐号格式错误']

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(MailInfo(0),MailInfo(0))
self.assertEqual(self.Assert_Text(),MailInfo(3))

def test_username_null(self):
'''验证:用户名为空密码不为空的错误信息提示'''
self.login_163(MailInfo(0),MailInfo(1))
self.assertEqual(self.Assert_Text(), MailInfo(3))

def test_passwd_null(self):
'''验证:用户名不为空密码为空的错误信息提示'''
self.login_163(MailInfo(1), MailInfo(0))
self.assertEqual(self.Assert_Text(),MailInfo(4))

def test_username_input_format(self):
'''验证:用户名输入非法字符的错误信息提示'''
self.login_163(MailInfo(2), MailInfo(1))
self.assertEqual(self.Assert_Text(), MailInfo(5))

if __name__ == '__main__':
unittest.main(verbosity=2) #详细日志信息

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

  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之数据驱动Excel操作(方法一)

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

  6. python之数据驱动yaml操作

    Mail163.yaml配置文件如下: login_data: url : 'https://mail.163.com/'case1: user : '' passwd : '' errorText ...

  7. python webdriver 测试框架-数据驱动txt文件驱动,带报告的例子

    数据驱动txt文件驱动的方式,带报告 data.txt: gloryroad test||光荣之路 摔跤爸爸||阿米尔 超人||电影 data_driven_by_txt_file.py: #enco ...

  8. Python中关于txt的简单读写模式与操作

    Python中关于txt的简单读写操作 常用的集中读写模式: 1.r 打开只读文件,该文件必须存在. 2.r+ 打开可读写的文件,该文件必须存在. 3.w 打开只写文件,若文件存在则文件长度清为0,即 ...

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

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

随机推荐

  1. Solon Auth 认证框架使用演示(更简单的认证框架)

    最近看了好几个认证框架,什么 Appache Shiro 啦.Sa-Token 啦.Spring Security啦...尤其是Spring Security,做为对标 Spring Boot &am ...

  2. 【C++】秒级时间戳,毫秒级时间戳

    时间戳,秒级 测试代码: #include <iostream> #include <time.h> #include <windows.h> using name ...

  3. 【UG二次开发】装配设计

    与装配相关的术语 tag 部件或对象的标识,还可能是部件原型.实例和事例 piece part 单个部件 occurrence 部件或对象的事例,装配中的是部件事例 object occurrence ...

  4. React开发中react-route-dom使用BrowserRouter部署到服务器上刷新时报404的问题

    React项目部署中遇到的问题 react开发中react-route使用BrowserRoute路径在iis服务器上刷新时报404的问题 解决:在发布的项目根目录添加web.config配置文件 在 ...

  5. 【Java】Debug断点调试常用技巧

    Debug操作技巧 Show Execution Point 将光标回到当前断点停顿的地方 Step Over 执行当前行代码,并将运行进度跳转到下一行. Step Into 进入到当前代码行的方法内 ...

  6. 如何提升springboot服务吞吐量

    生产环境偶尔会有一些慢请求导致系统性能下降,吞吐量下降,下面介绍几种优化建议. 方案 1.undertow替换tomcat 电子商务类型网站大多都是短请求,一般响应时间都在100ms,这时可以将web ...

  7. Spring Data JPA的Audit功能,审计数据库的变更

    我最新最全的文章都在南瓜慢说 www.pkslow.com,欢迎大家来喝茶! 1 数据库审计 数据库审计是指当数据库有记录变更时,可以记录数据库的变更时间和变更人等,这样以后出问题回溯问责也比较方便. ...

  8. Web端在线实时聊天,基于WebSocket(前后端分离)

    这是一个简易的Demo,已经实现了基础的功能 之前一直想实现一个实时聊天的系统,一直没有去实践他.有一天吃饭的时候扫码点菜,几个人点菜能够实时更新,当时就在想,这应该是同一种技术. 刚好前段时间项目上 ...

  9. Pytest学习笔记7-skip和skipif的使用

    前言 在实际的测试中,我们经常会遇到需要跳过某些测试用例的情况,pytest提供了skip和ifskip来跳过测试 下面我们就来通过一些例子看看skip和ifskip具体如何使用吧 skip的用法 使 ...

  10. 乘风破浪,Windows11设计和开发指导,全新图标字体和云母材质

    Windows11全新的布局设计 Windows 11全新的布局设计已设计为支持现代应用体验.渐进的圆角.嵌套元素和一致的排水沟相结合,营造出柔和.平静.平易近人的效果,强调目的的统一和易用性. ht ...