当前位置:网站首页>Multithreading realizes concurrent reading and execution of multi use case files +selenium grid4 realizes distributed deployment of test framework
Multithreading realizes concurrent reading and execution of multi use case files +selenium grid4 realizes distributed deployment of test framework
2022-07-29 02:51:00 【Si Xiaoyou】
Catalog
1.main.py
import os
import threading
from class25.excel_driver.excel_read import path, read
from class26 import log_conf
if __name__ == '__main__':
# establish log object
log = log_conf.get_log('./conf/log.ini')
# By reading the data Whether there are test cases under the path , Yes , Is executed , No, No
# Rerun set
repeat = list()
# Test case collection
cases = list()
# Thread pool creation
th = list()
# Read the test cases under the path
for path,dir,files in os.walk('../class25/data/'):
for file in files:
# Get the suffix of the file
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(' Wrong file type :{}'.format(file))
# for case in cases:
# log.info('******** Being implemented {} file *********'.format(case))
# f = read(case,log)
# if f:
# repeat.append(f)
# if len(repeat)>0:
# # Call rerun , function repeat All use cases under
# pass
# Set the corresponding number of threads based on the number of use cases
for case in cases:
th.append(threading.Thread(target = read,args = [case,log]))
# Start thread
for t in th:
t.start()
2. Encapsulate the suite function that gets the use case
''' Encapsulate the suite function that gets the use case '''
import threading
import unittest
def get_suite():
path = './'
discover = unittest.defaultTestLoader.discover(start_dir=path, pattern='test*.py')
return discover
# The runner runs the suite functions
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. Multithreaded use case concurrent processing implementation
''' Multithreaded use case concurrent processing implementation Multithreaded operation '''
import threading
from time import sleep
def run(name):
print(name+ ' Running ')
sleep(3)
print(name+' Tired of running ')
1. Single thread effect
li = [' fox ',' cyber-love experiences ',' Cold lamp ']
# for i in li:
# run(i)
2. Set up thread pool
# Run together : Realize the effect of multi-user running together through multi-threaded form
th = list()
3. Assign threads
th.append(threading.Thread(target = run,args=[' fox ']))
th.append(threading.Thread(target = run,args=[' cyber-love experiences ']))
th.append(threading.Thread(target = run,args=[' Cold lamp ']))
4. Start thread
# If your multiple threads are reading and writing to the same file , To prevent thread lock , Need to add join
for t in th:
t.start()
# In order to avoid multiple threads operating on the same file or content , Lock caused by
t.join()
4. visit Selenium Grid system
''' visit Selenium Grid system '''
from time import sleep
from selenium import webdriver
# establish remote object
driver = webdriver.remote('http://127.0.0.1:4444/wd/hub')
# a Business ,b Business ,c Business , Using different driver Objects can perform different businesses
driver.get('http://www.baidu.com')
sleep(5)
driver.quit()
边栏推荐
- Polygon zkEVM——Hermez 2.0简介
- 6-21 vulnerability exploitation MySQL weak password cracking
- Multimodal unsupervised image to image translation
- Family relationship calculator wechat applet source code
- Source code and display of 18 classic programs in C language vs2019
- Youxuan software appoints Huang Zhijun as the general manager of the company
- PHP lucky draw system with background source code
- h. 264 code stream explanation
- Polygon zkevm - Introduction to HERMEZ 2.0
- 并发模式之异步回调Future模式
猜你喜欢

K210 - sound source location and sound recognition

架构师进阶,微服务设计与治理的 16 条常用原则

(job) C language: Simulation Implementation of ATOI and strncpy, strncat, strncmp

以科技传递温度,vivo亮相数字中国建设峰会

第八天笔记

DataGrip 如何导出和恢复整个数据库数据,使用单个 SQL 文件

Thirty years of MPEG audio coding

第六天笔记

新版海螺影视主题模板M3.1全解密版本多功能苹果CMSv10后台自适应主题开源全解密版

Multiple inheritance and derived class member identification
随机推荐
K210 - sound source location and sound recognition
NVIDIA-VPI(Vision Programming Interface)
第八天笔记
Pgzero飞机大战
Trample --- discretization + tree array + difference
12.书写规则-静态模式
Stm32f103xx firmware function library-1
Small program source code for campus stray cat information recording and sharing / wechat cloud development medium big cat spectrum small program source code
【luogu P8352】小 N 的独立集(DP套DP)(性质)
图书管理系统
DHCP protocol detailed analysis
每周推荐短视频:如何让产品开发更加有效?
冰冰学习笔记:运算符重载---日期类的实现
QT compilation of IOT management platform 48 characteristic function design
PHP幸运抽奖系统带后台源码
Ffmpeg+sdl+qt is a simple video player
【无标题】
Memories of many years ago
Asemi rectifier bridge s25vb100, s25vb100 parameters, s25vb100 application
Day 5 experiment