1. 程式人生 > >RobotFramework 框架自動化執行策略

RobotFramework 框架自動化執行策略

自動化測試的執行策略

絕大多數整合/系統測試框架都支援失敗重執行的執行策略,從實現上來講,大概分為2類:

  1. 就地重執行失敗測試用例
  2. 執行完後,重新執行所有失敗的測試用例

比如TestNG框架支援上述兩種執行策略,pytest框架通過rerunfailures外掛支援第1種執行策略。RF的rerunfailed引數支援第2種執行策略

RF的rerunfailed執行策略

RF的rerunfailed可以從第一次跑過的結果中,篩選出失敗的用例重新執行,結合rebot的--merge功能,可以重新輸出output.xml,在Jenkins上展示出最後的測試結果。

\> pybot
-R --rerunfailed output Select failed tests from an earlier output file to be re-executed. Equivalent to selecting same tests individually using --test option.

\> rebot
-R --merge When combining results, merge outputs together instead of putting them under a new top level suite. Example: rebot --merge orig.xml rerun.xml

與Jenkins結合使用(windows)

  1. Jenkins中新增構建步驟:Execute Windows batch command
  2. rfrerun mysuite.robot

與Jenkins結合使用(Linux)

Linux下shell指令碼rfrerun

#!/bin/bash
rm -f output/output.xml
rm -f output/rerun.xml
rm -f output/first_run_log.html
rm -f output/second_run_log.html

echo
echo "#######################################"
echo "# First Run                                #"
echo "#######################################"
echo
pybot --outputdir output 
[email protected]
# Stop the script here if all the tests were OK if [ $? -eq 0 ]; then exit 0 fi # backup the first log file cp output/log.html output/first_run_log.html echo echo "#######################################" echo "# Rerun Failed Tests #" echo "#######################################" echo pybot --outputdir output --nostatusrc --rerunfailed output/output.xml --output rerun.xml
[email protected]
# backup the second log file cp output/log.html output/second_run_log.html echo echo "########################" echo "# Merge output files #" echo "########################" echo rebot --nostatusrc --outputdir output --output output.xml --merge output/output.xml output/rerun.xml # Robot Framework generates a new output.xml

使用方式:

  1. Jenkins中新增構建步驟:Execute Linux shell command
  2. rfrerun mysuite.robot

執行結果

在log日誌中,第一次失敗的用例會顯示2條message