Robot Framework 实现并行测试需要使用第三方库 Pabot,该库可以将一个执行分成多个以节省测试执行时间。
安装:
pip install -U robotframework-pabot
命令行选项:
pabot [--verbose|--testlevelsplit|--command .. --end-command|
--processes num|--pabotlib|--pabotlibhost host|--pabotlibport port|
--artifacts extensions|--artifactsinsubfolders|
--resourcefile file|--argumentfile[num] file|--suitesfrom file]
[robot options] [path ...]
注意:支持所有Robot Framework命令行选项以及以下选项(这些选项必须在普通RF选项之前)
–verbose
显示更多执行输出。
E:\__SVN__\Auto_Test_Jm\TestDemo>pabot --verbose --outputdir results .
Storing .pabotsuitenames file
Suite names resolved in 0.02200007438659668 seconds
2020-12-02 20:34:29.990031 [PID:7276] [1] [ID:0] EXECUTING PARALLEL TestDemo.测试套件1 with command:
robot --suite TestDemo.测试套件1 --variable CALLER_ID:97f37ea973934326af91b30e71c3043d --variable PABOTLIBURI:127.0.0.1:8270 --variable PABOTEXECUTIONPOOLID:1 --variable
PABOTISLASTEXECUTIONINPOOL:0 --variable PABOTNUMBEROFPROCESSES:8 --variable PABOTQUEUEINDEX:0 --variable PABOTLASTLEVEL:TestDemo.测试套件1 --outputdir "results\pabot_resu
lts\0" --log NONE --report NONE --xunit NONE --consolecolors off --consolemarkers off .
2020-12-02 20:34:29.990031 [PID:7388] [0] [ID:3] EXECUTING PARALLEL TestDemo.测试套件4 with command:
robot --suite TestDemo.测试套件4 --variable CALLER_ID:a26742ba4b664aac99f072732a54ff46 --variable PABOTLIBURI:127.0.0.1:8270 --variable PABOTEXECUTIONPOOLID:0 --variable
PABOTISLASTEXECUTIONINPOOL:1 --variable PABOTNUMBEROFPROCESSES:8 --variable PABOTQUEUEINDEX:3 --variable PABOTLASTLEVEL: --outputdir "results\pabot_results\3" --log NONE
--report NONE --xunit NONE --consolecolors off --consolemarkers off .
2020-12-02 20:34:29.990031 [PID:7740] [2] [ID:1] EXECUTING PARALLEL TestDemo.测试套件2 with command:
robot --suite TestDemo.测试套件2 --variable CALLER_ID:34737a8f32104668bb7a5217d2afd14b --variable PABOTLIBURI:127.0.0.1:8270 --variable PABOTEXECUTIONPOOLID:2 --variable
PABOTISLASTEXECUTIONINPOOL:0 --variable PABOTNUMBEROFPROCESSES:8 --variable PABOTQUEUEINDEX:1 --variable PABOTLASTLEVEL:TestDemo.测试套件2 --outputdir "results\pabot_resu
lts\1" --log NONE --report NONE --xunit NONE --consolecolors off --consolemarkers off .
2020-12-02 20:34:29.991031 [PID:7748] [3] [ID:2] EXECUTING PARALLEL TestDemo.测试套件3 with command:
robot --suite TestDemo.测试套件3 --variable CALLER_ID:ce06bc1b57a94184a0e0685777bddd23 --variable PABOTLIBURI:127.0.0.1:8270 --variable PABOTEXECUTIONPOOLID:3 --variable
PABOTISLASTEXECUTIONINPOOL:0 --variable PABOTNUMBEROFPROCESSES:8 --variable PABOTQUEUEINDEX:2 --variable PABOTLASTLEVEL:TestDemo.测试套件3 --outputdir "results\pabot_resu
lts\2" --log NONE --report NONE --xunit NONE --consolecolors off --consolemarkers off .
2020-12-02 20:34:34.495031 [PID:7388] [0] [ID:3] PASSED TestDemo.测试套件4 in 4.5 seconds
==============================================================================
TestDemo
==============================================================================
TestDemo.测试套件4
==============================================================================
测试用例1 | PASS |
------------------------------------------------------------------------------
测试用例2 | PASS |
------------------------------------------------------------------------------
测试用例3 | PASS |
------------------------------------------------------------------------------
测试用例4 | PASS |
------------------------------------------------------------------------------
TestDemo.测试套件4 | PASS |
4 critical tests, 4 passed, 0 failed
4 tests total, 4 passed, 0 failed
==============================================================================
TestDemo | PASS |
4 critical tests, 4 passed, 0 failed
4 tests total, 4 passed, 0 failed
==============================================================================
Output: E:\__SVN__\Auto_Test_Jm\TestDemo\results\pabot_results\3\output.xml
2020-12-02 20:34:34.500031 [PID:7748] [3] [ID:2] PASSED TestDemo.测试套件3 in 4.5 seconds
...
2020-12-02 20:34:34.592031 [PID:7276] [1] [ID:0] PASSED TestDemo.测试套件1 in 4.6 seconds
....
2020-12-02 20:34:34.595031 [PID:7740] [2] [ID:1] PASSED TestDemo.测试套件2 in 4.6 seconds
...
16 critical tests, 16 passed, 0 failed
16 tests total, 16 passed, 0 failed
===================================================
Output: E:\__SVN__\Auto_Test_Jm\TestDemo\results\output.xml
Log: E:\__SVN__\Auto_Test_Jm\TestDemo\results\log.html
Report: E:\__SVN__\Auto_Test_Jm\TestDemo\results\report.html
Total testing: 18.20 seconds
Elapsed time: 4.78 seconds
–testlevelsplit
在测试用例级别而不是默认测试套件级别上拆分执行。
E:\__SVN__\Auto_Test_Jm\TestDemo>pabot --testlevelsplit .
Storing .pabotsuitenames file
2020-12-02 20:26:57.721031 [PID:8820] [0] [ID:2] EXECUTING TestDemo.测试套件1.测试用例3
2020-12-02 20:26:57.722031 [PID:7016] [1] [ID:6] EXECUTING TestDemo.测试套件2.测试用例3
2020-12-02 20:26:57.722031 [PID:6856] [3] [ID:5] EXECUTING TestDemo.测试套件2.测试用例2
2020-12-02 20:26:57.723031 [PID:5872] [4] [ID:7] EXECUTING TestDemo.测试套件2.测试用例4
2020-12-02 20:26:57.723031 [PID:7600] [2] [ID:1] EXECUTING TestDemo.测试套件1.测试用例2
2020-12-02 20:26:57.723031 [PID:9144] [6] [ID:4] EXECUTING TestDemo.测试套件2.测试用例1
2020-12-02 20:26:57.723031 [PID:5776] [5] [ID:0] EXECUTING TestDemo.测试套件1.测试用例1
2020-12-02 20:26:57.723031 [PID:7228] [7] [ID:3] EXECUTING TestDemo.测试套件1.测试用例4
2020-12-02 20:26:59.331031 [PID:6856] [3] [ID:5] PASSED TestDemo.测试套件2.测试用例2 in 1.6 seconds
2020-12-02 20:26:59.333031 [PID:8404] [3] [ID:8] EXECUTING TestDemo.测试套件3.测试用例1
2020-12-02 20:26:59.347031 [PID:7016] [1] [ID:6] PASSED TestDemo.测试套件2.测试用例3 in 1.6 seconds
2020-12-02 20:26:59.349031 [PID:5572] [1] [ID:9] EXECUTING TestDemo.测试套件3.测试用例2
2020-12-02 20:26:59.357031 [PID:7228] [7] [ID:3] PASSED TestDemo.测试套件1.测试用例4 in 1.6 seconds
2020-12-02 20:26:59.358031 [PID:9144] [6] [ID:4] PASSED TestDemo.测试套件2.测试用例1 in 1.6 seconds
2020-12-02 20:26:59.359031 [PID:8520] [7] [ID:10] EXECUTING TestDemo.测试套件3.测试用例3
2020-12-02 20:26:59.360031 [PID:7996] [6] [ID:11] EXECUTING TestDemo.测试套件3.测试用例4
2020-12-02 20:26:59.369031 [PID:5776] [5] [ID:0] PASSED TestDemo.测试套件1.测试用例1 in 1.6 seconds
2020-12-02 20:26:59.371031 [PID:7876] [5] [ID:12] EXECUTING TestDemo.测试套件4.测试用例1
2020-12-02 20:26:59.438031 [PID:8820] [0] [ID:2] PASSED TestDemo.测试套件1.测试用例3 in 1.7 seconds
2020-12-02 20:26:59.438031 [PID:7600] [2] [ID:1] PASSED TestDemo.测试套件1.测试用例2 in 1.7 seconds
2020-12-02 20:26:59.440031 [PID:1304] [2] [ID:14] EXECUTING TestDemo.测试套件4.测试用例3
2020-12-02 20:26:59.441031 [PID:6980] [0] [ID:13] EXECUTING TestDemo.测试套件4.测试用例2
2020-12-02 20:26:59.447031 [PID:5872] [4] [ID:7] PASSED TestDemo.测试套件2.测试用例4 in 1.7 seconds
2020-12-02 20:26:59.448031 [PID:4080] [4] [ID:15] EXECUTING TestDemo.测试套件4.测试用例4
2020-12-02 20:27:00.976031 [PID:7996] [6] [ID:11] PASSED TestDemo.测试套件3.测试用例4 in 1.6 seconds
2020-12-02 20:27:00.987031 [PID:8520] [7] [ID:10] PASSED TestDemo.测试套件3.测试用例3 in 1.6 seconds
2020-12-02 20:27:01.038031 [PID:8404] [3] [ID:8] PASSED TestDemo.测试套件3.测试用例1 in 1.7 seconds
2020-12-02 20:27:01.046031 [PID:6980] [0] [ID:13] PASSED TestDemo.测试套件4.测试用例2 in 1.6 seconds
2020-12-02 20:27:01.046031 [PID:1304] [2] [ID:14] PASSED TestDemo.测试套件4.测试用例3 in 1.6 seconds
2020-12-02 20:27:01.070031 [PID:5572] [1] [ID:9] PASSED TestDemo.测试套件3.测试用例2 in 1.7 seconds
2020-12-02 20:27:01.073031 [PID:4080] [4] [ID:15] PASSED TestDemo.测试套件4.测试用例4 in 1.6 seconds
2020-12-02 20:27:01.076031 [PID:7876] [5] [ID:12] PASSED TestDemo.测试套件4.测试用例1 in 1.7 seconds
16 critical tests, 16 passed, 0 failed
16 tests total, 16 passed, 0 failed
===================================================
Output: E:\__SVN__\Auto_Test_Jm\TestDemo\output.xml
Log: E:\__SVN__\Auto_Test_Jm\TestDemo\log.html
Report: E:\__SVN__\Auto_Test_Jm\TestDemo\report.html
Total testing: 26.20 seconds
Elapsed time: 3.53 seconds
–processes [进程数]
要使用多少个并行执行程序(默认最大值为2和cpu数)
E:\__SVN__\Auto_Test_Jm\TestDemo>pabot .
Storing .pabotsuitenames file
2020-12-02 20:21:35.692031 [PID:8376] [2] [ID:2] EXECUTING TestDemo.测试套件3
2020-12-02 20:21:35.692031 [PID:7848] [0] [ID:1] EXECUTING TestDemo.测试套件2
2020-12-02 20:21:35.692031 [PID:7216] [3] [ID:0] EXECUTING TestDemo.测试套件1
2020-12-02 20:21:35.692031 [PID:8980] [1] [ID:3] EXECUTING TestDemo.测试套件4
2020-12-02 20:21:40.193031 [PID:8376] [2] [ID:2] PASSED TestDemo.测试套件3 in 4.5 seconds
2020-12-02 20:21:40.194031 [PID:7848] [0] [ID:1] PASSED TestDemo.测试套件2 in 4.5 seconds
2020-12-02 20:21:40.196031 [PID:7216] [3] [ID:0] PASSED TestDemo.测试套件1 in 4.5 seconds
2020-12-02 20:21:40.200031 [PID:8980] [1] [ID:3] PASSED TestDemo.测试套件4 in 4.5 seconds
16 critical tests, 16 passed, 0 failed
16 tests total, 16 passed, 0 failed
===================================================
Output: E:\__SVN__\Auto_Test_Jm\TestDemo\output.xml
Log: E:\__SVN__\Auto_Test_Jm\TestDemo\log.html
Report: E:\__SVN__\Auto_Test_Jm\TestDemo\report.html
Total testing: 18.0 seconds
Elapsed time: 4.71 seconds
E:\__SVN__\Auto_Test_Jm\TestDemo>pabot --processes 1 .
Storing .pabotsuitenames file
2020-12-02 20:21:58.713031 [PID:5080] [0] [ID:0] EXECUTING TestDemo.测试套件1
2020-12-02 20:22:03.215031 [PID:5080] [0] [ID:0] PASSED TestDemo.测试套件1 in 4.5 seconds
2020-12-02 20:22:03.218031 [PID:6832] [0] [ID:1] EXECUTING TestDemo.测试套件2
2020-12-02 20:22:07.724031 [PID:6832] [0] [ID:1] PASSED TestDemo.测试套件2 in 4.5 seconds
2020-12-02 20:22:07.725031 [PID:7832] [0] [ID:2] EXECUTING TestDemo.测试套件3
2020-12-02 20:22:12.227031 [PID:7832] [0] [ID:2] PASSED TestDemo.测试套件3 in 4.5 seconds
2020-12-02 20:22:12.229031 [PID:8336] [0] [ID:3] EXECUTING TestDemo.测试套件4
2020-12-02 20:22:16.732031 [PID:8336] [0] [ID:3] PASSED TestDemo.测试套件4 in 4.5 seconds
16 critical tests, 16 passed, 0 failed
16 tests total, 16 passed, 0 failed
===================================================
Output: E:\__SVN__\Auto_Test_Jm\TestDemo\output.xml
Log: E:\__SVN__\Auto_Test_Jm\TestDemo\log.html
Report: E:\__SVN__\Auto_Test_Jm\TestDemo\report.html
Total testing: 18.0 seconds
Elapsed time: 18.21 seconds
E:\__SVN__\Auto_Test_Jm\TestDemo>pabot --processes 2 .
Storing .pabotsuitenames file
2020-12-02 20:22:20.949031 [PID:7740] [0] [ID:0] EXECUTING TestDemo.测试套件1
2020-12-02 20:22:20.949031 [PID:7276] [1] [ID:1] EXECUTING TestDemo.测试套件2
2020-12-02 20:22:25.451031 [PID:7740] [0] [ID:0] PASSED TestDemo.测试套件1 in 4.5 seconds
2020-12-02 20:22:25.452031 [PID:7276] [1] [ID:1] PASSED TestDemo.测试套件2 in 4.5 seconds
2020-12-02 20:22:25.454031 [PID:8016] [0] [ID:2] EXECUTING TestDemo.测试套件3
2020-12-02 20:22:25.455031 [PID:8592] [1] [ID:3] EXECUTING TestDemo.测试套件4
2020-12-02 20:22:29.960031 [PID:8016] [0] [ID:2] PASSED TestDemo.测试套件3 in 4.5 seconds
2020-12-02 20:22:29.968031 [PID:8592] [1] [ID:3] PASSED TestDemo.测试套件4 in 4.5 seconds
16 critical tests, 16 passed, 0 failed
16 tests total, 16 passed, 0 failed
===================================================
Output: E:\__SVN__\Auto_Test_Jm\TestDemo\output.xml
Log: E:\__SVN__\Auto_Test_Jm\TestDemo\log.html
Report: E:\__SVN__\Auto_Test_Jm\TestDemo\report.html
Total testing: 18.0 seconds
Elapsed time: 9.17 seconds
–pabotlib
启动PabotLib远程服务器。 这样可以在并行测试执行之间进行锁定和资源分配。
–pabotlibhost [主机名]
PabotLib远程服务器的主机名(默认为127.0.0.1)
如果与–pabotlib选项一起使用,将更改创建的远程服务器的主机侦听地址
如果在没有–pabotlib选项的情况下使用,将连接到给定主机中已运行的PabotLib远程服务器实例。
远程服务器也可以与pabot实例分开启动和执行:
–pabotlibport [端口]
PabotLib远程服务器的端口号(默认为8270)
–resourcefile [文件路径]
可以包含用于分发资源的共享变量的文件的指示符。
python -m pabot.PabotLib <path_to_resourcefile> <host> <port>
python -m pabot.PabotLib resource.txt 192.168.1.123 8271
pabot --pabotlibhost 192.168.1.123 --pabotlibport 8271 --processes 10 tests
pabot --pabotlib --pabotlibhost 192.168.1.111 --pabotlibport 8272 --processes 10 tests
–suitesfrom [文件路径]
从output.xml文件中读取套件,失败的套件将首先运行,运行时间较长的套件将在较短的套件之前执行。
–argumentfile[整数] [文件路径]
使用多个参数文件选项运行相同的套件。
--argumentfile1 arg1.txt --argumentfile2 arg2.txt
–command [开始执行Robot Framework的实际命令] --end-command
Robot Framework脚本适用于不直接使用pybot的情况
pabot --command java -jar robotframework.jar --end-command --include SMOKE tests
希望本文对你有所帮助~~如果对软件测试、接口测试、自动化测试、面试经验交流感兴趣可以加入我们。642830685,免费领取最新软件测试大厂面试资料和Python自动化、接口、框架搭建学习资料!技术大牛解惑答疑,同行一起交流。