TestNG+Ant自动运行测试
2012-01-17 17:15
351 查看
如何在Ant的build.xml里面正确配置TestNG呢?
1. 在build.xml里面定义testng任务,在classpath里面指定testng.jar
regression 的 target 有一个depends属性,意思就是跑regression之前需要做compile,而跑compile之前需要clean,应该很容易理解。直接在命令行里面运行:
接下来只要把cron job配好就完成了
1. 在build.xml里面定义testng任务,在classpath里面指定testng.jar
<taskdef resource="testngtasks" classpath="${3rd.lib.dir}/testng.jar"/>2. 在build.xml里面新建一个 叫regression的target
<project basedir="." default="regression" name="automation test"> <property name="base.dir" value="/home/maguschen/workspaces/automation"/> <property name="testng.output.dir" value="${base.dir}/test-output"/> <property name="3rd.lib.dir" value="${base.dir}/libs"/> <property name="testng.file" value="testng.xml"/> <taskdef resource="testngtasks" classpath="${3rd.lib.dir}/testng.jar"/> <target name="clean"> <delete dir="${base.dir}/bin"/> </target> <target name="compile" depends="clean"> <mkdir dir="${base.dir}/bin"/> <javac srcdir="${base.dir}/src" destdir="${base.dir}/bin" classpathref="classes" includeantruntime="off" debug="on" debuglevel="lines,vars,source"/> </target> <path id="classes"> <fileset dir="${3rd.lib.dir}" includes="*jar"/> <fileset dir="${3rd.lib.dir}" includes="*zip"/> <pathelement location="${base.dir}/bin"/> </path> <target name="regression" depends="compile"> <testng outputdir="${testng.output.dir}" classpathref="classes" delegateCommandSystemProperties="true"> <xmlfileset dir="${base.dir}" includes="${testng.file}"/> </testng> </target> </project>在target里面新建一个testng标签,里面需要设置的属性有:outputdir – 测试结果输出目录;classpathref – 那些自动化测试代码的目标路径,通常就是编译完成以后的那个目标路径,例如 xxx/bin;delegateCommandSystemProperties – 接受传递命令行参数作为系统变量,这个设置为true可以在调用Ant的时候通过 -Dfoo=value 把参数传递给TestNG;里面还有一个xmlfileset节点,这个节点就是指定testng.xml文件的目录以及具体文件。
regression 的 target 有一个depends属性,意思就是跑regression之前需要做compile,而跑compile之前需要clean,应该很容易理解。直接在命令行里面运行:
ant -Durl=http://www.google.com -f build.xml regression
这里出现了 -Durl=http://www.google.com ,回到之前的配置,delegateCommandSystemProperties=”true”。如果这个参数为true,那么通过命令行的 -D 参数可以把一些变量传递给TestNG。譬如说TestNG的测试方法里面是有@Parameters({“url”})标签的话,就能通过ant -Durl=xxx 来传递url的值给到TestNG。例如@Parameters({"url"}) @Test public void search(String url){ WebDriver driver = new FirefoxDriver(); driver.get(url); WebElement query = driver.findElement(By.name("q")); query.sendKeys("Cheese"); query.submit(); }如果这样调用:ant -Durl=http://www.google.com -f build regression 。那么就会进入google的首页搜索,如果是: ant -Durl=http://magustest.com -f build regression ,那么就会找不到叫“q”的元素,呵呵。
接下来只要把cron job配好就完成了
15 * * * * ant -f /home/maguschen/workspaces/automation/build.xml regression
相关文章推荐
- TestNG+Ant自动运行测试
- TestNG+Ant自动运行测试
- selenuim+testng集成ant和reportNG自动执行和发送测试报告
- Ant中批量调用TestNG的XML文件,并调用TestNgXlst生成漂亮的html测试报告
- Webdriver+Testng实现测试用例失败自动截图功能
- net自动化测试之道API测试-自动运行测试套件
- 使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
- 在TestNG中运行WebDriver测试用例
- JUnit4---实践二:拓展之运行指定类的某些测试方法-自动生成该文件
- ant结合junit进行软件自动测试(转)
- selenium进阶之基础--web自动测试框架(ant+junit+selenium)
- Ant学习-002-ant 执行 TestNG 测试用例时 [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException 解决方案
- selenium+ant+testng测试框架简单介绍
- 使用Ant+JUnit+Cobertura来实现代码覆盖自动测试
- 转: ant集成junit自动测试的build.xml标准模板
- 软件测试实习0627-testNG运行JUnit测试
- 使用ant运行testng的testng.xml并且使用testng-results.xsl美化结果
- ant+junit 自动生成测试报告
- ant+TestNG-xslt生成selenium测试报告
- Webdriver+Testng实现测试用例失败自动截图功能