python-selenium并发执行测试用例(方法一 各模块每一条并发执行)
总执行代码:
# coding=utf-8
import unittest,os,time
import HTMLTestRunner
import threading
import sys
sys.path.append('C:/Users/Dell/Desktop/CARE/program')#使用编辑器,要指定当前目录,不然无法执行第20行代码
def creatsuite():
casedir = []
list = os.listdir(os.path.dirname(os.getcwd()))#获取当前路径的上一级目录的所有文件夹,这里可以改成绝对路径(要搜索的文件路径)
for xx in list:
if "baidu" in xx:
casedir.append(xx)
suite =[]
for n in casedir:
testunit = unittest.TestSuite()
unittest.defaultTestLoader._top_level_dir = None
#(unittest.defaultTestLoader(): defaultTestLoader()类,通过该类下面的discover()方法可自动更具测试目录start_dir匹配查找测试用例文件(test*.py),
并将查找到的测试用例组装到测试套件,因此可以直接通过run()方法执行discover)
discover = unittest.defaultTestLoader.discover(str(n),pattern='tet_*.py',top_level_dir=None)
for test_suite in discover:
for test_case in test_suite:
testunit.addTests(test_case)
suite.append(testunit)
return suite, casedir
def runcase(suite,casedir):
lastPath = os.path.dirname(os.getcwd())#获取当前路径的上一级
resultDir = lastPath+"\\run\\report\\" #报告存放路径
now = time.strftime("%Y-%m-%d %H.%M.%S",time.localtime())
filename = resultDir + now +" result.html"
fp = file(filename, 'wb')
proclist=[]
s=0
for i in suite:
runner = HTMLTestRunner.HTMLTestRunner(stream=fp,title=str(casedir[s])+u'测试报告',description=u'用例执行情况:')
proc = threading.Thread(target=runner.run,args=(i,))
proclist.append(proc)
s=s+1
for proc in proclist:
proc.start()
for proc in proclist:
proc.join()
fp.close()
if __name__ == "__main__":
runtmp=creatsuite()
runcase(runtmp[0],runtmp[1])



描述: 使用这个总执行文件,可以多进程 同时开始每个模块的测试用例(每个模块同时一条接着一条执行)

python-selenium并发执行测试用例(方法一 各模块每一条并发执行)的更多相关文章
- Python Nose框架编写测试用例方法
1. 关于Nose nose项目是于2005年发布的,也就是 py.test改名后的一年.它是由 Jason Pellerin 编写的,支持与 py.test 相同的测试习惯做法,但是这个包更容易安装 ...
- Python+Selenium定位元素的方法
Python+Selenium有以下八种定位元素的方法: 1. find_element_by_id() eg: find_element_by_id("kw") 2. find_ ...
- Python selenium 三种等待方法
1. 强制等待 sleep(xx) 是最简单粗暴的一种办法,不管你浏览器是否加载完了,程序都得等待3秒,3秒一到,继续执行下面的代码,作为调试很有用,不建议总用这种等待方式,严重影响程序执行速度. 代 ...
- 第8.5节 Python类中的__new__方法和构造方法__init__关系深入剖析:执行顺序及参数关系案例详解
上节介绍了__new__()方法这个比构造方法还重要的方法的语法,本节通过案例来详细剖析__new__()方法的细节以及它与构造方法之间的关系. 一. 案例说明 本节以圆Cir类为例来说明,为了 ...
- 5 Python+Selenium的元素定位方法(xpath)
[环境] Python3.6+selenium3.0.2+FireFox50+win7 [定位方法] 1.方法:find_element_by_xpath('') 说明:xpath定位方法有相对路径和 ...
- 4 Python+Selenium的元素定位方法(link/partial link)
[环境] Python3.6+selenium3.0.2+IE11+win7 [定位方法] 1.link/partial link定位方法:定位的元素为文字链接且链接很长时 方法:find_eleme ...
- 3 Python+Selenium的元素定位方法(id、class name、name、tag name)
[环境] Python3.6+selenium3.0.2+IE11+Win7 [定位方法] 1.通过ID定位 方法:find_element_by_id('xx') 2.通过name定位 方法:fin ...
- 6 Python+Selenium的元素定位方法(CSS)
[环境] python3.6+selenium3.0.2+Firefox50.0+win7 [定位方法] 1.方法:find_element_by_css_selector('xx') CSS的语法比 ...
- Python——cmd调用(os.system阻塞处理)(多条命令执行)
os.system(返回值为0,1,2)方法 0:成功 1:失败 2:错误 os.system默认阻塞当前程序执行,在cmd命令前加入start可不阻塞当前程序执行. 例如: import os os ...
随机推荐
- 2017.4.7 Sprng MVC工作流程描述图
图一: 图二: Spring工作流程描述 1. 用户向服务器发送请求,请求被Spring 前端控制Servelt DispatcherServlet捕获: 2. Dispa ...
- hdu1907 John 博弈
Little John is playing very funny game with his younger brother. There is one big box filled with M& ...
- java gaoji 算法
import java.util.Scanner; public class Main{ public static int[] Test(int[] a){ int [] ...
- <jsp:include>动作元素,附:最易出错的一点
先定义一个date.jsp,再定义一个main.jsp.用<jsp:include plage = "相对url地址" flush = "true"> ...
- 使用nexus 管理pip 私有包
nexus 已经支持了对于python pip 包的管理(支持group,host,proxy) 这个是一个简单的使用docker 运行的demo,同时集成了s3 存储,以及 一个为了测试简单的自定义 ...
- skipper filter 扩展开发
skipper 的扩展包含filter类型的,以及Predicates ,当然script(lua)脚本也是 这次主要是filter类型的开发 filter 接口约定 格式 filter 至少需要包含 ...
- mysql之 CentOS系统针对mysql参数优化
内核相关参数(/etc/sysctl.conf) 以下参数可以直接放到sysctl.conf文件的末尾: net.core.somaxconn = 65535 net.core.netdev_max ...
- malloc的使用、用malloc动态分配内存以适应用户的需求的源代码实例
int len; ; printf("please enter the size that you want: "); scanf("%d", &len ...
- 不同eclipse版本的git库使用
在eclipse 4.4.2 -win32版本下编译好后上传版本: 1.在eclipse 4.4.0 -win64 版本下,编译报 缺少 sevlet.http...库,解决方法 project - ...
- 在Ubuntu上使用noip动态域名的方法(ddns)
首先,注册一个noip.com的帐号. 注册的步骤见这篇教程:http://www.cnblogs.com/infopi/p/3991407.html 建立目录 第1行进入当前用户的home目录 第2 ...