ant编译错误,主要是使用webdriver文件。

时间:2016-05-16 20:50:22

标签: maven selenium-webdriver ant jar

我似乎与java版本有一些冲突。编译错误主要与webdriver文件相关联。我目前正在使用jdk1.8.0_65并在路径中正确配置它。     F:\ DataDriven \ WDDF> ant编译     Buildfile:F:\ DataDriven \ WDDF \ build.xml

setPath:

initialization:

clear:

compile:
[echo] Creating directory...
[mkdir] Created dir: F:\DataDriven\WDDF\build
[echo] Suite class path Is ------: F:\DataDriven\WDDF\JarFiles\SaxonLiaison
.jar:F:\DataDriven\WDDF\JarFiles\commons-codec-1.10.jar:F:\DataDriven\WDDF\JarFi
les\commons-logging-1.2.jar:F:\DataDriven\WDDF\JarFiles\curvesapi-1.03.jar:F:\Da
taDriven\WDDF\JarFiles\junit-4.12.jar:F:\DataDriven\WDDF\JarFiles\log4j-1.2.17.j
ar:F:\DataDriven\WDDF\JarFiles\poi-3.14-20160307.jar:F:\DataDriven\WDDF\JarFiles
\poi-examples-3.14-20160307.jar:F:\DataDriven\WDDF\JarFiles\poi-excelant-3.14-20
160307.jar:F:\DataDriven\WDDF\JarFiles\poi-ooxml-3.14-20160307.jar:F:\DataDriven
\WDDF\JarFiles\poi-ooxml-schemas-3.14-20160307.jar:F:\DataDriven\WDDF\JarFiles\p
oi-scratchpad-3.14-20160307.jar:F:\DataDriven\WDDF\JarFiles\saxon-8.7.jar:F:\Dat
aDriven\WDDF\JarFiles\testng-6.9.9.jar:F:\DataDriven\WDDF\JarFiles\testng-xslt-m
aven-plugin-test-0.0.jar:F:\DataDriven\WDDF\JarFiles\xmlbeans-2.6.0.jar
 [echo] compiling...
[javac] F:\DataDriven\WDDF\build.xml:60: warning: 'includeantruntime' was 
not set, defaulting to build.sysclasspath=last; set to false for repeatable builds

[javac] Compiling 9 source files to F:\DataDriven\WDDF\build
[javac]
[javac]           WARNING
[javac]
[javac] The -source switch defaults to 1.8 in JDK 1.8.
[javac] If you specify -target 1.5 you now must also specify -source 1.5.
[javac] Ant will implicitly add -source 1.5 for you.  Please change your build file.
[javac] warning: [options] bootstrap class path not set in conjunction with-source 1.5
[javac] warning: [options] source value 1.5 is obsolete and will be removed in a future release
[javac] warning: [options] target value 1.5 is obsolete and will be removed in a future release
[javac] warning: [options] To suppress warnings about obsolete options, use -Xlint:-options.
[javac] F:\DataDriven\WDDF\src\com\stta\TestSuiteBase\SuiteBase.java:7: error: package 
org.openqa.selenium does not exist
[javac] import org.openqa.selenium.WebDriver;
[javac]                           ^
[javac] F:\DataDriven\WDDF\src\com\stta\TestSuiteBase\SuiteBase.java:8: error: package 
org.openqa.selenium.firefox does not exist
[javac] import org.openqa.selenium.firefox.FirefoxDriver;
[javac]                                   ^
[javac] F:\DataDriven\WDDF\src\com\stta\TestSuiteBase\SuiteBase.java:17: error: cannot find symbol
[javac]     public static WebDriver driver=null;
[javac]                   ^
[javac]   symbol:   class WebDriver
[javac]   location: class SuiteBase
[javac] F:\DataDriven\WDDF\src\com\stta\TestSuiteBase\SuiteBase.java:37: error: cannot find symbol
[javac]                     driver = new FirefoxDriver();
[javac]                                  ^
[javac]   symbol:   class FirefoxDriver
[javac]   location: class SuiteBase
[javac] 4 errors
[javac] 4 warnings

