Eclipse+TestNG+ant+selenium++jenkins+svn自动化测试框架搭建

简介: Eclipse+TestNG+ant+selenium++jenkins+svn自动化测试框架搭建

1. 从写code开始吧,安装eclipse,官网下载软件,https://www.eclipse.org/downloads/,记得先装Java,建议装JDK1.7以上的。


2.接下来需要写selenium的code,testng的code,从selenium,selenium-server-standalone-2.41.0.jar,testng,testng-6.8.jar官网下载相应jar文件,放入eclipse的目录中。


4.接下来你可以写selenium的代码了,写好代码后,运用testng的框架,testNG如何使用,这里不详细说,参考testNG的官网,在code中加上testNG的注释。


5.testNG的xml文件如下,这时候执行这个xml文件就执行了selenium测试了,最后结果会显示执行成功多少case,失败多少case。


[html]  view plain  copy

<suite name="Suite1" parallel="tests" thread-count="5">  
  <test name="test1">  
  <parameter name="myage" value="25"/>  
  <parameter name="myname" value="abel,"/>  
  <groups>  
     <define name="allfunctest">  
        <include name="windows.*"/>  
        <include name="linux.*"/>  
     </define>  
     <define name="all">  
        <include name="allfunctest"/>  
        <include name="functest"/>  
        <exlcude name="checkintest"/>  
     </define>  
     <run>  
        <include name="all"/>  
        <include name="aa"/>  
        <include name="bb"/>  
        <include name="cc"/>  
     </run>  
     <dependencies>  
        <group name="aa" depends-on="bb cc"/>  
     </dependencies>  
  </groups>  
    <classes>  
       <class name="test.TestNG"/>  
    </classes>  
  </test>  
</suite>


6、接下来用ant去调用testNG的xml文件,因为最后执行是在jenkins的机器上执行,所以需要ant来进行编译,附上ant的build.xml文件。


在机器上装上ant,eclipse上装testng插件,ant插件,我安装了。


[html]  view plain  copy

<project name="TestNGTest" default="test" basedir=".">  
<!-- Define <testng> task -->  
  <taskdef name="testng" classname="org.testng.TestNGAntTask">  
    <classpath>  
      <pathelement location="lib/testng-6.8.jar"/>  
    </classpath>  
  </taskdef>  
   <property name="testdir" location="build" />  
   <property name="srcdir" location="src" />  
   <property name="libdir" location="lib" />  
   <property name="full-compile" value="true" />  
   <path id="classpath.base"/>  
   <path id="classpath.test">  
       <fileset dir="${libdir}">  
         <include name="**/testng*.jar" />  
      </fileset>  
      <pathelement location="${testdir}" />  
      <pathelement location="${srcdir}" />  
      <path refid="classpath.base" />  
   </path>  
   <target name="clean" >  
      <delete verbose="${full-compile}">  
         <fileset dir="${testdir}" includes="**/*.class" />  
      </delete>  
   </target>  
   <target name="compile" depends="clean">  
      <javac srcdir="${srcdir}" destdir="${testdir}"   
         verbose="${full-compile}">  
         <classpath refid="classpath.test"/>  
      </javac>  
   </target>  
         <target name="test"  depends="compile">  
            <testng outputdir="${testdir}" classpathref="classpath.test">   
                      <xmlfileset dir="${srcdir}" includes="TestNG_study.xml"/>   
           </testng>  
   </target>  
</project>


7、如果以上都ok了,这时需要将代码提交到svn,svn服务器搭建就不说了,Linux下自带了,只需要改改东西就行了。可能会出现没有权限的问题,authz文件加上这个

[/]
username=rw


8.代码提交成功,关于eclipse代码提交的问题,请参考我前面的blog。lib下的jar文件,代码,及testNG和ant的xml文件均需提交到svn。


6.一些都准备就绪,接下来需要jenkins来调用了。


