Hi Everyone
I was trying to build a sample war file and deploy it on a tomcat server. But, I'm facing this error of testNG unable to find class in the classpath. But I am pretty sure I have mentioned the right class path.
Here is my testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="User Registration suite 1" verbose="1" >
<test name="Regression suite 1" >
<classes>
<class name="com.vaannila.domain.UserTest"/>
</classes>
</test>
</suite>
Here is my UserTest.java class:
package com.vaannila.domain;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;
//Java imports
import java.util.concurrent.TimeUnit;
import java.util.List;
public class UserTest {
private WebDriver driver;
private String baseUrl;
@BeforeTest
@Test
@AfterTest
}
Here is my build.xml file:
<?xml version="1.0" ?>
<project name="UserRegistrationAnt" default="war" basedir="." xmlns:sonar="antlib:org.sonar.ant">
<!-- Beginning of project dir definition -->
<property name="testng.xml.file" value="testng.xml" />
<property name="basedir" location="." />
<property name="src" location="${basedir}/src" />
<property name="lib" location="${basedir}/WebContent/WEB-INF/lib" />
<property name="build" location="${basedir}/target/classes" />
<property name="war-file" location="${basedir}/dist" />
<property name="test-reports" location="{basedir}/test-reports" />
<!-- End of project dir definition -->
<!-- Beginning of sonar properties definition -->
<property name="sonar.host.url" value="http://xx.xx.x.xxx:9000" />
<property name="sonar.projectKey" value="9bc89a6e0d659c33ef4b61b27dc486b1f9075241" />
<property name="sonar.projectName" value="9bc89a6e0d659c33ef4b61b27dc486b1f9075241" />
<property name="sonar.projectVersion" value="1.0" />
<property name="sonar.language" value="java" />
<property name="sonar.sources" value="${src}" />
<property name="sonar.java.binaries" value="${build}" />
<property name="sonar.sourceEncoding" value="UTF-8" />
<!-- End of sonar properties definition -->
<!-- Definition of external dependencies location -->
<path id="compile.classpath">
<fileset dir="${lib}">
<include name="*.jar"/>
</fileset>
</path>
<!-- Making dirs for compiled, war file and test reports-->
<target name="init">
<mkdir dir="${build}"/>
<mkdir dir="${war-file}" />
<mkdir dir="${test-reports}" />
</target>
<!-- Compilation of our source and test code -->
<target name="compile" depends="init" >
<javac destdir="${build}" debug="true" srcdir="${src}" classpathref="compile.classpath" includeantruntime="false" />
</target>
<!-- Execution of testng -->
<taskdef name="testng" classname="org.testng.TestNGAntTask" classpathref="compile.classpath" />
<target name="tests" depends="compile">
<testng outputdir="${test-reports}" classpathref="compile.classpath" haltOnFailure="true">
<classpath location="{build}" />
<xmlfileset dir="${basedir}" includes="${testng.xml.file}" />
</testng>
</target>
<!-- Execution of sonar analysis -->
<target name="sonar" depends="compile">
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- update the following line or put sonar-ant-task-*.jar in $ANT_HOME/.ant/lib folder -->
<classpath path="/opt/ant/apache-ant-1.10.5/lib/sonarqube-ant-task-2.5.jar" />
</taskdef>
<!-- Execute SonarQube scanner for ant analysis -->
<sonar:sonar />
</target>
<target name="war" depends="compile">
<war destfile="{war-file}/AntExample.war" webxml="WebContent/WEB-INF/web.xml">
<fileset dir="${basedir}/WebContent"/>
<lib dir="${lib}"/>
<classes dir="${build}"/>
</war>
</target>
<!--target name="clean">
<delete dir="dist" />
<delete dir="build" />
<delete dir="reports" />
</target-->
<target name="all" depends="init, compile, tests, sonar, war" description="one single target to fire up every ant build stage" />
</project>
I am completely blank about this error, and have referred this link but my builds are happening without a glitch in eclipse IDE and cmd.exe. The build is failing in Atlassian bamboo CI server with the aforementioned error. So that issue and mine are completely different. I can't clean and do a build in a CI server.
Should I place testng jar in ANT_HOME/lib folder? Will that resolve this issue?
I need help on resolving this error.
Regards
Aditya
It was a silly mistake on my end. I didn't insert $ before {build} in tests target.
Hi,
I am getting the same error when I run my tests from bamboo. Tried few options but not able to resolve it.
Could you please help?..I am stuck and need help immediately.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.