Robot Framework 實現並行測試
Robot Framework 實現並行測試需要使用第三方庫Pabot,該庫可以將一個執行分成多個以節省測試執行時間。
Github:
安裝:
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 seconds2020-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
作者:Leozhanggg
出處:https://www.cnblogs.com/leozhanggg/p/14076284.html
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段宣告,且在文章頁面明顯位置給出原文連線,否則保留追究法律責任的權利。