My needs:
1, Webdriver code on the SVN;
2, Hudson (Jenkins) to perform the build, it downloads code from SVN, and uses Testng.xml to execute my set of test suites;
3, connected, the result is placed in the specified position;
My device:
Development tools: IntelliJ Idea
Automation Tools : Webdriver (selenium2.0)
Continuous Integration tool: Hudson (its plug-in needs to be installed seleniumhq,testng,ant) These can be installed under the package or automatically. Ant I'm using 1.8.3 version
PS: My svn and Hudson are all using my local machine as a server;
In addition: Before configuring this environment, please run your code on your development IDE to ensure that the code does not error
One, Hudson plug-in installation and setup
Http://hi.baidu.com/janice51
5/item/4c468bf7e79e780985d27821 here, can refer to;
Ps:ant installation I choose is automatic installation, can next package, decompression can be;
After installing selenium, there will be a selenium service pack in the working directory of Jenkins;
Note: In the Hudson at startup, you can observe the log, whether you can see the server package will automatically start selenium, so you can not set up the server when building selenium, otherwise, will error, said the port has been used, because it has been started.
Second, establish Hudson job, set up job
The main thing to suggest job is to get what you want Hudson to do, here you need to set ANT,SVN
SVN Store Code Address
Execute testng.xml with Ant
The following can actually not set, testng execution will produce test-output files, we have to do is to configure the location of this file.
When you have completed the job, you can try to build it; At this time, there will be a workspace in the working directory of Jenkins;
Workspace is the content that is downloaded on SVN.
Iii. Preparation of build.xml--focus
When all the things that need plug-ins are set, click Build, First Jenkins go to svn to download code, and put in workspace;
Then Ant went to find workspace's build.xml. If not, it will tell you that there is no, it is very important that you can go to the Jenkins console to see the log at the end of the build process, which is a very critical place, so don't overlook it.
Build.xml mainly do 3 things,
One is to compile the Java class,
The other thing to do Testng.xml,
The last thing to do is output the result to the specified location.
To compile a Java class:
<target name= "Compile" depends= "init" >
<javac srcdir= "${src}" destdir= "${dest}" classpathref= "Compile.path" encoding= "UTF-8"/>
</target>
Srcdir= "${src}" where the Java class resides;
Destdir= "${dest}", after compiling classes temporarily put place, why say temporary, because in build.xml I deleted it, you can also not delete it;
Classpathref= "Compile.path", compile the need to use some lib;
Encoding= "UTF-8", this should pay attention to the settings, if not set will be error, such as character and * * not conform to, of course, first of all, your Java class encoding format needs to be UTF-8;
Executive Testng.xml
<target name= "run_tests" depends= "compile" >
<testng classpathref= "Compile.path"? failureproperty= "Test.failed" >
<!--XML test suite file---
<xmlfileset dir= "${basedir}" >
<include name= "Testng.xml"/>
</xmlfileset>
</testng>
<antcall target= "Sendreport"/>
<fail message= "Error:test failed!!!!!" if= "test.failed"/>
</target>
<taskdef resource= "Testngtasks" classpath= "${lib.dir}/testng-6.4.jar"/>
Here are the questions:
1, Cause:
The name is undefined. Action:
Check the spelling. Action:
Check that any custom tasks/types has been declared.
Action:check that any <presetdef>/<macrodef> declarations has taken place.
The creation of the task did not succeed.
Workaround:
1) http://ant-contrib.sourceforge.net/Download Ant-contrib-1.0b3.zip
2) After downloading, decompression, will be ant-contrib-1.0b3.jar, placed under the ant you installed under the Lib can be;
Result output to the specified location
<target name= "Transform" >
<xslt in= "${basedir}/test-output/testng-results.xml" style= "${basedir}/test-output/testng-results.xsl" out= "${ Basedir}/test-output/index1.html "classpathref=" Compile.path ">
<!--need to specify the directory here again--
<param name= "Testngxslt.outputdir" expression= "${basedir}/test-output/"/>
<param name= "Testngxslt.showruntimetotals" expression= "true"/>
<!--<classpath refid= "Compile.path"/>-->
</xslt>
</target>
Here are the questions:
1, testng-results.xsl can not find this file
Workaround:
I went to download a zip on the internet, will unzip this file testng-results.xsl, put in Test-output (this file testng will automatically generate, as long as your testng.xml is successfully executed)
After the ps:ant1.7 version, processor = "Saxon Liaison" attribute is used after the error, the direct deletion is good.
The following is the content of the whole build.xml; with the above, it may seem to be better understood;
<project name= "kuaidi100" default= "start_server_and_run_tests" basedir= "." >
<property name= "src" value= "src/com"/>
<property name= "Dest" value= "Classes"/>
<property name = "log4j" value = "config"/>
<property name= "Lib.dir" value= "Lib"/>
<path id= "Compile.path" >
<fileset dir= "${lib.dir}/" >
<include name= "*.jar"/>
<include name= "*.zip"/>
</fileset>
<fileset dir= "${log4j}/" >
<include name= "*.properties"/>
<include name= "*.xml"/>
</fileset>
<pathelement location= "${src}"/>
<pathelement location= "${dest}"/>
<pathelement location= "${log4j}"/>
</path>
<target name= "init" description = "Create Classes file" >
<!--mkdir Means:create file:classes-->
<mkdir dir= "${dest}"/>
</target>
<target name= "Compile" depends= "init" >
<javac srcdir= "${src}" destdir= "${dest}" classpathref= "Compile.path" encoding= "UTF-8"/>
</target>
<!--run testng Ant task-->
<taskdef resource= "Testngtasks" classpath= "${lib.dir}/testng-6.4.jar"/>???????
<target name= "start_server_and_run_tests" depends= "compile" description= "Start Selenium server and Run tests" >
<parallel>
<antcall target= "Run_tests" >
</antcall>
</parallel>
</target>
<target name= "run_tests" depends= "compile" >
<testng classpathref= "Compile.path"? failureproperty= "Test.failed" >
<!--XML test suite file---
<xmlfileset dir= "${basedir}" >
<include name= "Testng.xml"/>
</xmlfileset>
</testng>
<antcall target= "Sendreport"/>
<fail message= "Error:test failed!!!!!" if= "test.failed"/>
</target>
<target name= "Sendreport" >
<delete dir= "${dest}"/>
<antcall target= "Transform"/>
</target>
<target name= "Transform" >
<xslt in= "${basedir}/test-output/testng-results.xml" style= "${basedir}/test-output/testng-results.xsl" out= "${ Basedir}/test-output/index1.html "classpathref=" Compile.path ">
<!--need to specify the directory here again--
<param name= "Testngxslt.outputdir" expression= "${basedir}/test-output/"/>
<param name= "Testngxslt.showruntimetotals" expression= "true"/>
<!--<classpath refid= "Compile.path"/>-->
</xslt>
</target>
</project>
So my whole environment was built, writing code and debugging for nearly a week, and the configuration actually only used a morning;
I hope you will succeed, and you will never have to open idea directly with Jenkins to get it done.
This article transferred from: http://www.spasvo.com/ceshi/open/kydycsgj/TestNG/20131218103100.html
Jenkins+testng+ant+webdriver Continuous Integration Testing