Robotframework集成jenkins执行用例
Robotframework+jenkins配置
假設我們完成了一個模塊的用例設計,可是想晚上9點或凌晨運行,這時候該怎么實現呢?jenkins可以很好解決我們的疑難。
Jenkins安裝
這里簡單說下安裝,建議下載war包在tomacat中啟動或是直接在cmd中使用命令啟動jenkins(如果已經使用.msi安裝成windows服務了,下面會提到解決方法)。
配置
- 基本信息
在jenkins主頁中,新建 一個自由風格的項目,配置項目的名稱等基本信息如圖
?
因為這里沒有使用svn或git,文件直接保存在本地,所以沒有使用源碼管理,如果使用了源碼管理的可以根據實際情況配置源碼管理的配置信息。
- 構建觸發器
這里選擇使用Build periodically,進行定時構建,如圖
?
這里設置的是每天凌晨2點進行構建。
這里注意選擇的是build Periodically,選擇的是定時構建,不管代碼是否有更新;而另外一個構建方式Poll SCM,則是svn或git代碼有更新才會再制定的時間內進行構建
- 構建
接下來就是構建過程,這里是windows環境,所以使用的是Execute Windows batch command
使用命令執行要運行的用例如pybot.bat -d F:\outputdir F:\test\cswx\,這里-d是將執行結果保存在F:\outputdir目錄下,而F:\test\cswx\是需要執行用例的文件夾
?
- 構建后操作
這里提前需要安裝一個插件Public Robot Framework test result
?
如果構建的時候,使用的是默認的輸出目錄,那么這里的Directory of Robot output 默認為空。
- 添加接收郵箱
?
- 執行結果
構建之后查看結果如圖
?
?
?
?
?
以Android為例,iOS的啟動方式和控件查找略作改動即可。
resource.txt
*** Settings ***
Library???????? AppiumLibrary
?
*** Variables ***
{REMOTE_URL}? http://0.0.0.0:4800/wd/hub
?
*** Keywords ***
TestStart
??? [Documentation]? start application
??? Open Application? {REMOTE_URL}? platformName=Android? platformVersion=5.0.0? deviceName=192.168.56.101:5555? app={CURDIR}/snowball-dev.apk? automationName=appium? appPackage=com.xxx.xxxx? appWaitActivity=.view.UnloginHomePageActivity
?
mobile login
??? [Arguments]? {user_name}? {password}
??? Input Text? id=com.xxx.xxxx:id/phone_number_input? {user_name}
??? Input Text? id=com.xxx.xxxx:id/password_input? {password}
??? Click Element? id=com.xxx.xxxx:id/login
??? Capture Page Screenshot
?
use with login
??? Click Element? identifier=登錄
??? Wait Until Page Contains? 注冊
test.tx
*** Settings ***
Resource? login_resource.txt
Test Setup???? TestStart
Test Teardown? Close Application
?
*** Test Cases ***
手機號登錄/退出登錄成功
??? [Documentation]? 手機號登錄成功,再退出登錄
??? [Tags]? login
??? use with login
? ??mobile login? xxxxxx? xxxxx
??? Page Should Contain Element? identifier=xxx
??? Page Should Contain Element? identifier=xxx
??? logout
?
匿名使用再用手機號登錄
??? [Documentation]? 匿名使用后,再用手機號登錄
??? [Tags]? login
??? use without login
??? Page Should Contain Element? identifier=xxx
??? Page Should Contain Element? identifier=xxx
??? Click Element? identifier=xxxx
??? Click Element? identifier=xxxx
??? Click Element? identifier=xxxxx
??? mobile login? xxxx? xxxx
??? Click Element? identifier=xxxxx
??? Page Should Contain Text? text=xxxx
??? logout
jenkins郵件報告
使用email-ext plugin,可以將robotframework的結果集成到郵件報告里。
jelly郵件模板如下:
<!-- Robotframework TEMPLATE -->
? <j:set var="robotAction" value="${it.getAction('hudson.plugins.robot.RobotBuildAction')}" />
? <j:if test="${robotAction!=null}">
??? <div class="content">
????? <j:set var="robotResult" value="${robotAction.result}" />
????? <j:if test="${robotResult!=null}">
??????? <a href="rooturlrooturl{build.url}robot">
????????? <h1>UI Test Results</h1>
??????? </a>
??????? <img src="${rooturl}static/72341926/plugin/robot/robot.png" />
??????? <a href="rooturlrooturl{build.url}robot/report/report.html#totals?all"><tt>Robot Test Results</tt></a>
??????? <table class="border">
????????? <tr>
??????????? <th class="border">Name</th>
??????????? <th class="border">Suite</th>
??????????? <th class="border">Status</th>
??????????? <th class="border">Duration</th>
????????? </tr>
????????? <j:forEach var="suiteResult" items="${robotResult.getAllSuites()}">
??????????? <j:forEach var="caseResult" items="${suiteResult.getCaseResults()}">
????????????? <tr>
??????????????? <td class="border">${caseResult.getName()}</td>
??????????????? <td class="border">${suiteResult.getName()}</td>
??????????????? <j:if test="${caseResult.isPassed()}">
????????????????? <td class="border test_passed">Pass</td>
??????????????? </j:if>
??????????????? <j:if test="${!caseResult.isPassed()}">
????????????????? <td class="border test_failed">Fail</td>
??????????????? </j:if>
??????????????? <td class="border test_duration">${caseResult.getDuration()/1000}s</td>
????????????? </tr>
??????????? </j:forEach>
????????? </j:forEach>
??????? </table>
????? </j:if>
??? </div>
? </j:if>
展示結果如圖
?
轉載于:https://www.cnblogs.com/tester-l/p/8199218.html
總結
以上是生活随笔為你收集整理的Robotframework集成jenkins执行用例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringMVC @RequestBo
- 下一篇: 粘性控件,滑动停留StickLayout