0
votes

I am using ANT and IVY to resolve the dependencies and build the project. I have to write a selenium test case, so I have included the selenium dependency in the IVY file as below:

<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2"/>

IVY is able to download the dependency, But When I compile the project using ANT it fails with the below error:

    cannot find symbol
    [javac] symbol  : class WebDriver
    [javac] location: class com.barclays.test.selenium.TestSelenium
    [javac]         WebDriver driver = new FirefoxDriver();

So could you please let me know anything I am missing.

EDIT:

part of 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>

And 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>

Same case with log4j as well. I have added the dependency, but when I tried to create a Logger object, eclipse doesn't list the log4j's logger when using code assist.

Thanks

1
please post the build.xml - WeMakeSoftware
It is bit big, so I have added the compile target - GuruKulki
<dependency org="org.seleniumhq.selenium" name="selenium-java" rev="2.48.2" conf="test-java->default"/> maybe? - Joop Eggen

1 Answers

0
votes

in your build.xml you're compiling the test classes not with the test classpath, but with compile classpath.

Classpathref should be set to 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>

and you should define the scope for each of the ivy dependencies. Like this:

 <!-- 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->*"/>