Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构

1、Business:公共业务模块,如登录模块,可以把登录模块进行封装供调用

------login_business.py


  1. from Page_Object.Common_Page.login_page import Login_Page
  2. from HTMLReport import logger
  3. import time
  4. def login(driver, username, password):
  5. """
  6. 登录业务
  7. :param driver:浏览器驱动
  8. :param username:用户名
  9. :param password:密码
  10. :return:None
  11. """
  12. logger().info(f"使用用户名:{username},密码:{password}进行登陆")
  13. login_page = Login_Page(driver)
  14. login_page.send_username(username)
  15. login_page.send_password(password)
  16. login_page.submit()
  17. time.sleep(2)

----Base_url.py:对应的url地址

2、Common:与业务无关的公共模块,如对Selenium的二次封装,方便后期的调用,还有一些工具类,如在读取数据时需要对读取文件进行封装

3、PageOBject:这个就应该不用多说了,页面元素的封装,这个根据自己公司系统的业务去做分层封装(不做过多解释)

4、report:测试报告

5、TestCase:测试用例层,下面以logincase为例子

---logincase.py

  1. import unittest
  2. from Business.Base_url import url_index
  3. import ddt
  4. from Common.tools.read_txt import read_txt
  5. from HTMLReport import logger
  6. from Page_Object.Common_Page.index_page import Index_Page
  7. from Common.selenium_library import SeleniumBase
  8. from Business.login_business import login
  9. @ddt.ddt
  10. class Test_login(unittest.TestCase):
  11. def setUp(self):
  12. self.driver = SeleniumBase().get_web_driver()
  13. def tearDown(self):
  14. SeleniumBase(self.driver).quit()
  15. @ddt.unpack
  16. @ddt.data(*read_txt('TestData/login_user_password.txt'))
  17. def test_login(self, username, password, assert_type):
  18. se = SeleniumBase(self.driver)
  19. se.get(url_index)
  20. login(self.driver, username, password)
  21. se.add_page_screen_shot()
  22. if assert_type == '1':
  23. logger().info("断言登陆成功")
  24. text = Index_Page(self.driver).login_success()
  25. self.assertIn("测试", text, '登陆成功断言')
  26. elif assert_type == "2":
  27. text = self.driver.find_element_by_id("submit").text
  28. self.assertIn("立即登录", text, '登陆失败断言')
  29. elif assert_type == "3":
  30. text = self.driver.find_element_by_id("submit").text
  31. self.assertIn("立即登录", text, '登陆失败断言')
  32. elif assert_type == "4":
  33. text = self.driver.find_element_by_id("submit").text
  34. self.assertIn("立即登录", text, '登陆失败断言')
  35. else:
  36. logger().info(f"未知断言类型{assert_type}")
  37. self.assertTrue(False, "未知断言类型")

6、TestData:测试数据,对应用例的数据都是在这里去取

7、TestSuite:测试套件,以登录套件为例

---loginsuite.py

  1. import unittest
  2. from TestCase.LoginCase import login_case
  3. def return_suite():
  4. suite=unittest.TestSuite()
  5. loader=unittest.TestLoader()
  6. suite.addTests(loader.loadTestsFromTestCase(login_case.Test_login))
  7. return suite

8、browser.ini:浏览器配置文件

  1. [local]
  2. local_browser = False
  3. wait_time = 10
  4. [browser]
  5. name = chrome
  6. ;name = firefox
  7. ;name = ie
  8. window_width =
  9. window_height =
  10. [grid]
  11. command_executor = http://127.0.0.1:4444/wd/hub
  12. headless = False
  13. proxy =

9、run.py:整体运行文件

  1. import unittest
  2. from TestSuite.LinesSuite import lines_suite
  3. from TestSuite.LinesSuite import itinerary_suite
  4. import HTMLReport
  5. suite = unittest.TestSuite()
  6. # suite.addTests(login_suite.return_suite())
  7. suite.addTests(lines_suite.return_suite())
  8. suite.addTests(itinerary_suite.return_suite())
  9. HTMLReport.TestRunner(
  10. report_file_name="test",
  11. title='WEB UI 自动化',
  12. description='登陆',
  13. thread_count=3
  14. ).run(suite)

