Robotframework集成jenkins执行用例
Robotframework+jenkins配置
假設(shè)我們完成了一個(gè)模塊的用例設(shè)計(jì),可是想晚上9點(diǎn)或凌晨運(yùn)行,這時(shí)候該怎么實(shí)現(xiàn)呢?jenkins可以很好解決我們的疑難。
Jenkins安裝
這里簡單說下安裝,建議下載war包在tomacat中啟動(dòng)或是直接在cmd中使用命令啟動(dòng)jenkins(如果已經(jīng)使用.msi安裝成windows服務(wù)了,下面會(huì)提到解決方法)。
配置
- 基本信息
在jenkins主頁中,新建 一個(gè)自由風(fēng)格的項(xiàng)目,配置項(xiàng)目的名稱等基本信息如圖
?
因?yàn)檫@里沒有使用svn或git,文件直接保存在本地,所以沒有使用源碼管理,如果使用了源碼管理的可以根據(jù)實(shí)際情況配置源碼管理的配置信息。
- 構(gòu)建觸發(fā)器
這里選擇使用Build periodically,進(jìn)行定時(shí)構(gòu)建,如圖
?
這里設(shè)置的是每天凌晨2點(diǎn)進(jìn)行構(gòu)建。
這里注意選擇的是build Periodically,選擇的是定時(shí)構(gòu)建,不管代碼是否有更新;而另外一個(gè)構(gòu)建方式Poll SCM,則是svn或git代碼有更新才會(huì)再制定的時(shí)間內(nèi)進(jìn)行構(gòu)建
- 構(gòu)建
接下來就是構(gòu)建過程,這里是windows環(huán)境,所以使用的是Execute Windows batch command
使用命令執(zhí)行要運(yùn)行的用例如pybot.bat -d F:\outputdir F:\test\cswx\,這里-d是將執(zhí)行結(jié)果保存在F:\outputdir目錄下,而F:\test\cswx\是需要執(zhí)行用例的文件夾
?
- 構(gòu)建后操作
這里提前需要安裝一個(gè)插件Public Robot Framework test result
?
如果構(gòu)建的時(shí)候,使用的是默認(rèn)的輸出目錄,那么這里的Directory of Robot output 默認(rèn)為空。
- 添加接收郵箱
?
- 執(zhí)行結(jié)果
構(gòu)建之后查看結(jié)果如圖
?
?
?
?
?
以Android為例,iOS的啟動(dòng)方式和控件查找略作改動(dòng)即可。
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 ***
手機(jī)號登錄/退出登錄成功
??? [Documentation]? 手機(jī)號登錄成功,再退出登錄
??? [Tags]? login
??? use with login
? ??mobile login? xxxxxx? xxxxx
??? Page Should Contain Element? identifier=xxx
??? Page Should Contain Element? identifier=xxx
??? logout
?
匿名使用再用手機(jī)號登錄
??? [Documentation]? 匿名使用后,再用手機(jī)號登錄
??? [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郵件報(bào)告
使用email-ext plugin,可以將robotframework的結(jié)果集成到郵件報(bào)告里。
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>
展示結(jié)果如圖
?
轉(zhuǎn)載于:https://www.cnblogs.com/tester-l/p/8199218.html
總結(jié)
以上是生活随笔為你收集整理的Robotframework集成jenkins执行用例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SpringMVC @RequestBo
- 下一篇: 粘性控件,滑动停留StickLayout