Question

I've created a suite of TestNG tests that I'm attempting to run from an Ant task using Selenium Grid. I've tried to set the classpath in Ant, including the TestNG jar and some other required jars (the tests are Selenium tests). This is modified slightly from the Selenium Grid demo to reflect locations in my environment.

<path id="runtime.classpath">
   <pathelement path="${java.class.path}/" />
    <fileset dir="C:\Tools\selenium-grid-1.0.8\vendor">
        <include name="selenium-java-client-driver-${selenium.version}.jar"/>
       <include name="testng-5.7-jdk15.jar"/>
        <include name="commons-logging-1.0.4.jar"/>
    </fileset>
    <fileset dir="${test.location}">
        <include name="**/*.java" />
    </fileset>
    <pathelement location="${grid.location}/lib/selenium-grid-tools-standalone-${grid.version}.jar" />
</path>

TestNG starts, but immediately fails with an error:

     [java] ===============================================
     [java] Selenium Tests
     [java] Total tests run: 0, Failures: 0, Skips: 0
     [java] ===============================================
     [java]
     [java] [ERROR]:
     [java] Cannot find class in classpath: TestName

test.location is currently pointing to the src folder for the tests. Changing the test.location to contain the bin directory and changing the name attribute to **/*.class doesn't make a difference; the error is the same.

I can run this suite successfully from the Eclipse plugin, so I know the test suite file is ok. I'm working to get it running in Ant to ensure that Selenium Grid actually is distributing the tests properly to the Selenium Remote Controls.

Was it helpful?

Solution

Rather than setting the classpath to point at the individual class files, set it to point at the parent directory.

Instead of

<fileset dir="${test.location}">
    <include name="**/*.java" />
</fileset>

try

<pathelement path="${test.location}" />

(although you may need to change this to point at the bin dir, not the src dir).

OTHER TIPS

i was caught with the same error on more than one instance. While exploring eclipse for solution, i stumbled into the Markers window (Main menu ->Windows -> Show View -> Markers) which said that my project (proj1, which i launched using Testng) is missing a required library, which was the case.

I was using an external java project (ext_proj) by attaching it as an external jar file in the build path of this project, proj1 (by pointing it to the ext_proj.jar which resides in ext_proj directory). I accidentally cleaned the (ext_proj) which wiped out the ext_proj.jar in it. I could not see the exact cause of this above error in the Console but only in the Markers window as i pointed above.

Once i made this ext_proj.jar available in proj1 this error was gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top