testng+ant+jenkins持續集成UI自動化

1、環境搭建java

1. 安裝testNG插件到eclipse.eclipse

-) 選擇菜單 Help /Software updates / Find and Install.測試

-) 點擊add button而後在location中輸入http://beust.com/eclipse/ui

-) 肯定後會自動安裝testNG插件。spa

 

二.包的引入 WebDriver包:selenium-server-standalone.jar插件

    testng 包: testng-6.8.jarserver

    reportng包:reporting.jar,velocity-dep.jarxml

    ant包:ant-contrib.jarblog

3、新建一個testNG工程:(手動建立lib文件夾,須要把以上三個JAR包放在lib下面)ip

建立類和方法:

public class test {
  @Test(groups="init")
  public void f() {
  System.out.println("This is test f" );
  }
  @Test(groups="init")
  public void g() {
  System.out.println("This is test g" );
  }
  @Test(dependsOnGroups="init",groups="proccess")
  public void h() {
  System.out.println("This is test h " );
  }
  @Test(dependsOnGroups="init",groups="proccess")
  public void i() {
  System.out.println("This is test i" );
  }
}
testng.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="tests" thread-count="1">
  <test name="test">
  <parameter name = "driverType" value = "1"/>
  <classes>
  <!--測試類-->
      <class name="test"/>
      <class name="login"/>
    </classes>
  <groups>
  <run>
  <!--測試執行用例組合-->
  <include name="proccess"/>
  <include name="login"/>
  </run>
  </groups>
  </test> <!-- Test -->
</suite> <!-- Suite -->

ant build.xml文件內容:

<project name="TestNGTest" default="test" basedir=".">
<!-- Define <testng> task -->
  <taskdef name="testng" classname="org.testng.TestNGAntTask">
    <classpath>
      <pathelement location="lib/testng-6.8.jar"/>
    </classpath>
  </taskdef>
   <property name="testdir" location="test" />
   <property name="srcdir" location="src" />
   <property name="libdir" location="lib" />
   <property name="full-compile" value="true" />
   <path id="classpath.base"/>
   <path id="classpath.test">
       <fileset dir="${libdir}">
         <include name="**/*.jar" />
      </fileset>
      <pathelement location="${testdir}" />
      <pathelement location="${srcdir}" />
      <path refid="classpath.base" />
   </path>
   <target name="clean" >
      <delete verbose="${full-compile}">
         <fileset dir="${testdir}" includes="**/*.class" />
      </delete>
   </target>
   <target name="compile" depends="clean">
      <javac srcdir="${srcdir}" destdir="${testdir}"
         verbose="${full-compile}">
         <classpath refid="classpath.test"/>
      </javac>
   </target>
   <target name="test" depends="compile">
<testng outputdir="${testdir}" classpathref="classpath.test">
      <xmlfileset dir="${srcdir}">
      <include name="suite.xml"/>
      </xmlfileset>
    </testng>
   </target>
</project>
 
 

JENKINS引入SVN下載工程包,編譯運行:

SVN配置:

![](http://images2015.cnblogs.com/blog/816853/201611/816853-20161104112845361-224894314.png)

ANT配置:

![](http://images2015.cnblogs.com/blog/816853/201611/816853-20161104112913033-1089837005.png)

報告輸出:

(JENKINS安裝TESTNG report 插件) jenkins console執行報告輸出,基本上到這一步就成功了。

![](http://images2015.cnblogs.com/blog/816853/201611/816853-20161104113451455-1967450719.png)

再看TESTNG插件生成的TESTNG報告:

![](http://images2015.cnblogs.com/blog/816853/201611/816853-20161104113218971-618336380.png)

相關文章
相關標籤/搜索