
然后右击我的电脑->属性->高级->环境变量->系统变量 中,对CLASSPATH进行编辑,如果没有就新建一个(如果运行java或编译时有错误,就在)
务必将所有.jar文件的详细地址添加到CLASSPATH中,而不是用“c:\htmlunit\lib\”来代替,如.c:\htmlunit\lib\1.jarc:\htmlunit\lib\2.jar才是正确的写法
务必每一个都写清楚,需要注意最前面有个点".",最后面有个""
搜索资料,外加引用,自己实施配置了selenium+testng+reprotng+ant,可以运行成功,分享给大家。一、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 javacPerhaps 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文件
<!DOCTYPEsuite 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即可执行成功。
12. 至此基础的selenium+testng+reporting+ant框架搭建成功。
JAR 文件就是 Java Archive File,顾名思意,它的应用是与 Java 息息相关的,是 Java 的一种文档格式。 JAR 文件非常类似 ZIP 文件——准确的说,它就是 ZIP 文件,所以叫它文件包。欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)