总执行代码:

# 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并发执行测试用例(方法一 各模块每一条并发执行)的更多相关文章

  1. Python Nose框架编写测试用例方法

    1. 关于Nose nose项目是于2005年发布的,也就是 py.test改名后的一年.它是由 Jason Pellerin 编写的,支持与 py.test 相同的测试习惯做法,但是这个包更容易安装 ...

  2. Python+Selenium定位元素的方法

    Python+Selenium有以下八种定位元素的方法: 1. find_element_by_id() eg: find_element_by_id("kw") 2. find_ ...

  3. Python selenium 三种等待方法

    1. 强制等待 sleep(xx) 是最简单粗暴的一种办法,不管你浏览器是否加载完了,程序都得等待3秒,3秒一到,继续执行下面的代码,作为调试很有用,不建议总用这种等待方式,严重影响程序执行速度. 代 ...

  4. 第8.5节 Python类中的__new__方法和构造方法__init__关系深入剖析:执行顺序及参数关系案例详解

    上节介绍了__new__()方法这个比构造方法还重要的方法的语法,本节通过案例来详细剖析__new__()方法的细节以及它与构造方法之间的关系. 一.    案例说明 本节以圆Cir类为例来说明,为了 ...

  5. 5 Python+Selenium的元素定位方法(xpath)

    [环境] Python3.6+selenium3.0.2+FireFox50+win7 [定位方法] 1.方法:find_element_by_xpath('') 说明:xpath定位方法有相对路径和 ...

  6. 4 Python+Selenium的元素定位方法(link/partial link)

    [环境] Python3.6+selenium3.0.2+IE11+win7 [定位方法] 1.link/partial link定位方法:定位的元素为文字链接且链接很长时 方法:find_eleme ...

  7. 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 ...

  8. 6 Python+Selenium的元素定位方法(CSS)

    [环境] python3.6+selenium3.0.2+Firefox50.0+win7 [定位方法] 1.方法:find_element_by_css_selector('xx') CSS的语法比 ...

  9. Python——cmd调用(os.system阻塞处理)(多条命令执行)

    os.system(返回值为0,1,2)方法 0:成功 1:失败 2:错误 os.system默认阻塞当前程序执行,在cmd命令前加入start可不阻塞当前程序执行. 例如: import os os ...

随机推荐

  1. js 关于本地文件的处理

    https://developer.mozilla.org/zh-CN/docs/Web/API/File/Using_files_from_web_applications

  2. BZOJ 2002:Bounce 弹飞绵羊(分块)

    2002: [Hnoi2010]Bounce 弹飞绵羊 Time Limit: 10 Sec  Memory Limit: 259 MB Submit: 14944  Solved: 7598 [Su ...

  3. myeclipse从svn导入文件报错:

    Access restriction:The type JPEGCodec is not accessible due to restriction on required library C:\Pr ...

  4. sailsjs learning note

    menu list: custom controller custom 模块使用 custom model custom middleware custom service ? 路由与对应的contr ...

  5. 经过强制类型转换以后,变量a, b的值分别为( )short a = 128; byte b = (byte) a;

    1.Java中用补码形式表示 2.第一位正负位,1表示负,0表示正. 3.原码:一个数的二进制表示.                  3的原码00000011   -3的 原码 10000011 4 ...

  6. PyMongo 常见问题

    PyMongo是线程安全的吗PyMongo是线程安全的,并且为多线程应用提供了内置的连接池 PyMongo是进程安全的吗PyMongo不是进程安全的,如果你在fork()中使用MongoClient实 ...

  7. Python——psutil的使用(获取系统性能信息)

    >>> import psutil #导入psutil >>> a=psutil.virtual_memory() >>> a.total #总虚 ...

  8. day5 python学习

    本日主要讲了列表的一些操作 1.列表的增 ret=['wang','taibai','alxe','ritian'] ret.append("wusir") print(ret) ...

  9. lch 儿童围棋课堂 启蒙篇 (李昌镐 著)

    第1章 了解围棋 第2章 无气不活 棋子的"气"第3章 有目数才能赢空第4章 常用术语第5章 吃子第6章 死活:眼第7章 死活:典型棋形第8章 布局:术语篇 第1章 了解围棋 (已 ...

  10. Spring Cloud 与 Dubbo、Spring Cloud 与 Docker、Spring Cloud 与 Kubernetes 比较

    出处:http://dockone.io/article/4142