一、新建数据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. GPU编程和流式多处理器(三)

    GPU编程和流式多处理器(三) 3. Floating-Point Support 快速的本机浮点硬件是GPU的存在理由,并且在许多方面,它们在浮点实现方面都等于或优于CPU.全速支持异常可以根据每条 ...

  2. Relay张量集成

    Relay张量集成 Introduction NVIDIA TensorRT是一个用于优化深度学习推理的库.这种集成将尽可能多地减轻从中继到TensorRT的算子,在NVIDIA GPU上提供性能提升 ...

  3. hashmap专题

    hashmap重要变量 源码中定义了很多常量,有几个是特别重要的. DEFAULT_INITIAL_CAPACITY: Table数组的初始化长度: 1 << 4,即 2^4=16(这里可 ...

  4. Bind DNS服务——转发与区域记录更新

    Linux基础服务--Bind DNS服务 Part4 转发与区域记录更新 一个DNS服务器不可能保存所有的区域记录,所以我们一般都会将其他的区域纪录转发到其他的服务器上进行解析. Bind9提供了全 ...

  5. 学习Qt Charts-创建一个简单的折线图

    一.Qt Charts Qt Charts是基于Qt Graphics View实现的一个图表的组件,可以用来在QT GUI程序中添加现在风格的.可交互的.以数据为中心的图表,可以用作QWidget或 ...

  6. Ubuntu 之 Esc and CapsLK

    Ubuntu 更换 CapsLK 和 ESC 内容如下 // vim .xmodmap !! No Caps Lock clear lock !! Make Caps_lock an escape k ...

  7. 应用CRM的自动化功能为什么备受推崇

    相信每个销售团队都遇到过这样的问题:在跟进新客户的时候顾此失彼,在跟踪一个客户的时候,转眼就忘记了另一个客户.这种情况很常见,但是每个新客户都有潜在的价值,我们该如何做,才能避免错失商机?CRM客户管 ...

  8. 【spring源码系列】之【Bean的属性赋值】

    每次进入源码的世界,就像完成一场奇妙的旅行! 1. 属性赋值概述 上一篇讲述了bean实例化中的创建实例过程,实例化后就需要对类中的属性进行依赖注入操作,本篇将重点分析属性赋值相关流程.其中属性赋值, ...

  9. Camunda工作流引擎简单入门

    官网:https://camunda.com/ 官方文档:https://docs.camunda.org/get-started/spring-boot/project-setup/ 阅读新体验:h ...

  10. CentOS-Docker安装RabbitMQ(单点)

    这里注意获取镜像的时候要获取management版本的,不要获取last版本的,management版本的才带有管理界面. 获取镜像 $ docker pull rabbitmq:management ...