7.jenkins调用:

 前提:在jenkins的机器上安装ant,并修改ant的环境变量。jdk是必需品,不多说了。。


jenkins的步骤:

a.通过svn将代码check out

b.通过jenkins的ant插件invoke ant,如果出现JAVA_HOME error,需要在jenkins的system manger中安装JDK,这时还需要个Oracle帐号(free).

 c.invoke ant前,先jenkins的系统管理中配置ant插件,invoke时需指定build.xml文件的位置,否则无法找到,因为build.xml不在默认的workspace目录下。

 d.不出意外,这个时候应该是可以执行了。但是执行结果怎么看到呢? 安装jenkins的testNG的插件,执行testng-results.xml文件的位置,就能看到testng的report了

e.个人感觉testNG的report还是不够美观,网上查资料看有testNGxslt使用,但是我研究了后,我这怎么都运行不起来,不是少这就是少那的。。。后续有时间再搞。


8.到此,整个框架搭建完成,所有软件都在相应的官网可下载并有使用说明。


后续,testNGxslt解决了,将saxon-8.7.jar,SaxonLiaison.jar 两个文件传到lib文件夹中,记得验证文件是否错误,双击文件,如果出现错误,则文件错了,我就是因为文件有问题,所以死活整不通,后来双击一下,发现了这个问题。ant的build.xml文件加上以下内容即可:


[html]  view plain  copy

<path id="test.classpath">  
<fileset dir="${libdir}" includes="*.jar"/>  
</path>  
    <target name="testcase">  
    <property name="dir" value=""/>  
    <mkdir dir="${testdir}/output"/>  
    <xslt processor="SaxonLiaison" classpathref="test.classpath" out="${testdir}/output/index.html" style="src/testng-results.xsl" in="${testdir}/testng-results.xml">  
    <param name="testNgXslt.outputDir" expression="${testdir}/output/"/>  
    <param name="testNgXslt.sortTestCaseLinks" expression="true"/>  
    <param name="testNgXslt.testDetailsFilter" expression="FAIL,SKIP,PASS"/>  
    </xslt>  
    </target>



相关文章
|
5月前
|
Web App开发 人工智能 JavaScript
主流自动化测试框架的技术解析与实战指南
本内容深入解析主流测试框架Playwright、Selenium与Cypress的核心架构与适用场景,对比其在SPA测试、CI/CD、跨浏览器兼容性等方面的表现。同时探讨Playwright在AI增强测试、录制回放、企业部署等领域的实战优势,以及Selenium在老旧系统和IE兼容性中的坚守场景。结合六大典型场景,提供技术选型决策指南,并展望AI赋能下的未来测试体系。
|
3月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
214 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
3月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
252 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
8月前
|
安全 Unix Linux
Metasploit Pro 4.22.7-2025050101 发布 - 专业渗透测试框架
Metasploit Pro 4.22.7-2025050101 发布 - 专业渗透测试框架
251 10
Metasploit Pro 4.22.7-2025050101 发布 - 专业渗透测试框架
|
6月前
|
Web App开发 存储 前端开发
Python+Selenium自动化爬取携程动态加载游记
Python+Selenium自动化爬取携程动态加载游记
|
9月前
|
安全 Ubuntu Linux
Metasploit Pro 4.22.7-2025042101 发布 - 专业渗透测试框架
Metasploit Pro 4.22.7-2025042101 (Linux, Windows) - 专业渗透测试框架
252 5
Metasploit Pro 4.22.7-2025042101 发布 - 专业渗透测试框架
|
4月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
365 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
4月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
451 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
|
4月前
|
安全 Linux 网络安全
Metasploit Framework 6.4.88 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.88 (macOS, Linux, Windows) - 开源渗透测试框架
597 0
|
4月前
|
缓存 安全 Linux
Metasploit Pro 4.22.8-2025082101 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025082101 (Linux, Windows) - 专业渗透测试框架
217 0

推荐镜像

更多