WebDriver+testng+reportng+ant測試框架整合

一、環境搭建
1. 安裝testNG插件到eclipse.
-) 選擇菜單 Help /Software updates / Find and Install.
-) 點擊add button然後在location中輸入http://beust.com/eclipse/
-) 確定後會自動安裝testNG插件。

二.包的引入

WebDriver包:selenium-server-standalone.jar
    testng 包: testng.jar
    reportng包:reporting.jar,velocity-dep.jar

ant包:ant-contrib.jar

三.創建測試類

package com.test;
import org.testng.annotations.Test;
public class DependsTesting {
@Test(groups="init")
public void launchServer(){
System.out.println("init---1");
}
@Test(dependsOnGroups="init",groups="deploy-apps")
public void deploy(){
System.out.println("deploy-apps---2");
}
@Test(dependsOnGroups="init",groups="deploy-apps")
public void deployAuthenticationServer(){
System.out.println("deploy-apps----2");
}
@Test(dependsOnGroups="deploy-apps")
public void test1(){
System.out.println("test---3");
}
@Test(dependsOnGroups="deploy-apps")
public void test2(){
System.out.println("test---4");
}
}

三.配置testng.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" parallel="tests" thread-count="1">
  <test name="FF Test" preserve-order="false">
<parameter name = "driverType" value = "1"/>
<groups>
  <run>
  <include name="deploy-apps"/>
  </run>
  </groups>
  <classes>
<!--<class name="com.testcase.TaskTest"/> -->
<class name="com.test.DependsTesting"/>
    </classes> 
  </test>
</suite>

四.選擇testng.xml然後run as TestNG Suite。看是否執行成功。

五.配置build.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!-- one project with multiple targets  -->
<project name = "test" default = "OPSTestFF" basedir = ".">
<!-- paths used -->
<property name = "src.dir" value = "src"/>
<property name = "conf.dir" value = "conf"/>
<property name = "dest.dir" value = "build"/>
<property name = "dest.report" value = "report"/>
<path id="jarfile">
<fileset dir="lib" includes="selenium-server-standalone-2.24.1.jar" />
<fileset dir="lib" includes="testng-6.5.1.jar" />
<fileset dir="lib" includes= "ant-contrib-1.0b3.jar" />
<fileset dir="lib" includes= "slf4j-api-1.6.4.jar" />
<fileset dir="lib" includes= "reportng-1.1.4.jar" />
<fileset dir="lib" includes= "velocity-dep-1.4.jar" />
</path>
<!-- delete the output folder if it exists -->
<delete dir="${dest.dir}" failonerror="false"/> 
<!-- create the output folder -->
<mkdir dir="${dest.dir}"/> 
<mkdir dir="${dest.report}"/> 
<!-- target to compile all test classes out -->
<target name = "build" description="執行TestNg測試用例">
<!-- do copy -->
<copy todir="${dest.dir}/conf">
<fileset dir="${conf.dir}"/>
</copy>
<!-- compile -->
<javac srcdir="${src.dir}" destdir = "${dest.dir}" encoding="UTF-8" debug="true" fork = "yes">
<classpath refid="jarfile" />
</javac>
</target>
<!-- define the TestNG task -->
<taskdef name="testng" classname="com.beust.testng.TestNGAntTask" classpathref="jarfile"/>

<taskdef resource="net/sf/antcontrib/antlib.xml">
 <classpath>
   <pathelement location="lib/ant-contrib-1.0b3.jar"/>
 </classpath>
</taskdef>

<!-- run test cases for FF -->
<target name="OPSTestFF" depends="build">
<testng classpathref="jarfile"
outputDir="${dest.report}" haltOnFailure="true" useDefaultListeners="false"  listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,org.testng.reporters.FailedReporter">
<classfileset dir="${dest.dir}" includes="*.class" />
<classpath>
<pathelement path = "${dest.dir}"/>
</classpath>
<xmlfileset dir = "${basedir}" includes = "FFtestng.xml"/>
<sysproperty key="org.uncommons.reportng.title" value="自動化測試報告" />
</testng>
</target>  
</project>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章