Ionutz Asaftei
Ionutz Asaftei

Reputation: 37

ChromeDriver does not start through CMD with "testng.xml"

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

Upvotes: 1

Views: 1356

Answers (3)

Conor
Conor

Reputation: 395

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

Upvotes: 0

user3270646
user3270646

Reputation: 1

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.

Upvotes: 0

Krishnan Mahadevan
Krishnan Mahadevan

Reputation: 14736

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).

Upvotes: 0

Related Questions