1

I was trying to run a TestNG.xml file from CMD but there are no errors shown and it seems that ChromeDriver is not starting.

Note: if i go to Eclipse -> right click on testng.xml -> run as TestNG suite it will work perfectly.

  1. Below is the message i get when executing through cmd. enter image description here

  2. The bat file contains: java -cp "D:\Java Applications\WebDriverProject\lib*;D:\Java Applications\WebDriverProject\bin" org.testng.TestNG testng.xml pause

  3. The testng.xml contains:

enter image description here

  1. The project structure from eclipse is: enter image description here
James Z
  • 12,209
  • 10
  • 24
  • 44
  • Where is the package declaration in your code? – randominstanceOfLivingThing Jan 21 '18 at 17:13
  • Sorry, the image captured by me does not include the package declaration, but the declaration is in the code (just a little bit higher). – Ionutz Asaftei Jan 21 '18 at 17:26
  • 2
    Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Jan 21 '18 at 18:18
  • You need to include the path to the compiled test classes in the classpath also. Classes would be inside the target folder... – Grasshopper Jan 21 '18 at 20:00
  • @IonutzAsaftei - Any reason why you are resorting to running tests via `java -cp` on a maven project (i noticed you have a `pom.xml` in your project) instead of just using `mvn clean test` ? – Krishnan Mahadevan Jan 22 '18 at 03:37
  • Hi @Grasshopper , could you tell me how to do it please (an example would help a lot) ? – Ionutz Asaftei Jan 22 '18 at 10:00
  • Hello @KrishnanMahadevan , i wanted to run it through TestNG (it's more used in IT industry around here) but you can tell me also how to do it in Maven through CMD (important thing is to make it work). Thank you ! – Ionutz Asaftei Jan 22 '18 at 10:02
  • @IonutzAsaftei Hey, I figured it out finally. My proposed solution is below, please check. – Conor Feb 12 '20 at 12:42

3 Answers3

0

Running your tests using Maven (Recommended way)

From your screenshot I am inferring that yours is a maven project. Maven is a build tool that helps with building java code, running tests etc., in an easy fashion. But it looks like you haven't imported your project into eclipse as a Maven project.

So if you would like to run your tests via Maven, you would need to do the following :

  1. Remove your project from the workspace (delete it from the workspace but not from the file system). Refer here to learn how to do it.
  2. Now remove the following files from your project folder manually :
    1. .settings (I think this should be a folder)
    2. .classpath
    3. .project If you have already setup Maven properly in your machine (Refer here to learn how to do that), you can easily clean up the eclipse related files by opening up a command prompt, using cd command to navigate into your project directory such that dir pom.xml lists the pom.xml and then running the command mvn eclipse:clean
  3. Now refer to this StackOverFlow post to learn how to import a maven project into eclipse and import the project into eclipse.
  4. You now have your project configured properly so that eclipse recognizes your project as a maven project. Now to run the tests from the command prompt, (refer to surefire documentation to learn how to add surefire plugin to your pom file) run mvn clean test

Running your tests from command prompt

For running your project without using any build tool, you just need to append target\test-classes and target\classes directories to your java -cp command run it. So your modified batch file can look like below

java -cp "D:\Java Applications\WebDriverProject\lib*;D:\Java Applications\WebDriverProject\bin;D:\Java Applications\WebDriverProject\target\classes;D:\Java Applications\WebDriverProject\target\test-classes" org.testng.TestNG testng.xml
pause

On a side note, please add verbose="2" or higher to the <suite> tag in your suite xml file, so that it shows you what error occurred.

Also please ensure that your testng.xml resides under src\test\resources folder (you can very well create this folder if it doesn't exist).

Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
0

well try to put TestNG.jar file https://mvnrepository.com/artifact/org.testng/testng/6.7 and jcommander jar https://mvnrepository.com/artifact/com.beust/jcommander/1.7 in lib folder.

0

I figured this out. First of all, how you set up the classpath environment is crucial. The very first path must be a path to your project bin folder (where the .class files are found). I will just paste what my classpath environment looks like:

set classpath=C:\eclipse-2018\ACR_Tests\bin;C:\Selenium_dependencies\*;C:\TestNG\plugins\*

Set TestNG classpath:

java -classpath %classpath% org.testng.TestNG testng.xml

Note: I have a "Selenium dependencies" folder also added to the classpath, this is a folder containing more selenium libraries, including chromedriver.jar

Download the zipped package:

selenium-chrome-driver JAR 3.12.0

It contains the dependencies that you need.

https://jar-download.com/artifacts/org.seleniumhq.selenium/selenium-chrome-driver/3.12.0/source-code

Extract all to a folder. In my case I called it "Selenium_dependencies".

Also, for TestNG libraries I'm using 7.0.0 release which you can download here:

http://dl.bintray.com/testng-team/testng-eclipse-release/zipped/

My testng.xml is like so:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite">
  <test thread-count="5" name="Test">
    <classes>
      <class name="P1.ACR_Server"/> <!-- package.class -->
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Also - ensure that you have client-combined.jar included on the build path.

The build path should contain these libraries:

enter image description here

Conor
  • 327
  • 6
  • 15