selenium+testNG+Ant

好几天没写了,抽时间写下,也好有个总结:

1.selenium+testNG+Ant

  (1)ant 是构建工具 他的作用就是运行你配置好的东西 而tentng.xml你可以认为他是管理test的一个配置。在ant中配置运行testng 启动testng的时候 就会运行testng里面配置好的东西。

  (2)eclipse 中给项目自动创建ant的build.xml文件

     Eclipse 自动生成 Ant的Build.xml 配置文件,生成的方法很隐蔽 选择你要生成Build.xml文件的项目,右键. Export-> General -> Ant Buildfiles .点Next,再点Finish.生成完毕.

  (3)

 1 Buildfile: D:myFilefileeclispe.workaistauild.xml
 2 build-subprojects:
 3 init:
 4 build-project:
 5      [echo] aista: D:myFilefileeclispe.workaistauild.xml
 6     [javac] D:myFilefileeclispe.workaistauild.xml:123: warning: 'includeantruntime' was not set, defaulting to 
 7 
 8 build.sysclasspath=last; set to false for repeatable builds
 9     [javac] D:myFilefileeclispe.workaistauild.xml:127: warning: 'includeantruntime' was not set, defaulting to 
10 
11 build.sysclasspath=last; set to false for repeatable builds
12     [javac] D:myFilefileeclispe.workaistauild.xml:132: warning: 'includeantruntime' was not set, defaulting to 
13 
14 build.sysclasspath=last; set to false for repeatable builds
15     [javac] D:myFilefileeclispe.workaistauild.xml:136: warning: 'includeantruntime' was not set, defaulting to 
16 
17 build.sysclasspath=last; set to false for repeatable builds
18 build:
19 BUILD SUCCESSFUL
20 Total time: 575 milliseconds
View Code

    解决:<javac srcdir="${build.src}" destdir="${build.dest}">

    改为<javac srcdir="${build.src}" destdir="${build.dest}" includeantruntime="on"/>

  (4)配置Ant的build.xml文件:eclipse Target "build" does not exist in the project 

     <project name="AntExample" default="secondTarget" basedir=".">
     这个里面的default设定了默认执行的目标,也就是dos下执行ant命令不加参数时,会默认执行default中设定的目标
     你的default是secondTarget但是这里:
        <targle name="secondTargle">
               <echo>${secondText}</echo>
        </targle>
     name是secondTargle和上面default中设置的不一样,只要设为一样就行了

   (5)

Buildfile: D:myFilefileeclispe.worksysframe-normal-testuild.xml
init:
compile:
     [echo] compile tests
run_tests:
     [echo] running tests
     [echo] D:myFilefileeclispe.worksysframe-normal-testclasses
   [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
   [testng]     at java.lang.Class.getDeclaredMethods0(Native Method)
   [testng]     at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
   [testng]     at java.lang.Class.getMethod0(Class.java:2694)
   [testng]     at java.lang.Class.getMethod(Class.java:1622)
   [testng]     at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
   [testng]     at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
   [testng] Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
   [testng]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
   [testng]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   [testng]     at java.security.AccessController.doPrivileged(Native Method)
   [testng]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   [testng]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
   [testng]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
   [testng]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   [testng]     ... 6 more
   [testng] Exception in thread "main" 
   [testng] The tests failed.
transform:
     [xslt] Processing D:myFilefileeclispe.worksysframe-normal-testlib	estng-results.xml to D:myFilefile

eclispe.worksysframe-normal-test	est-outputReport.html
     [xslt] Loading stylesheet D:myFilefileeclispe.worksysframe-normal-testlib	estng-results.xsl
BUILD SUCCESSFUL
Total time: 2 seconds
View Code

     发现testNG.jar的版本不对

原文地址:https://www.cnblogs.com/loveok-56/p/4438349.html