当前位置:网站首页>多线程实现多用例文件并发读取执行+Selenium Grid4实现测试框架分布式部署
多线程实现多用例文件并发读取执行+Selenium Grid4实现测试框架分布式部署
2022-07-29 02:30:00 【司小幽】
1.main.py
import os
import threading
from class25.excel_driver.excel_read import path, read
from class26 import log_conf
if __name__ == '__main__':
# 创建log对象
log = log_conf.get_log('./conf/log.ini')
# 通过读取data路径下是否有测试用例,有,就执行,没有就不执行
# 重跑集合
repeat = list()
# 测试用例集合
cases = list()
# 线程池创建
th = list()
# 读取路径下的测试用例
for path,dir,files in os.walk('../class25/data/'):
for file in files:
# 获取文件的后缀名
file_type = os.path.splitext(file)[1]
# file_name = os.path.split(file)[1]
file_name = os.path.splitext(file)[0]
# print(file_type)
# print(path+file)
if file_type == '.xlsx':
# print(file_type)
if 'old' not in file_name:
case_path = path+file
cases.append(case_path)
else:
log.error('文件类型错误:{}'.format(file))
# for case in cases:
# log.info('********正在执行{}文件*********'.format(case))
# f = read(case,log)
# if f:
# repeat.append(f)
# if len(repeat)>0:
# #调用重跑,运行repeat下的所有用例
# pass
# 基于用例的数量设置与之对应的线程数量
for case in cases:
th.append(threading.Thread(target = read,args = [case,log]))
# 启动线程
for t in th:
t.start()
2.封装获取用例的套件函数
''' 封装获取用例的套件函数 '''
import threading
import unittest
def get_suite():
path = './'
discover = unittest.defaultTestLoader.discover(start_dir=path, pattern='test*.py')
return discover
# 运行器运行套件函数
def runner(suite):
unittest.TextTestRunner().run(suite)
if __name__ == '__main__':
suites = get_suite()
th = []
for suite in suites:
th.append(threading.Thread(target=runner,args = [suite]))
for t in th:
t.start()
3.多线程的用例并发处理实现
''' 多线程的用例并发处理实现 多线程的操作 '''
import threading
from time import sleep
def run(name):
print(name+ '在跑步')
sleep(3)
print(name+'跑累了')
1.单线程效果
li = ['狐狸','网恋','寒灯']
# for i in li:
# run(i)
2.建立线程池
# 一起跑步:通过多线程的形态实现多用户一起跑步的效果
th = list()
3.分配线程
th.append(threading.Thread(target = run,args=['狐狸']))
th.append(threading.Thread(target = run,args=['网恋']))
th.append(threading.Thread(target = run,args=['寒灯']))
4.启动线程
# 如果你的多条线程是针对同一个文件来进行读写操作的话,为防止出现线程锁,需要添加join
for t in th:
t.start()
# 为了避免多线程对同一文件或内容进行操作,造成的锁
t.join()
4.访问Selenium Grid体系
''' 访问Selenium Grid体系 '''
from time import sleep
from selenium import webdriver
# 创建remote对象
driver = webdriver.remote('http://127.0.0.1:4444/wd/hub')
# a业务,b业务,c业务,用不同的driver对象执行不同的业务不就可以了
driver.get('http://www.baidu.com')
sleep(5)
driver.quit()
边栏推荐
- etcd实现大规模服务治理应用实战
- A good-looking IAPP donation list source code
- laravel框架中实现封装公共方法全局调用
- Implementation principle of golang synergy
- 云开发打工人必备上班摸鱼划水微信小程序源码
- 第六天笔记
- PHP process communication series (I) named pipes
- QT compilation of IOT management platform 48 characteristic function design
- Some records during the development of ros2/ros1
- Implement encapsulated public method global call in laravel framework
猜你喜欢

Shell 脚本 快速入门 -01

STM32F103 learn the steps and template fool tutorial of 1-keil5 project establishment

C language: Little Lele and hexadecimal conversion

并发模式之异步回调Future模式

QT屏幕自适应自动布局,拖动窗口自动变大变小(一)

Comic algorithm_ Xiaohuihui interview

一款好看的iapp捐赠榜单源码

DHCP协议详细解析
![[opencv] use OpenCV to call mobile camera](/img/66/6207bafbc9696e43da7a60a386a238.jpg)
[opencv] use OpenCV to call mobile camera

区区区间---线段树lazy标记板子题
随机推荐
以科技传递温度,vivo亮相数字中国建设峰会
HTTP cache
Comic algorithm_ Xiaohuihui interview
11.书写规则-伪目标
并发模式之单例和不变模式
Three expiration strategies
HTB-Blue
(作业)C语言:atoi和strncpy、strncat、strncmp的模拟实现
Implementation principle of golang synergy
Happy childhood
解析机器人与人类情感共鸣的主观意识
QT屏幕自适应自动布局,拖动窗口自动变大变小(一)
K210 - sound source location and sound recognition
10. Writing rules - Document Search
Some records during the development of ros2/ros1
[untitled]
A good-looking IAPP donation list source code
第八天笔记
vim常用命令
用于校园流浪猫信息记录和分享的小程序源码/微信云开发中大猫谱小程序源码