打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
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>
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Ant学习指南
JR 精品文章 - Ant参考教程(一)
ANT1.6.1常用命令
开发你自己的XMPP IM 续
ant 使用指南
无所不能的“蚂蚁”--Ant(一)(二)(三)(四)
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服