• Jenkin+TestNG进行自动化测试执行


    1.登陆jenkins'后,主页面有一个jenkins管理选项,进入该模块,对插件,系统进行配置。(安装一个extend choice parameter插件)

    2.点击new item新建一个项目,选择自由风格的工程;

    3.extend choice parameter插件使用:

    在构建参数选项,选择extend choice parameter,输入name,比如selectcase,然后在value那里填入case的名字(和xml里或者脚本的名字一致),详细步骤可以参考这里:http://www.ibm.com/developerworks/cn/opensource/os-autotesting-jenkins-testing/

    4.在项目高级选项,配置你的项目路径;选择Use custom workspace, 在Directory栏填入项目工程路径, 如E:jenkinsworkspaceWebUIAutomation

    5.在版本控制选项,如果不用版本控制,选择none; (如果需要版本控制,可以选择svn, github等,然后填上你的版本库地址即可。)

    6.建一个run.bat文件,内容如下,并将该bat放入你本地工程的根目录

    java -cp E:jenkinsworkspaceWebUIAutomationin;E:jenkinsworkspaceWebUIAutomationlibs* org.testng.TestNG SCI_WebUI_BVT.xml

    7.在build选项那里,选择Execute windows batch commnad,填入run.bat

    保存。

    8. 或者通过ant来进行构建:在工程根目录建一个build.xml文件,内容如下。

    <project basedir="." default="regression" name="automation test">
        <!-- 变量设置  -->
        <property name="base.dir" value="/tmp/workspace/WebUIAutomation"/>
        <property name="testng.output.dir" value="${base.dir}/test-output"/>
        <property name="3rd.lib.dir" value="${base.dir}/libs"/>
        <property name="testng.file" value="SCI_WebUI_BVT.xml"/>
     
        <!-- testng任务  -->
        <taskdef resource="testngtasks" classpath="${3rd.lib.dir}/testng6.8.jar"/>
       
        <!-- 引用包设置  -->
        <path id="classes">
            <fileset dir="${3rd.lib.dir}">
            <include name="*.jar"/>
        </fileset>
            <pathelement location="${base.dir}/bin"/>
        </path>
     
        <!-- 每次构建清空之前构建文件  -->
        <target name="clean">
            <delete dir="${base.dir}/bin"/>
        </target>
    
        <!-- 编译文件  -->
         <target name="compile" depends="clean">
            <mkdir dir="${base.dir}/bin"/>
            <javac srcdir="${base.dir}/src" destdir="${base.dir}/bin" classpathref="classes" includeantruntime="off" debug="on" debuglevel="lines,vars,source"/>
        </target>
    
        <!-- 运行指定的xml  -->
        <target name="regression" depends="compile">
            <testng outputdir="${testng.output.dir}" classpathref="classes" delegateCommandSystemProperties="true">
                <xmlfileset dir="${base.dir}" includes="${testng.file}"/>
            </testng>
        </target>
    </project>

    建好文件后再jenkins的Build部分,选择execute shell或者invoke ant, 我这里选择的是invoke ant,然后在targets栏填入build.xml文件里的target name。

    之后回到项目页面,选择build,选择build参数(这里就可以看到前面创建的selectcase选择框了,选择你要执行的case),点击build就可以开始执行测试了。执行完成后在左边会显示所有build的记录,点开某一个记录,通过console output可以查看运行的log。

  • 相关阅读:
    牛客代码测试栈深度
    "Coding Interview Guide" -- 在行列都排好序的矩阵中找数
    "Coding Interview Guide" -- 括号字符串的有效性和最长有效长度
    "Coding Interview Guide" -- 将正方形矩阵顺时针转动90°
    "Coding Interview Guide" -- 按照左右半区的方式重新组合单链表
    "Coding Interview Guide" -- 先序、中序和后序数组两两结合重构二叉树
    "Coding Interview Guide" -- 只用位运算不用算术运算实现整数的加减乘除运算
    "Coding Interview Guide" -- 从N个数中等概率打印M个数
    "Coding Interview Guide" -- 判断字符数组中是否所有的字符都只出现过一次
    "Coding Interview Guide" -- 字符串的统计字符串
  • 原文地址:https://www.cnblogs.com/jingwei/p/4759915.html
Copyright © 2020-2023  润新知