1.CSV文件设置为UTF-8;
2.重写build.xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<!-- <?xml version="1.0" encoding="GBK"?> -->
<project basedir="." default="testoutput" name="automation test"> <!--默认使用testoutput任务-->
<property name="base.dir" value="D:\workspace\MySeleniumScript"/><!--项目根目录-->
<property name="testng.output.dir" value="${base.dir}/result"/><!--配置结果输出地址-->
<property name="lib.dir" value="${base.dir}/lib"/><!--设置其他jar包目录-->
<property name="testng.file" value="${base.dir}/testng.xml"/> <!--调用的testng用例执行xml文件,这里是文件名-->
<property name="testdir" location="test" /> <!--设置编译的2进制文件目录-->
<taskdef resource="testngtasks" classpath="${lib.dir}/testng.jar"/><!--导入testng的jar包-->
<target name="clean"> <!--清除之前的2进制文件-->
<delete dir="${testdir}"/>
<delete file="D:/Myjenkins/workspace/Interface/test-output/TestReport.zip"/>
</target>
<target name="compile" depends="clean">
<mkdir dir="${testdir}"/><!--新建2进制文件存放目录-->
<mkdir dir="result"/> <!--新建结果导出目录-->
<javac srcdir="${base.dir}/src" encoding="UTF-8" destdir="${testdir}" classpathref="classes"
includeantruntime="off" debug="on" debuglevel="lines,vars,source"/> </target> <!--编译java程序-->
<path id="classes"> <!--设置jar包相关-->
<fileset dir="${lib.dir}" includes="*.jar"/>
<pathelement location="${testdir}"/>
<pathelement location="${base.dir}/src" />
</path>
<target name="runtest" depends="compile">
<!--运行testng文件-->
<!-- 在target里面新建一个testng标签,里面需要设置的属性有:outputdir – 测试结果输出目录;classpathref – 那些自动化测试代码的目标路径,通常就是编译完成以后的那个目标路径,例如xxx/bin;delegateCommandSystemProperties – 接受传递命令行参数作为系统变量,这个设置为true可以在调用Ant的时候通过 -Dfoo=value 把参数传递给TestNG;里面还有一个xmlfileset节点,这个节点就是指定testng.xml文件的目录以及具体文件。 -->
<testng outputdir="${base.dir}/test-output"
classpathref="classes"
delegateCommandSystemProperties="true">
<sysproperty key="file.encoding" value="UTF-8" /><!--解决控制台中文乱码问题,关系到和用例输出结果进行对比-->
<xmlfileset dir="${base.dir}" includes="testng.xml"/> <!--在指定路径下,找文件名由testng.file-->
</testng> <!--定义的testng.xml文件-->
</target>
<tstamp>
<format property="CURTIME" pattern="yyyyMMdd_HHmmss" locale="us"/> <!--设置当前时间-->
</tstamp>
<path id= "test.classpath" >
<fileset dir= "${lib.dir}" includes= "*.jar" />
</path>
<target name= "testoutput" depends="runtest" >
<xslt in= "D:/workspace/MySeleniumScript/test-output/testng-results.xml" style= "D:/workspace/MySeleniumScript/test-output/testng-results.xsl"
out= "D:/workspace/MySeleniumScript/test-output/TestReport/index.html" >
<!-- you need to specify the directory here again -->
<param name= "testNgXslt.outputDir" expression= "D:/Myjenkins/workspace/Interface/test-output/TestReport" />
<classpath refid= "test.classpath" />
</xslt>
<zip destfile="D:/workspace/MySeleniumScript/test-output/html.zip" basedir="D:/workspace/MySeleniumScript/test-output/html"/>
</target>
</project>