BUILD FAILED
F:\DataDriven\WDDF\build.xml:60: Compile failed; see the compiler error output f
or details.

Total time: 1 second

这是我的build.xml

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE project [
]>

<project name="WDDF" default="usage" basedir=".">  

<property environment="appenv"/>    
<property name="project.home" value="${basedir}"/>
<!-- Set JarFiles Folder's Path. -->
<property name="project.jars" value="F:\DataDriven\WDDF\JarFiles"/>
<property name="report.dest" value="${project.home}/build"/>
<property name="report.src" value="${project.home}/src"/>
<property name="report.result" value="test-output"/>

<target name="setPath" unless="suite.classpath">
    <path id="jar_path">
        <fileset dir="${project.jars}" includes="*.jar"/>
    </path>
    <pathconvert pathsep=":" 
        property="suite.classpath" 
        refid="jar_path"/>
</target>

<target name="initialization" depends="setPath">
    <tstamp>
        <format property="Init.time" pattern="MM/dd/yyyy hh:mm aa" />
    </tstamp>
    <condition property="ANT" 
        value="${appenv.ANT_HOME}/bin/ant.bat" 
        else="${appenv.ANT_HOME}/bin/ant">
                <os family="windows" />
    </condition>
    <taskdef name="testng" classname="org.testng.TestNGAntTask">
            <classpath>
                <pathelement location="F:\DataDriven\WDDF\JarFiles\testng-6.9.9.jar"/>
            </classpath>
    </taskdef>
</target>    

<!-- To clear -->
<target name="clear">
    <delete dir="${report.dest}"/>
</target>

<!-- To compile -->

    <target name="compile" depends="initialization, clear" > 
        <delete includeemptydirs="true" quiet="true">
            <fileset dir="${report.dest}" includes="**/*"/>
        </delete>
        <echo message="Creating directory..."/>
        <mkdir dir="${report.dest}"/>
        <echo message="Suite class path Is ------: ${suite.classpath}"/>
        <echo message="compiling..."/>
        <javac 
            debug="true" 
            destdir="${report.dest}" 
            srcdir="${report.src}" 
            target="1.5" 
            classpath="${suite.classpath}"
        >
        </javac>
         <copy todir="${report.dest}">
                    <fileset dir="${report.src}" excludes="**/*.java"/>
          </copy>
      </target>


<!-- build -->
<target name="build" depends="initialization">
</target>

<!-- run -->
<target name="run" depends="compile">
    <testng classpath="${suite.classpath}:${report.dest}" suitename="suite1">   
        <xmlfileset dir="${project.home}" includes="testng.xml"/>
    </testng>       
</target>   

<target name="usage">
    <echo>
        ant run will execute the test
    </echo>
</target>


<path id="test.c">
        <fileset dir="${project.jars}" includes="*.jar"/>

</path>

  <target name="reports">
        <mkdir dir="${project.home}/XSLT_Reports/Reports"/>
    <!-- Set testng-results.xsl File's Path. -->
        <xslt in="${report.result}/testng-results.xml" style="src/com/stta/xslt/testng-results.xsl"
              out="${project.home}/XSLT_Reports/Reports/index.html" classpathref="test.c" processor="SaxonLiaison">
            <param name="testNgXslt.outputDir" expression="${project.home}/XSLT_Reports/Reports/"/>
            <param name="testNgXslt.showRuntimeTotals" expression="true"/>
        </xslt>
    </target>   

</project>

1 个答案:

答案 0 :(得分:0)

这可能与您使用旧版Java的事实有关。在你的情况下它是Java 5。尝试在target的以下块中的build.xml参数中将Java版本更改为8:

 <javac 
     debug="true" 
     destdir="${report.dest}" 
     srcdir="${report.src}" 
     target="1.8" 
     classpath="${suite.classpath}"
 >

之后刷新并清理项目。