一、新建数据Mail163.txt文本

二、Txt_Mail163.py脚本如下:

  1. 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. 利用NVIDIA NGC的TensorRT容器优化和加速人工智能推理

    利用NVIDIA NGC的TensorRT容器优化和加速人工智能推理 Optimizing and Accelerating AI Inference with the TensorRT Contai ...

  2. 面试一次问一次,HashMap是该拿下了(一)

    文章目录 前言 一.HashMap类图 二.源码剖析 1. HashMap(jdk1.7版本) - 此篇详解 2. HashMap(jdk1.8版本) 3. ConcurrentHashMap ~~ ...

  3. Qt自定义信号槽的使用浅析+实例

    1. Qt中自定义信号槽的使用 Qt框架提供的信号槽在某些特定场景下是无法满足我们的项目需求的,因此我们还设计自己需要的的信号和槽,使用connect()对自定义的信号槽进行连接. 如果想要使用自定义 ...

  4. 【VBA】单元格插入图片,单元格删除图片

    封装函数: Sub 插入产品形象(strRange As String, datebaseTu As String) Dim strJpg As String strJpg = datebaseTu ...

  5. 04:CSS(02)

    溢出属性 p { height: 100px; width: 50px; border: 3px solid red; /*overflow: visible; !*默认就是可见 溢出还是展示*!*/ ...

  6. 循序渐进BootstrapVue,开发公司门户网站(1)---基于Bootstrap网站模板构建组件界面

    在前面随笔<使用BootstrapVue相关组件,构建Vue项目界面>概括性的介绍了BootstrapVue的使用过程,其实选用这个主要就是希望能够用来构建一些公司门户网站的内容,毕竟基于 ...

  7. 6.17考试总结(NOIP模拟8)[星际旅行·砍树·超级树·求和]

    6.17考试总结(NOIP模拟8) 背景 考得不咋样,有一个非常遗憾的地方:最后一题少取膜了,\(100pts->40pts\),改了这么多年的错还是头一回看见以下的情景... T1星际旅行 前 ...

  8. Oracle数据库delete删除普通堆表千万条记录

    Oracle数据库delete删除普通堆表千万条历史记录. 直接删除的影响: 1.可能由于undo表空间不足从而导致最终删除失败的问题: 2.可能导致undo表空间过度使用,影响到其他用户正常操作. ...

  9. 关于equals()和hashcode()的一些约定

    本文章主要讨论和回答一下几个问题: equals()的四大特性 equals()和hashcode()之间的关系,为什么我们经常说这两个方法要么都重写,要么都不重写? HashMap.HashSet等 ...

  10. Jenkins+SonarQube实现C#代码质量检查

    环境准备 SonarQube 项目创建 jenkins Windows构建节点配置 安装与SonarQube服务端相同版本jdk 安装sonar-scanner 并配置环境变量 安装Visual St ...