When i'm trying to run the test suite, am getting this exception. We are using maven project here and i am done with refreshing, cleaning, reinstalling testNG and then imported the maven projects but then also am getting the same exception. Please suggest any ways that am missing here.
Error console:
org.testng.TestNGException:
Cannot find class in classpath: EmpClass
at org.testng.xml.XmlClass.loadClass(XmlClass.java:81)
at org.testng.xml.XmlClass.init(XmlClass.java:73)
at org.testng.xml.XmlClass.<init>(XmlClass.java:59)
at org.testng.xml.TestNGContentHandler.startElement(TestNGContentHandler.java:543)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
at com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.emptyElement(XMLDTDValidator.java:766)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.java:1350)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2778)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:649)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:333)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.testng.xml.XMLParser.parse(XMLParser.java:39)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:17)
at org.testng.xml.SuiteXmlParser.parse(SuiteXmlParser.java:10)
at org.testng.xml.Parser.parse(Parser.java:168)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:311)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:88)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
This question is related to
java
selenium
selenium-webdriver
testng
I came across the same issue stated above today. **setting the class-path again in eclipse ** solved the issue .
In testng.xml file, remove "." from tag "" class name if you are not using packages.
I also got the same exception:
I tried the following steps:
In Eclipse> Project > Clean. (The Exception remained)
I ran another project(The testng.xml ran successfully)
After running another project, I ran the project in which I was getting the Exception, and fortunately it worked for me, with no errors.
I had similar issue and the project had some build errors. I did sudo -R 777 to the project and then I cleaned my project. After that it worked fine.
Hope it helps.
Make sure that your class is under src.
It happens when MAVEN is not installed locally on the system.
I faced the same issue when i cloned a Maven based Project from GIT and then as soon as I executed I got exception "Cannot Find Class In ClassPath : Class Name"
So i did a mvn clean test and found that maven is not installed locally.
After doing sudo apt install maven Maven got installed and i was able to Run the code
You have to edit your tests Runner xml file. See this example:
<test name="Employees Test">
<classes>
<class name="packagename.classname">
</class>
</classes>
</test>
In <class name="packagename.classname">
row you must enter your tests package name then name of class that you want to run.
Thanks and wish you all the best.
include the package name with class. It will remove your name. I also got the same issue but adding the package name with class fixed this issue.
I had the same error when tried to run my tests in a JSF project.
I´m using Eclipse IDE (kepler). So, I did "project > clean" and then ran the tests again of the same project.
It worked!
Project>>Clean and Maven>>Update Project worked for me
I had the same error. I cleaned the maven project then the problem was solved.
In my case I imported maven project as Default existing project in eclipse.After that I imported as maven project.That worked for me.
For me, the issue was because I excluded the test from compilation in the POM. My pom.xml looked like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testExcludes>
<exclude>com/mycompany/app/AppTest.java</exclude>
</testExcludes>
</configuration>
</plugin>
After removing the <exclude>
, I was able to run the tests in AppTest.java
again.
If you use IntelliJ IDEA, try the following:
This issue can be resolved by adding TestNG.class package to OnlineStore package as below
In my opinion if src has test/java/ folders then in build path out location should be like target/test-classes.
If src has main/java/ folders then in build path out location should be like target/classes.
I faced the similar issue on importing maven with testng project. This was solved by converting again into TestNg project by
right click on eclipse project > TestNG > Convert to TestNG
and replacing the existing testng.xml
file with the newly created. Clean and update the maven project with mvn install
Note: take backup of your testng.xml
I also had this issue.
I'm using IntelliJ IDEA.
I was using src/main/java
for configuration files and src/test/java
for test files.
Because of this testNG couldn't find the class path.
To prevent getting that error need to move all the files from src/main/java
to src/test/java
or vice versa.
Note: You have to specify class name along with packages as given below.
<suite name="testNGLearning">
<test name="simpleTest">
<classes>
<class name="testngTests.TestNGSimpleTest" />
<class name="testngTests.TestMessageUtil" />
</classes>
</test>
</suite>
Go to Project>Build Path>Configure Build Path>Libraries>Remove Error libraries
After Refresh project and run again program.
I had this same problem when I imported my project from one PC to another on IntelliJ IDEA.
Below Solution worked for me:
I also ran into the same problem with TestNG version 6.14.2
However, this was due to a foolish mistake on my end and there is no issue whatsoever with maven, testng or eclipse. What I was doing was -
For me the problem was very strange.
I have a testng.xml file at the root of my Eclipse project. When I changed the file through Eclipse, it wasn't changing the testng.xml file in my directory.
Turns out it made a copy of the folder into the eclipse workspace..
Hope this helps someone out
I had no problems with this until recently.
Now I had to move the suite's xml test file into the root of the project I was testing.
It may be that there is a setting to point at the classes I am testing, but I have not found it.
Got the IDE working again. The solution is quite funny - and even a re-install, and deleting the IDE does not fix it on windows. What you need to do in that case, is to go to the testNG run configurations - and delete them all. This is for the TestNG XML classpath error on windows OS. I am using spring tools suite 3.6.4.
Make certain that you delete all the configurations, make sure the project can build, and if there are no problems, the test should run now.
Regards -Anthony Toorie
You should create package first and then create new TestNG class under that package.
My 2 cents on the problem: I was experiencing the same problem, while some part of my path was in Cyrillic. So check the path to your project for special characters. Once I removed this, the problem was fixed
Let me share what worked for me:
When we do "mvn clean" - we are cleaning old compiled classes please lgo to ocation "your project directroy -> target " you will find this folder is getting cleaned because that's where MVN places it's compiled artifacts
Since it's already a MAVEN project then go to your project folder and open in command prompt. And issue "mvn clean" and then "mvn test" -> "mvn test" command will place all the compiled files under proper folders and then you can run your tests through TestNG or MAVEN itself.
Make sure you set up "M2_HOME" or "MAVEN_HOME" to your env path , sometime "MAVEN_HOME" doesn't work so add "M2_HOME" as well (google it for this set up)
Above suggestions worked for me so I wanted to share, good luck
For me it was that I added Skip Tests checkbox/flag in the Maven Build of the Project
Therefore the test classes weren't compiled and then weren't found by TestNG
I had the same issue when i was using selenium 3.11.xx dependency however my problem was resolved when i used selenium 3.4.x dependency.
Source: Stackoverflow.com