robotframework 多进程 多线程

来源:互联网 发布:爱奇艺网络机顶盒版 编辑:程序博客网 时间:2024/05/17 04:38

robotframework 多进程 多线程

一直想找个多进程执行rf case 的第三方库,都没找到。
这两天又上网找了找,从网上的两个回答里找到了灵感。
我们可以间接的达到这个目的。

参考答案:
使用Process Library 多进程,后台执行
https://stackoverflow.com/questions/25427506/robotframework-threads
http://robotframework.org/robotframework/latest/libraries/Process.html
RF 合并测试结果的工具 Rebot:
https://stackoverflow.com/questions/16519277/aggregate-the-reports-from-different-robot-testsuites

下面给出使用Process 的例子:
导入Process 库
这里写图片描述
使用多进程执行:
Start Process 代表后台执行,不用等待进程执行完成
Run Process 执行线程,需要等待进程执行完成
这里写图片描述

分析:
Start Process 执行的命令是,执行python 代码,等待100s
但是我们执行Process 的时候,并没有等待这个进程执行完
然后就执行了 Run Process 的进程,这个进程会打开计算器程序。
需要我们手动关闭计算机程序,Run Process 这个进程才会结束。

发散思维:
既然我们可以使用 Start Process 后台执行命令,那我们可以多起
几个后台进程,这个就相当于多进程执行了。
例如:

Start Process pybot -s suite1 -o xx/output1.xml D:/xxx/projectStart Process pybot -s suite2 -o xx/output2.xml D:/xxx/projectStart Process pybot -s suite3 -o xx/output3.xml D:/xxx/projectStart Process pybot -s suite4 -o xx/output4.xml D:/xxx/project

这里就相当于后台执行project 的4个测试套件,然后我们会得到四个output?.xml 输出文件
OK, 这个时候我们合并输出结果的命令就可以派上用场了
这个命令还有其他参数,详细使用命令可以在cmd窗口使用命令查看:
rebot –help

python -m robot.rebot outputs/*.xml -r report/merge_report.html

最后得到的merge_report.html 就是我们合并后的最终测试报告
理论上可行,但还是实践一下最好:
我们新建一个空文件夹
这里写图片描述

再看看我们的case:
一共有3个case, 我们利用 process 去多进程执行 另外两个case
并把两个进程生成的测试结果合并生成一个测试报告
这里写图片描述
图太长截不全,上代码:

start process   pybot.bat   -t  exec_script -o  D:/Document/outputs/opt1.xml    D:/Document/GitProject/auto-unix/unix.txt   alias=case1start process   pybot.bat   -t  test_remote -o  D:/Document/outputs/opt2.xml    D:/Document/GitProject/auto-unix/unix.txt   alias=case2wait for process    case1                       wait for process    case2                       Run Process python  -m  robot.rebot -d  D:/Document/outputs -R  D:/Document/outputs/*.xml

最后跑一下,看看我们的结果:
注意哦,里面加了两个进程的等待
我们要等所有进程结束,才能合并生成完整的测试报告
这里写图片描述

最后看一下我们的报告:
这里写图片描述
日志:
这里写图片描述

没毛病~
那么我们就可以实现多进程去并行执行case 了