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

#安装 : pip install parameterized

#数据驱动模型
# ddt excel+ddt yaml+ddt txt+ddt

#@unpack 表示用来解压元组到多个参数
#应用:ui级别的自动化测试中可以实现编写一个测试用例实现多个不同的测试点验证
#例如在163邮箱登录页面中,存在多种测试情况,如用户名和密码为空,用户名为空密码不为空,密码为空用户名不为空返回的错误提示信息

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()

#只有一个列表,列表里面有元组
@parameterized.expand(
[('', '', '请输入帐号'),
('admin', '', '请输入密码'),
('', 'admin', '请输入帐号'),
('^^^', '', '帐号格式错误')])
def test_login(self,username,password,result):
#登录163 --异常处理
self.login_163(username,password)
time.sleep(2)
try:
divtext = self.driver.find_element(By.CSS_SELECTOR, 'div.ferrorhead').text
print("错误信息:", divtext)
self.assertEqual(divtext, result)
except Exception as msg:
print("断言失败{}".format(msg))
self.driver.switch_to_default_content()

if __name__ == '__main__':
unittest.main(verbosity=2)

最新文章

  1. osgi dm
  2. jQuery获取cookie
  3. 做IT不能一辈子只靠技术生存
  4. 真实的C++单例模式举例
  5. dotfuscator初步
  6. Elasticsearch简单介绍
  7. Unity3D4.x之AssetBundle学习笔记
  8. Loggerly技术架构
  9. 每天一个linux命令(37)--iostat命令
  10. golang http server分析(一)
  11. vertical-align 与 line-height 傻傻分不清??
  12. PowerBI开发 第四篇:DAX表达式
  13. 【Python】Elasticsearch和elasticsearch_dsl
  14. Effective C++ 笔记:条款 32 确定你的public继承塑造出正确的is-a关系
  15. LeetCode – LRU Cache (Java)
  16. linux文件系统问题:wrong fs type, bad option, bad superblock
  17. Zookeeper 系列(二)安装配制
  18. 关于php的array_diff和array_diff_assoc的使用总结
  19. c++ list set 方法集合
  20. OpenID 和 OAuth 的区别及第三方登录的安全隐患分析

热门文章

  1. 编写HSA内核
  2. 毫米波RADAR与LIDAR探秘
  3. 基于自动驾驶车辆的NVIDIA-TensorRT推理实时优化
  4. C++标准模板库(STL)——queue常见用法详解
  5. P1045 [NOIP2003 普及组] 麦森数
  6. 微信小程序 -- 基于 movable-view 实现拖拽排序
  7. [翻译]Go与C#的比较,第二篇:垃圾回收
  8. 【NLP学习其二】什么是隐马尔可夫模型HMM?
  9. 旁路电容的PCB布局布线透彻详解(4)
  10. Unity 添加,修改默认创建脚本模板