SeleniumPython多线程

Posted 素人渔芙2017

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SeleniumPython多线程相关的知识,希望对你有一定的参考价值。

 # all_tests_pro.py

 

import unittest,time,os,multiprocessing
import HTMLTestRunner

#查找多有含有thread的文件,文件夹
def EEEcreatsuit():
casedir = []
listaa = os.listdir(r\'C:\\Users\\wangxue1\\PycharmProjects\\selenium2TestOne\')
for xx in listaa:
if \'thread\' in listaa:
casedir.append(xx)
suite = []
for n in casedir:
testunit = unittest.TestSuite()
discover = unittest.defaultTestLoader.discover(n,pattern=\'test*.py\',top_level_dir=n)
print(discover)
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
suite.append(testunit)
print(\'================casedir:==========\',casedir)
print(\'+++++++++++++++++++++++++++++++++++\')
print(\'!!!!!suite:!!!!!\',suite)
return suite,casedir

#多进程运行测试套件,将结果写入HTMLTestRunner报告
def EEEEmultiRunCase(suite,casedir):
now = time.strftime(\'%Y-%m-%d-%H_%M_%S\',time.localtime(time.time()))
testreport = \'C:\\\\Users\\\\wangxue1\\\\PycharmProjects\\\\selenium2TestOne\\\\\' + now + \'\\\\\'
filename = testreport + \'report.html\'
if not os.path.exists(testreport):
os.makedirs(testreport)
else:
pass
proclist = []
s = 0
with open(filename,\'wb\') as report:
for i in suite:
runner = HTMLTestRunner.HTMLTestRunner(stream=report,title=u\'测试报告\',description=u\'用例执行情况:\')
proc = multiprocessing.Process(target=runner.run(i),args=(i,))
proclist.append(proc)
s = s + 1
for proc in proclist: proc.start()
for proc in proclist: proc.join()

runtmp = EEEcreatsuit()
EEEEmultiRunCase(runtmp[0],runtmp[1])





































以上是关于SeleniumPython多线程的主要内容,如果未能解决你的问题,请参考以下文章

多个用户访问同一段代码

线程学习知识点总结

多个请求是多线程吗

python小白学习记录 多线程爬取ts片段

多线程编程

多线程编程