selenium+testng+reprotng+ant框架搭建配置
来源:互联网 发布:js求二维数组的最大值 编辑:程序博客网 时间:2024/04/30 15:03
一、Configure
1. 安装testNG插件到eclipse.
-) 选择菜单 Help /Software updates / Find and Install.
-) 点击add button然后在location中输入http://beust.com/eclipse/
-) 确定后会自动安装testNG插件。
2. 在使用ant时候先将jdk的tools.jar引入进来。(不引入会报错Unable to find a javac;Perhaps JAVA_HOME does not point to the JDK)
二、Create a example to illustrate.
1. Create a new java project.
2. 将需要用到的包加进来。
selenium 包:selenium-java-client-driver.jar, selenium-server.jar
testng 包: testng.jar
reportng包:reporting.jar,velocity-dep.jar
3. Add a TestNG class.
4. 配置时: XML suit File = testng.xml
5. 在该类中添加代码,例如下
package com.selenium.testng.ant;
import org.testng.annotations.AfterSuite;
importorg.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
importcom.thoughtworks.selenium.DefaultSelenium;
importcom.thoughtworks.selenium.SeleneseTestCase;
importcom.thoughtworks.selenium.Selenium;
public class NewSample extends SeleneseTestCase{
private Selenium selenium;
private String testUrl="http://...";
@BeforeSuite
public void beforSuite()
{
selenium = new DefaultSelenium("localhost",4444,"*chrome",testUrl);
selenium.setSpeed("600");
selenium.start();
}
@Test
public void login()
{
//login js
}
@Test
public void configure()
{
//configure js
}
@Test
public void support()
{
// support js
}
@AfterSuite
public void afterSuit()
{
selenium.stop();
}
}
6. 配置testng.xml文件
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="false">
<test name="Test" preserve-order="true">
<classes>
<class name="com.selenium.testng.ant.NewSample">
<methods>
<include name="login"/>
<include name="configure"/>
<include name="support"/>
</methods>
</class>
</classes>
</test>
</suite>
7. 选择testng.xml然后run as TestNG Suite。看是否执行成功。(至此testng配置好)
8. 在根目录下新建一个file名为build.xml。(此文件为ant的配置文件)
9. 在project根目录下(与src,bin同级)建立lib目录并将所需要的包拷贝到改目录下。
10. 配置build.xml文件
<?xml version="1.0" ?>
<project name="testng" default="run_testng" basedir=".">
<property name="src" value="src" />
<property name="dest" value="classes" />
<property name="lib.dir" value="${basedir}/lib"/>
<property name="output.dir" value="${basedir}/OneSight"/>
<path id="compile.path">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
<pathelement location="${src}" />
<pathelement location="${dest}"/>
</path>
<target name="init">
<mkdir dir="${dest}" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}" classpathref="compile.path"/>
</target>
<taskdef resource="testngtasks" classpath="${lib.dir}/testng.jar"/>
<target name="run_testng" depends="compile" description="run testng">
<echo>running testng</echo>
<parallel>
<antcall target="startServer"/>
<sequential>
<echo taskname="waitfor" message="Wait for proxy server launch" />
<waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
<http url="http://localhost:4444/selenium-server/driver/?cmd=testComplete"/>
</waitfor>
<antcall target="run_tests"/>
<antcall target="stopServer"/>
</sequential>
</parallel>
</target>
<!-- start selenium server -->
<target name="startServer" description="start selenium server">
<java jar="${lib.dir}/selenium-server.jar" fork="true" spawn="true">
<arg line="-timeout 30" />
<jvmarg value="-Dhttp.proxyHost=proxy.corporate.com"/>
<jvmarg value="-Dhttp.proxyPort=3128"/>
</java>
</target>
<!-- stop selenium server -->
<target name="stopServer" description="stop selenium server">
<get dest="result.txt" src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer" ignoreerrors="true"/>
</target>
<!-- run tests -->
<target name="run_tests" depends="compile">
<echo>running tests</echo>
<testng classpathref="compile.path" outputdir="${output.dir}" haltonfailure="true" usedefaultlisteners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter" failureproperty="test.failed">
<xmlfileset dir="${src}/" >
<include name="testng.xml" />
</xmlfileset>
<sysproperty key="org.uncommons.reportng.title" value="My Test Report"/>
</testng>
<fail message="test failed.." if="test.failed"/>
</target>
</project>
11. 选择build.xml然后run as ant build即可执行成功。
1. 安装testNG插件到eclipse.
-) 选择菜单 Help /Software updates / Find and Install.
-) 点击add button然后在location中输入http://beust.com/eclipse/
-) 确定后会自动安装testNG插件。
2. 在使用ant时候先将jdk的tools.jar引入进来。(不引入会报错Unable to find a javac;Perhaps JAVA_HOME does not point to the JDK)
二、Create a example to illustrate.
1. Create a new java project.
2. 将需要用到的包加进来。
3. Add a TestNG class.
4. 配置时: XML suit File = testng.xml
5. 在该类中添加代码,例如下
package com.selenium.testng.ant;
import org.testng.annotations.AfterSuite;
importorg.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
importcom.thoughtworks.selenium.DefaultSelenium;
importcom.thoughtworks.selenium.SeleneseTestCase;
importcom.thoughtworks.selenium.Selenium;
public class NewSample extends SeleneseTestCase{
selenium = new DefaultSelenium("localhost",4444,"*chrome",testUrl);
}
6. 配置testng.xml文件
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="false">
<test name="Test" preserve-order="true">
<classes>
<class name="com.selenium.testng.ant.NewSample">
<methods>
<include name="login"/>
<include name="configure"/>
<include name="support"/>
</methods>
</class>
</classes>
</test>
</suite>
7. 选择testng.xml然后run as TestNG Suite。看是否执行成功。(至此testng配置好)
8. 在根目录下新建一个file名为build.xml。(此文件为ant的配置文件)
9. 在project根目录下(与src,bin同级)建立lib目录并将所需要的包拷贝到改目录下。
10. 配置build.xml文件
<?xml version="1.0" ?>
<project name="testng" default="run_testng" basedir=".">
<property name="src" value="src" />
<property name="dest" value="classes" />
<property name="lib.dir" value="${basedir}/lib"/>
<property name="output.dir" value="${basedir}/OneSight"/>
<path id="compile.path">
<fileset dir="${lib.dir}/">
<include name="*.jar" />
</fileset>
<pathelement location="${src}" />
<pathelement location="${dest}"/>
</path>
<target name="init">
<mkdir dir="${dest}" />
</target>
<target name="compile" depends="init">
<javac srcdir="${src}" destdir="${dest}" classpathref="compile.path"/>
</target>
<taskdef resource="testngtasks" classpath="${lib.dir}/testng.jar"/>
<target name="run_testng" depends="compile" description="run testng">
<echo>running testng</echo>
<parallel>
<antcall target="startServer"/>
<sequential>
<echo taskname="waitfor" message="Wait for proxy server launch" />
<waitfor maxwait="2" maxwaitunit="minute" checkevery="100">
<http url="http://localhost:4444/selenium-server/driver/?cmd=testComplete"/>
</waitfor>
<antcall target="run_tests"/>
<antcall target="stopServer"/>
</sequential>
</parallel>
</target>
<!-- start selenium server -->
<target name="startServer" description="start selenium server">
<java jar="${lib.dir}/selenium-server.jar" fork="true" spawn="true">
<arg line="-timeout 30" />
<jvmarg value="-Dhttp.proxyHost=proxy.corporate.com"/>
<jvmarg value="-Dhttp.proxyPort=3128"/>
</java>
</target>
<!-- stop selenium server -->
<target name="stopServer" description="stop selenium server">
<get dest="result.txt" src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer" ignoreerrors="true"/>
</target>
<!-- run tests -->
<target name="run_tests" depends="compile">
<echo>running tests</echo>
<testng classpathref="compile.path" outputdir="${output.dir}" haltonfailure="true" usedefaultlisteners="false"
<xmlfileset dir="${src}/" >
<include name="testng.xml" />
</xmlfileset>
<sysproperty key="org.uncommons.reportng.title" value="My Test Report"/>
</testng>
<fail message="test failed.." if="test.failed"/>
</target>
</project>
11. 选择build.xml然后run as ant build即可执行成功。
12. 至此基础的selenium+testng+reporting+ant框架搭建成功。
转载自:http://blog.163.com/weixia_1985/blog/static/963047972012714335914/
- selenium+testng+reprotng+ant框架搭建配置
- 分享selenium+testng+reprotng+ant配置
- Java+selenium+testng+ant框架搭建-环境搭建01
- Eclipse+TestNG+ant+selenium++jenkins+svn自动化测试框架搭建
- Eclipse+TestNG+ant+selenium++jenkins+svn自动化测试框架搭建
- jenkins、ant、selenium、testng搭建自动化测试框架
- TestNG+ant+selenium框架示例
- 基于Ant+Selenium+TestNG的测试框架配置
- Ant+testng+selenium基本配置
- selenium+java+testng+ant环境搭建
- selenium+java+testng+ant环境搭建
- Selenium框架搭建—安装TestNG
- 搭建自动化框架selenium+java+testng
- Selenium + ANT +TestNG
- selenium+TestNG+ANT
- TestNg + ReprotNG Commandline
- TestNg + ReprotNG Commandline
- Selenium+ANT+TestNG (SAT) Framework
- js获取地址栏url以及获取url参数
- poj_3735_Training little cats(矩阵快速幂)
- MAC OS X下安装Eclipse的SVN插件。
- OCP-1Z0-051-V9.02-14题
- android解锁屏时Activity生命周期的变化
- selenium+testng+reprotng+ant框架搭建配置
- QTimeLine学习
- sap,一句话入门
- Socket编程Linux或者Windows或Vxworks
- Design_pattern_AspNet_part4
- ICMP (RFC792)
- 130827解题报告
- VC6.0不能添加和打开工程文件的问题
- Chrome下安装Advanced REST Client插件