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_conf.get_log('./conf/log.ini')
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.splitext(file)[0]
if file_type == '.xlsx':
if 'old' not in file_name:
case_path = path+file
cases.append(case_path)
else:
log.error('文件类型错误:{}'.format(file))
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 = ['狐狸','网恋','寒灯']
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.启动线程
for t in th:
t.start()
t.join()
4.访问Selenium Grid体系
'''
访问Selenium Grid体系
'''
from time import sleep
from selenium import webdriver
driver = webdriver.remote('http://127.0.0.1:4444/wd/hub')
driver.get('http://www.baidu.com')
sleep(5)
driver.quit()