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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值