您的位置:首页 > 其它

WebDriver+testng+reportng+ant测试框架整合

2013-12-11 11:51 411 查看
一、环境搭建

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: