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>
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>
相关文章推荐
- jenkins+testng+ant+webdriver持续集成测试
- selenium使用testNG测试框架编写webdriver脚本_05
- java web + testNG + ant + Selenium整合对IE浏览器的自动化测试二(一个简单的Selenium测试)
- jenkins+testng+ant+webdriver持续集成测试
- WebDriver+TestNG+ANT 实现多浏览器兼容性测试
- Ant+TestNG+Webdriver环境搭建
- ReportNG替代TestNG自带html版测试报告
- selenium webdriver的testNG框架的介绍及使用
- UI自动化测试篇 :ReportNG替代TestNG自带html版测试报告初探
- Mac Eclipse+Maven+TestNg+ReportNg 生成测试报告
- selenium webdriver+testng自定义html测试报告
- karma + phantom + mocha + sion + chai + nightwatch + selenium2(webdriver) 测试框架学习
- 基于java WebDriver +TestNG 框架环境设置
- TestNG+ReportNG+Maven优化测试报告
- Mac Eclipse+Maven+TestNg+ReportNg 生成测试报告
- selenium+ant+testng测试框架简单介绍
- [CI]jenkins+ant+testng+webdriver+svn
- selenium +TestNG+ reportng 的ant配置
- Eclipse+Maven+TestNg+ReportNg 生成测试报告
- jenkins、ant、selenium、testng搭建自动化测试框架