分享selenium+testng+reprotng+ant配置
来源:互联网 发布:alias软件logo 编辑:程序博客网 时间:2024/05/18 03:48
一、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
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;
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;
publicclass NewSampleextends SeleneseTestCase{
private Selenium selenium;
private String testUrl="http://...";
@BeforeSuite
publicvoid beforSuite()
{
selenium =new DefaultSelenium("localhost",4444,"*chrome",testUrl);
selenium.setSpeed("600");
selenium.start();
}
@Test
publicvoid login()
{
//loginjs
}
@Test
publicvoid configure()
{
//configurejs
}
@Test
publicvoid support()
{
// supportjs
}
@AfterSuite
publicvoid afterSuit()
{
selenium.stop();
}
}
6.配置testng.xml文件
<!DOCTYPEsuiteSYSTEM "http://testng.org/testng-1.0.dtd">
<!DOCTYPEsuiteSYSTEM "http://testng.org/testng-1.0.dtd">
<suitename="Suite"parallel="false">
<testname="Test"preserve-order="true">
<classes>
<classname="com.selenium.testng.ant.NewSample">
<methods>
<includename="login"/>
<includename="configure"/>
<includename="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" ?>
<?xml version="1.0" ?>
<projectname="testng"default="run_testng"basedir=".">
<propertyname="src"value="src"/>
<propertyname="dest"value="classes"/>
<propertyname="lib.dir"value="${basedir}/lib"/>
<propertyname="output.dir"value="${basedir}/OneSight"/>
<pathid="compile.path">
<filesetdir="${lib.dir}/">
<includename="*.jar"/>
</fileset>
<pathelementlocation="${src}"/>
<pathelementlocation="${dest}"/>
</path>
<targetname="init">
<mkdirdir="${dest}"/>
</target>
<targetname="compile"depends="init">
<javacsrcdir="${src}"destdir="${dest}"classpathref="compile.path"/>
</target>
<taskdefresource="testngtasks"classpath="${lib.dir}/testng.jar"/>
<targetname="run_testng"depends="compile"description="run testng">
<echo>running testng</echo>
<parallel>
<antcalltarget="startServer"/>
<sequential>
<echotaskname="waitfor"message="Wait for proxy server launch"/>
<waitformaxwait="2"maxwaitunit="minute"checkevery="100">
<httpurl="http://localhost:4444/selenium-server/driver/?cmd=testComplete"/>
</waitfor>
<antcalltarget="run_tests"/>
<antcalltarget="stopServer"/>
</sequential>
</parallel>
</target>
<!-- start selenium server -->
<targetname="startServer"description="start selenium server">
<javajar="${lib.dir}/selenium-server.jar"fork="true"spawn="true">
<argline="-timeout 30"/>
<jvmargvalue="-Dhttp.proxyHost=proxy.corporate.com"/>
<jvmargvalue="-Dhttp.proxyPort=3128"/>
</java>
</target>
<!-- stop selenium server -->
<targetname="stopServer"description="stop selenium server">
<getdest="result.txt"src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer"ignoreerrors="true"/>
</target>
<!-- run tests -->
<targetname="run_tests"depends="compile">
<echo>running tests</echo>
<testngclasspathref="compile.path"outputdir="${output.dir}"haltonfailure="true"usedefaultlisteners="false"
listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter"failureproperty="test.failed">
<xmlfilesetdir="${src}/">
<includename="testng.xml"/>
</xmlfileset>
<syspropertykey="org.uncommons.reportng.title"value="My Test Report"/>
</testng>
<failmessage="test failed.."if="test.failed"/>
</target>
</project>
11.选择build.xml然后run as ant build即可执行成功。
12. 至此基础的selenium+testng+reporting+ant框架搭建成功。- 分享selenium+testng+reprotng+ant配置
- selenium+testng+reprotng+ant框架搭建配置
- Ant+testng+selenium基本配置
- Selenium + ANT +TestNG
- selenium+TestNG+ANT
- TestNg + ReprotNG Commandline
- TestNg + ReprotNG Commandline
- 基于Ant+Selenium+TestNG的测试框架配置
- Selenium+ANT+TestNG (SAT) Framework
- TestNG+ant+selenium框架示例
- Selenium+Testng+Ant+Jenkins手记
- selenium+testng+ant+jenkins 手记
- ant+TestNG-xslt生成selenium测试报告
- selenium+java+testng+ant环境搭建
- Executing Selenium TestNG tests using ANT
- Executing Selenium TestNG tests using ANT
- ant+testng-xslt生成selenium测试报告
- selenium+java+testng+ant环境搭建
- HttpServletResponse 的状态码含义及方法摘要----api
- 对偶问题参考文献
- iOS_判断异常出现在多少行
- win7 打开plsql登录不上显示空白提示框解决办法
- cocos2d-x 3.0sprite轮换
- 分享selenium+testng+reprotng+ant配置
- windows使用双网卡同时上内外网
- 关于com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
- response.setContentType()的作用及参数
- 多线程详解
- gsoap传递数组方法
- 致公党江苏省委副主委应邀出席“引凤工程”网站建设讨论会
- Ogre学习(一)绘制一个立方体ManualObject(原)
- 常用DOS命令大全