10、整体框架结构图:

Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构的更多相关文章

  1. Python+selenium+unittest+HTMLTestReportCN单元测试框架分享

    分享一个比较基础的,系统性的知识点.Python+selenium+unittest+HTMLTestReportCN单元测试框架分享 Unittest简介 unittest是Python语言的单元测 ...

  2. python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告

    1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请求参数 ...

  3. python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(二)

    可以参考 python+requests接口自动化完整项目设计源码(一)https://www.cnblogs.com/111testing/p/9612671.html 原文地址https://ww ...

  4. python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(已弃用)

    前言 1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请 ...

  5. python+selenium +unittest生成HTML测试报告

    python+selenium+HTMLTestRunner+unittest生成HTML测试报告 首先要准备HTMLTestRunner文件,官网的HTMLTestRunner是python2语法写 ...

  6. python+selenium+unittest,爬虫电影网站

    以前经常在这个网站上下载电影下来看,这个网站比较坑的就是,主页上只有电影的名称,但是评分是看不到的:只有再点击电影名字,进入电影主页时才能看到评分.一般下载的电影都是评分高的才看,低的就忽略掉了.每次 ...

  7. python+selenium+unittest 实现自动化测试

    示例代码: baidu.py import csv #导入csv模块 from itertools import islice #从itertools导入islice,后边让其默认跳过第一行使用 fr ...

  8. Python Selenium unittest+HTMLTestRunner实现 自动化测试及发送测试报告邮件

    1.UI测试框架搭建-目录结构 2. 文件介绍 2.1.baseinfo->__init__.py 配置文件定义基础参数 #-*-coding:utf-8-*- #测试用例配置参数 base_u ...

  9. python + selenium + unittest 自动化测试框架 -- 入门篇

    . 预置条件: 1. python已安装 2. pycharm已安装 3. selenium已安装 4. chrome.driver 驱动已下载 二.工程建立 1. New Project:建立自己的 ...

随机推荐

  1. Linux load average负载量分析与解决思路

    一.load average top命令中load average显示的是最近1分钟.5分钟和15分钟的系统平均负载.系统平均负载表示 系统平均负载被定义为在特定时间间隔内运行队列中(在CPU上运行或 ...

  2. 表格排序(tablesorter)

    1.在html页面的head中引用 <script src="/static/Bootstrap/js/jquery/jquery.tablesorter.min.js"&g ...

  3. PHP中unset,array_splice删除数组中元素的区别

    php中删除数组元素是非常的简单的,但有时删除数组需要对索引进行一些排序要求我们会使用到相关的函数,这里我们来介绍使用unset,array_splice删除数组中的元素区别吧 如果要在某个数组中删除 ...

  4. 乘风破浪:LeetCode真题_033_Search in Rotated Sorted Array

    乘风破浪:LeetCode真题_033_Search in Rotated Sorted Array 一.前言     将传统的问题进行一些稍微的变形,这个时候我们可能无所适从了,因此还是实践出真知, ...

  5. Hexo搭建博客笔记

    Hexo搭建(建议看ppt:https://files.cnblogs.com/files/-SANG/%E4%BD%A0%E7%9A%84%E7%8C%AB.pptx ) 安装Git https:/ ...

  6. CSS布局(三) 布局模型

    布局模型 在网页中,元素有三种布局模型:1.流动模型(Flow) 默认的2.浮动模型 (Float)3.层模型(Layer) 1.流动模型(Flow) 流动(Flow)模型是默认的网页布局模式.也就是 ...

  7. SDN 第四次作业

    阅读 了解SDN控制器的发展 http://www.sdnlab.com/13306.html http://www.docin.com/p-1536626509.html 了解ryu控制器 http ...

  8. 阿里八八Alpha阶段Scrum(7/12)

    今日进度 叶文滔: Andriod Studio新版打开旧版项目存在兼容性问题,仍在寻求解决办法 王国超: 今天还是在调bug,真机运行总是闪退 俞鋆: 正在学习api制作和相关的文档编写,研究了一些 ...

  9. oneinstack远程管理数据库

    本篇文章主要内容是本地工具连接数据非网页(网站)连接 如果你想使用网页(网站)连接远程数据库,请看下面的官网教程 OneinStack如何配置MySQL远程连接? 为了安全考虑,OneinStack仅 ...

  10. OpenCV——滤波

    常见滤波函数: 其中前3中为线性滤波,后2中为非线性滤波 参考资料:https://mp.weixin.qq.com/s/3maNqlTSkl6FQs_xqrs8Fg