Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构
Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构
1、Business:公共业务模块,如登录模块,可以把登录模块进行封装供调用
------login_business.py
from Page_Object.Common_Page.login_page import Login_Page
from HTMLReport import logger
import time
def login(driver, username, password):
"""
登录业务
:param driver:浏览器驱动
:param username:用户名
:param password:密码
:return:None
"""
logger().info(f"使用用户名:{username},密码:{password}进行登陆")
login_page = Login_Page(driver)
login_page.send_username(username)
login_page.send_password(password)
login_page.submit()
time.sleep(2)
----Base_url.py:对应的url地址
2、Common:与业务无关的公共模块,如对Selenium的二次封装,方便后期的调用,还有一些工具类,如在读取数据时需要对读取文件进行封装
3、PageOBject:这个就应该不用多说了,页面元素的封装,这个根据自己公司系统的业务去做分层封装(不做过多解释)
4、report:测试报告
5、TestCase:测试用例层,下面以logincase为例子
---logincase.py
import unittest
from Business.Base_url import url_index
import ddt
from Common.tools.read_txt import read_txt
from HTMLReport import logger
from Page_Object.Common_Page.index_page import Index_Page
from Common.selenium_library import SeleniumBase
from Business.login_business import login
@ddt.ddt
class Test_login(unittest.TestCase):
def setUp(self):
self.driver = SeleniumBase().get_web_driver()
def tearDown(self):
SeleniumBase(self.driver).quit()
@ddt.unpack
@ddt.data(*read_txt('TestData/login_user_password.txt'))
def test_login(self, username, password, assert_type):
se = SeleniumBase(self.driver)
se.get(url_index)
login(self.driver, username, password)
se.add_page_screen_shot()
if assert_type == '1':
logger().info("断言登陆成功")
text = Index_Page(self.driver).login_success()
self.assertIn("测试", text, '登陆成功断言')
elif assert_type == "2":
text = self.driver.find_element_by_id("submit").text
self.assertIn("立即登录", text, '登陆失败断言')
elif assert_type == "3":
text = self.driver.find_element_by_id("submit").text
self.assertIn("立即登录", text, '登陆失败断言')
elif assert_type == "4":
text = self.driver.find_element_by_id("submit").text
self.assertIn("立即登录", text, '登陆失败断言')
else:
logger().info(f"未知断言类型{assert_type}")
self.assertTrue(False, "未知断言类型")
6、TestData:测试数据,对应用例的数据都是在这里去取
7、TestSuite:测试套件,以登录套件为例
---loginsuite.py
import unittest
from TestCase.LoginCase import login_case
def return_suite():
suite=unittest.TestSuite()
loader=unittest.TestLoader()
suite.addTests(loader.loadTestsFromTestCase(login_case.Test_login))
return suite
8、browser.ini:浏览器配置文件
[local]
local_browser = False
wait_time = 10
[browser]
name = chrome
;name = firefox
;name = ie
window_width =
window_height =
[grid]
command_executor = http://127.0.0.1:4444/wd/hub
headless = False
proxy =
9、run.py:整体运行文件
import unittest
from TestSuite.LinesSuite import lines_suite
from TestSuite.LinesSuite import itinerary_suite
import HTMLReport
suite = unittest.TestSuite()
# suite.addTests(login_suite.return_suite())
suite.addTests(lines_suite.return_suite())
suite.addTests(itinerary_suite.return_suite())
HTMLReport.TestRunner(
report_file_name="test",
title='WEB UI 自动化',
description='登陆',
thread_count=3
).run(suite)
10、整体框架结构图:

Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构的更多相关文章
- Python+selenium+unittest+HTMLTestReportCN单元测试框架分享
分享一个比较基础的,系统性的知识点.Python+selenium+unittest+HTMLTestReportCN单元测试框架分享 Unittest简介 unittest是Python语言的单元测 ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告
1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请求参数 ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(二)
可以参考 python+requests接口自动化完整项目设计源码(一)https://www.cnblogs.com/111testing/p/9612671.html 原文地址https://ww ...
- python+requests+excel+unittest+ddt接口自动化数据驱动并生成html报告(已弃用)
前言 1.环境准备: python3.6 requests xlrd openpyxl HTMLTestRunner_api 2.目前实现的功能: 封装requests请求方法 在excel填写接口请 ...
- python+selenium +unittest生成HTML测试报告
python+selenium+HTMLTestRunner+unittest生成HTML测试报告 首先要准备HTMLTestRunner文件,官网的HTMLTestRunner是python2语法写 ...
- python+selenium+unittest,爬虫电影网站
以前经常在这个网站上下载电影下来看,这个网站比较坑的就是,主页上只有电影的名称,但是评分是看不到的:只有再点击电影名字,进入电影主页时才能看到评分.一般下载的电影都是评分高的才看,低的就忽略掉了.每次 ...
- python+selenium+unittest 实现自动化测试
示例代码: baidu.py import csv #导入csv模块 from itertools import islice #从itertools导入islice,后边让其默认跳过第一行使用 fr ...
- Python Selenium unittest+HTMLTestRunner实现 自动化测试及发送测试报告邮件
1.UI测试框架搭建-目录结构 2. 文件介绍 2.1.baseinfo->__init__.py 配置文件定义基础参数 #-*-coding:utf-8-*- #测试用例配置参数 base_u ...
- python + selenium + unittest 自动化测试框架 -- 入门篇
. 预置条件: 1. python已安装 2. pycharm已安装 3. selenium已安装 4. chrome.driver 驱动已下载 二.工程建立 1. New Project:建立自己的 ...
随机推荐
- git命令:全局设置用户名邮箱配置
1.查看git配置信息 git config --list 2.查看git用户名 git config user.name 3.查看邮箱配置 git config user.email 4.全局配置用 ...
- chmod chown llinux文件及目录的权限介绍
linux 文件或目录的读.写.执行权限说明: chmod :设置文件或目录权限. u:所有者 g:所在组 o:其他组 a:所有人(u.g.o的总和) chmod -R 文件1/文件2….. ...
- spring-bean 版本的问题(报错:org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 75;)
当XML中配置的xsd是4.0,而引用的包是4以下的spring-bean.jar时,当服务器能连网时没问题,不能连网时,就报以下类似错误: org.xml.sax.SAXParseException ...
- 使用Index()+Match()函数实现更为灵活的VLookUp()
上一篇 http://www.cnblogs.com/-SANG/p/8407017.html 文章中已经介绍了vlookup的用法. 今天要使用index+match实现更为灵活的vlookup 先 ...
- Java多线程学习笔记之三内存屏障与Java内存模型
基本内存屏障 处理器支持那种内存重排序,就会提供能够禁止相应内存重排序的的指令,这些指令就被成为基本内存屏障:StroeLoad屏障.StroeLoad屏障.LoadLoad屏障.LoadStore屏 ...
- ICP点云配准原理及优化
ICP算法简介 根据点云数据所包含的空间信息,可以直接利用点云数据进行配准.主流算法为最近迭代算法(ICP,Iterative Closest Point),该算法是根据点云数据首先构造局部几何特征, ...
- JS内置对象-String对象、Date日期对象、Array数组对象、Math对象
一.JavaScript中的所有事物都是对象:字符串.数组.数值.函数... 1.每个对象带有属性和方法 JavaScript允许自定义对象 2.自定义对象 a.定义并创建对象实例 b.使用函数来定义 ...
- webstorm 2017 激活
参考:https://blog.csdn.net/wangyingwing/article/details/79119592
- jQuery UI dialog插件出错信息:$(this).dialog is not a function
使用jQuery UI 1.7.2 dialog插件,遇到这样的错误: [img]http://dl.iteye.com/upload/attachment/308166/97c428e4-2ce2- ...
- (mac系统下)mysql 入门
1.安装好mysql之后并且服务启动,系统偏好设置里有启动mysql服务的按钮 看到running表示可用 2.通过终端访问mysql 先到mysql的路径下(默认安装没有配置环境变量):cd /us ...