我正在尝试使用jenkins来运行selenium webdriver测试(持续集成),但到目前为止我还没有成功。我的设置: - 日食 - testng - ant(build.xml文件) - 詹金斯 - 一切都在当地托管 我正在并行运行我的测试(1个测试,3个浏览器),如果我运行testng文件,这个工作正常,如果我运行ant文件(build.xml)它说“构建成功”但是如果也运行这个没有任何反应同样的文件在詹金斯它说同样的事情'建立成功'但是没有任何反应。由此我可以推断出jenkins正在运行正确的文件,但它只是没有执行测试。我甚至尝试过使用maven,但我不明白,所以当我采用这条路线时代码甚至都没有编译。 有人可以帮助我,并指出我正确的方向,因为我相信我错过了一些东西。我已经包含了我的jenkins集合的照片,下面是我的ant文件的副本:
![<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. --><project basedir="." default="build" name="jenkins_run_selenium">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../Program Files (x86)/eclipse-standard-kepler-R-win32-x86_64/Eclipse"/>
<property name="junit.output.dir" value="junit"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="jenkins_run_selenium.classpath">
<pathelement location="bin"/>
<pathelement location="../../../Program Files (x86)/Eclipse/selenium-2.40.0/selenium-java-2.40.0-srcs.jar"/>
<pathelement location="../../../Program Files (x86)/Eclipse/selenium-2.40.0/selenium-server-standalone-2.40.0.jar"/>
<pathelement location="../Desktop/Jar Files and Sources/testng-6.8.5-javadoc.jar"/>
<pathelement location="../Desktop/Jar Files and Sources/testng-6.8.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="jenkins_run_selenium.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="jenkins_run_selenium">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<classpath refid="jenkins_run_selenium.classpath"/>
</junit>
</target>
<target name="junitreport">
<junitreport todir="${junit.output.dir}">
<fileset dir="${junit.output.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${junit.output.dir}"/>
</junitreport>
</target>
</project>][1]
答案 0 :(得分:0)
我可以用jenkins,maven和代码来解释你的方式。它应该与ant非常相似。这肯定会让詹金斯解雇你的考试。
在代码中: 创建如下所示的测试套件类
@RunWith(Suite.class)
@Suite.SuiteClasses
({
Test1.class,
Test2.class
})
public class UnitTestSuite{}
在maven中:在pom.xml中使用maven-surefire-plugin,如下所示:
<!-- TEST -->
<plugin>
<!-- Runs the unit tests. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<configuration>
<includes>
<include>**/UnitTestSuite.java</include>
</includes>
</configuration>
</plugin>
最后在jenkins构建部分设定目标为
clean install -e -Dmaven.test.failure.ignore=false
答案 1 :(得分:0)
尝试通过添加目标&#34; jenkins_run_selenium&#34;来修改您的ant文件如下:
<target name="jenkins_run_selenium">
<mkdir dir="${junit.output.dir}"/>
<junit fork="yes" printsummary="withOutAndErr">
<formatter type="xml"/>
<test name="tests.MyUnitTests" todir="${junit.output.dir}"/>
<classpath refid="jenkins_run_selenium.classpath"/>
</junit>
</target>
如果要批量运行所有测试,请参阅https://stackoverflow.com/a/4760714/1712272