Can I run TestNG using Command Prompt

0 votes
I want to run TestNG using command prompt. How can I do it?
Jun 19, 2019 in Selenium by Himanshi
2,325 views

1 answer to this question.

+1 vote

Hey Himanshi, you can run testNG with command prompt by using following line of commands:

C:\Users\Admin\Desktop\Ruksar\workspace\TestNG

set classpath=C:\Users\Admin\Desktop\Ruksar\workspace\TestNG\bin;C:\Users\Admin\Desktop\Ruksar\workspace\TestNG\lib\*
 
java org.testng.TestNG C:\Users\Admin\Desktop\Ruksar\workspace\TestNG\testng.xml
answered Jun 19, 2019 by Abha
• 28,020 points
Hi,

I've tried this so  many time but I keep getting a same error.  Can you please help.  I've read all the posts I can find online, but nothing is helping.

C:\Eclipse\WorkSpace\TestingPractice>set classpath=C:\Eclipse\WorkSpace\TestingPractice\bin\;C:\Eclipse\WorkSpace\TestingPractice\lib\*
C:\Eclipse\WorkSpace\TestingPractice>java org.testng.TestNG C:\Eclipse\WorkSpace\TestingPractice\testng.xml

Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Stage
        at org.testng.internal.Configuration.<init>(Configuration.java:33)
        at org.testng.TestNG.init(TestNG.java:216)
        at org.testng.TestNG.<init>(TestNG.java:200)
        at org.testng.TestNG.privateMain(TestNG.java:1312)
        at org.testng.TestNG.main(TestNG.java:1304)
Caused by: java.lang.ClassNotFoundException: com.google.inject.Stage
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        ... 5 more

Add the google-guice-core dependency in the pom.xml.

<dependency>
    <groupId>com.google.inject</groupId>
    <artifactId>guice</artifactId>
    <version>4.1.0</version>
</dependency>

or download the jar here and add it to the classpath.

Thank you so much for a quick reply.  I'm very new to selenium, I have not used maven yet.  Can we not run testng file from command line without using maven?

Thanks again
Thank you so much for assisting, I didn't have to have POM.xml but I did need to download the guice-4.2.2.jar and add it to lib folder.  Once I did that, it worked.

Once again thank you.

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

How can I run/debug pytest script using eclipse?

Hi Amish, to run/debug pytest scripts in ...READ MORE

answered Aug 23, 2019 in Selenium by Abha
• 28,020 points
920 views
+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13, 2020 in Selenium by Karan
• 19,590 points
3,813 views
0 votes
1 answer

How can I run test cases in parallel using Keyword Driven Framework?

One solution to try for executing test ...READ MORE

answered Jun 29, 2020 in Selenium by Alexander
565 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,010 points
1,101 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,520 points
4,912 views
0 votes
1 answer

Diff between WebDriver listeners and TestNG listeners?

This is not a very important concept ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,710 points
2,978 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,010 points
5,709 views
0 votes
1 answer
0 votes
1 answer

How can I send some data to a Prompt Alert box using Selenium Webdriver?

Hey Abhishek, you can use sendKeys() method ...READ MORE

answered Jul 2, 2019 in Selenium by Abha
• 28,020 points
3,973 views