我正在使用ANT和IVY来解决依赖关系并构建项目。我必须编写一个硒测试用例,所以我在IVY文件中包含了硒依赖性,如下所示:
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2"/>
IVY可以下载依赖项,但当我使用ANT编译项目时,它失败了,并出现以下错误:
cannot find symbol
[javac] symbol : class WebDriver
[javac] location: class com.barclays.test.selenium.TestSelenium
[javac] WebDriver driver = new FirefoxDriver();
你能告诉我我缺了什么吗。
编辑:
build.xml的一部分:
<target name="init">
<ivy:resolve />
<ivy:cachepath pathid="compile.path" conf="compile" />
<ivy:cachepath pathid="test.path" conf="test" />
</target>
<target name="clean">
<delete dir="${target.dir}" />
</target>
<target name="prepare" depends="clean" description="Create working dirs and copy static files to work dir">
<mkdir dir="${target.dir}/WEB-INF/classes" />
<mkdir dir="${target.dir}/WEB-INF/classes-test" />
<!-- Copy static HTML and JSP files to work dir -->
<copy todir="${target.dir}">
<fileset dir="${web.home}" />
</copy>
</target>
<target name="compile" depends="prepare, init" description="Compile Java sources and copy to WEB-INF/classes dir">
<javac srcdir="${src.dir}" includeantruntime="false" debug="true" classpathref="compile.path" destdir="${target.dir}/WEB-INF/classes">
</javac>
<javac srcdir="${test.dir}" includeantruntime="false" debug="true" classpathref="test.path" destdir="${target.dir}/WEB-INF/classes-test">
<classpath>
<pathelement location="${target.dir}/WEB-INF/classes" />
</classpath>
</javac>
<copy todir="${target.dir}/WEB-INF/classes">
<fileset dir="${src.dir}" excludes="**/*.java" />
</copy>
</target>
以及ivy.xml:
<ivy-module version="2.0">
<info organisation="org.apache" module="test-ivy" />
<configurations>
<conf name="runtime" />
<conf name="compile" extends="runtime" description="provides the
compiler" />
<conf name="test" description="Required for test only" extends="runtime"/>
</configurations>
<dependencies>
<dependency org="javax.servlet" name="servlet-api" rev="2.5" />
<dependency org="junit" name="junit" rev="4.12" />
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2" conf="test-java->default"/>
<dependency org="log4j" name="log4j" rev="1.2.16" conf="compile->*" />
</dependencies>
</ivy-module>
log4j也是如此。我已经添加了依赖项,但当我尝试创建Logger对象时,eclipse在使用代码辅助时没有列出log4j的记录器。
感谢
在build.xml中,您不是用测试类路径编译测试类,而是用编译类路径编译。
Classpathref应设置为test.path
<javac srcdir="${test.dir}" includeantruntime="false" debug="true" classpathref="test.path" destdir="${target.dir}/WEB-INF/classes-test">
<classpath>
<pathelement location="${target.dir}/WEB-INF/classes" />
</classpath>
</javac>
并且应该为每个ivy依赖项定义范围。像这样:
<!-- Compile time-->
<dependency org="log4j" name="log4j" rev="1.2.14" conf="compile->*"/>
<!-- test time-->
<dependency org="log4j" name="log4j" rev="1.2.14" conf="test->*"/>