TestNG Errors - Running TestNG via Command Line

1,348 views
Skip to first unread message

Rii Rii

unread,
Apr 1, 2021, 3:49:02 PM4/1/21
to testng-dev
Hello Everyone,

Please can someone help, I have a very simple testNG project which I am running via intelliJ and its execution is successful, I can't find any solution to the errors that I am presented with, I suspect it is configuration related somewhere.

When I attempt to run this via command line, I see the following errors, how do I manage this?, this is the result on command line I am not sure how to disable these things

C:\Program Files\Java\jdk1.8.0_201\bin>java org.testng.TestNG C:\Users\myUser\IdeaProjects\JAVATestNGProject\testng.xml
[TestHTMLReporter] The system cannot find the path specified

===============================================
setup
Total tests run: 1, Failures: 1, Skips: 0
===============================================

java.io.FileNotFoundException: test-output\testng.css (The system cannot find the path specified)
        at java.io.FileOutputStream.open0(Native Method)
        at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
        at org.testng.internal.Utils.writeResourceToFile(Utils.java:465)
        at org.testng.reporters.HtmlHelper.generateStylesheet(HtmlHelper.java:25)
        at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:54)
        at org.testng.TestNG.generateReports(TestNG.java:1097)
        at org.testng.TestNG.run(TestNG.java:1022)
        at org.testng.TestNG.privateMain(TestNG.java:1354)
        at org.testng.TestNG.main(TestNG.java:1323)
[Utils] [ERROR] The system cannot find the path specified
java.io.IOException: The system cannot find the path specified
        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
        at java.io.File.createNewFile(File.java:1012)
        at org.testng.internal.Utils.writeUtf8File(Utils.java:111)
        at org.testng.reporters.XMLReporter.generateReport(XMLReporter.java:72)
        at org.testng.TestNG.generateReports(TestNG.java:1097)
        at org.testng.TestNG.run(TestNG.java:1022)
        at org.testng.TestNG.privateMain(TestNG.java:1354)
        at org.testng.TestNG.main(TestNG.java:1323)
[EmailableReporter2] [ERROR] Unable to create output file
java.nio.file.NoSuchFileException: test-output\emailable-report.html
        at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:79)
        at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
        at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
        at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(WindowsFileSystemProvider.java:230)
        at java.nio.file.spi.FileSystemProvider.newOutputStream(FileSystemProvider.java:434)
        at java.nio.file.Files.newOutputStream(Files.java:216)
        at java.nio.file.Files.newBufferedWriter(Files.java:2860)
        at org.testng.reporters.EmailableReporter2.createWriter(EmailableReporter2.java:80)
        at org.testng.reporters.EmailableReporter2.generateReport(EmailableReporter2.java:57)
        at org.testng.TestNG.generateReports(TestNG.java:1097)
        at org.testng.TestNG.run(TestNG.java:1022)
        at org.testng.TestNG.privateMain(TestNG.java:1354)
        at org.testng.TestNG.main(TestNG.java:1323)
java.io.FileNotFoundException: test-output\jquery-1.7.1.min.js (The system cannot find the path specified)
        at java.io.FileOutputStream.open0(Native Method)
        at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at java.io.FileOutputStream.<init>(FileOutputStream.java:162)
        at org.testng.reporters.Files.copyFile(Files.java:50)
        at org.testng.reporters.jq.Main.generateReport(Main.java:85)
        at org.testng.TestNG.generateReports(TestNG.java:1097)
        at org.testng.TestNG.run(TestNG.java:1022)
        at org.testng.TestNG.privateMain(TestNG.java:1354)
        at org.testng.TestNG.main(TestNG.java:1323)

Here my POM configuration:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value<!-- disabling default listeners is optional -->
</property>
<property>
<name>generateTestResultAttributes</name>
<value>false</value>
</property>
<property>
<name>reporter</name>
<value>org.testng.reporters.XMLReporter</value>
</property>
</properties>
</configuration>
</plugin>
</plugins>
</build>

⇜Krishnan Mahadevan⇝

unread,
Apr 2, 2021, 12:42:47 AM4/2/21
to testn...@googlegroups.com
I asked for a sample project that you can share to help us find out what exactly is going on in your other thread that you posted on the TestNG-users forum : https://groups.google.com/g/testng-users/c/VgGLesPthlU/m/nxPNiFLPCgAJ 

Either ways, it looks like you may be facing permission issues.

You seem to be running your tests from your JDK bin directory

C:\Program Files\Java\jdk1.8.0_201\bin>java org.testng.TestNG C:\Users\myUser\IdeaProjects\JAVATestNGProject\testng.xml
[TestHTMLReporter] The system cannot find the path specified

Perhaps you dont have permission to create directory (TestNG will attempt to create a test-output in the JDK bin folder) in the current directory from where execution is happening.

To check this theory, see if you have a test-output folder created. If its not there, try running the same command as an administrator (or any other user who would have permission to create folders in the JDK bin directory).

To fix this you should be doing the following:

cd C:\Users\myUser\IdeaProjects\JAVATestNGProject
java org.testng.TestNG testng.xml

Last but not the least:
If your intent is just to run tests, I would strongly encourage you to start leveraging a build tool such as Gradle/Maven to do that for you instead of you trying to manage your CLASSPATH and run tests in this fashion.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/


--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/testng-dev/e83c59a2-13f6-4a6a-a528-e73af5b705c5n%40googlegroups.com.

Rii Rii

unread,
Apr 6, 2021, 3:35:06 AM4/6/21
to testng-dev
Thank you Krishnan, I will double check these things that you have mentioned.

Rii Rii

unread,
Apr 6, 2021, 4:20:17 AM4/6/21
to testng-dev
I am in the process of sharing the sample project, currently uploading to google drive.

My intent is to integrate this project with Jenkins, so I am first testing it via command line. I am already using Maven.

Thanks!
R

Rii Rii

unread,
Apr 6, 2021, 4:30:52 AM4/6/21
to testng-dev
Please see sample project;



>echo %CLASSPATH%
C:\Users\myUser\IdeaProjects\JAVATestNGProject\target\classes;C:\Users\myUser\IdeaProjects\JAVATestNGProject\lib\*

C:\Program Files\Java\jdk1.8.0_201\bin>java org.testng.TestNG C:\Users\myUser\IdeaProjects\JAVATestNGProject\testng.xml

[TestHTMLReporter] The system cannot find the path specified

===============================================
setup
Total tests run: 1, Failures: 1, Skips: 0
===============================================

java.io.FileNotFoundException: test-output\testng.css (The system cannot find the path specified)
        at java.io.FileOutputStream.open0(Native Method)



If I execute the TestNG project via IntelliJ idea, the project runs perfectly fine, I am missing something.

Regards,
R

Rii Rii

unread,
Apr 6, 2021, 3:41:10 PM4/6/21
to testng-dev
I was able to successfully execute on command line as per your suggestion, however you did mention that I should not be executing from the JDK location. I have tried running the execution from the project location but it seems the Java command is not recognized, is this something do to with my classpath?

C:\Program Files\Java\jdk1.8.0_201\bin>java org.testng.TestNG C:\Users\myUser\IdeaProjects\JAVATestNGProject\testng.xml
Starting ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294}) on port 22344
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Apr 06, 2021 9:38:04 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
test
test

===============================================
setup
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Rii Rii

unread,
Apr 8, 2021, 7:27:20 AM4/8/21
to testng-dev
Hi,

Can someone tell me when we execute testNG via command line. should all the classes be in one directory because my folder structure uses the IntelliJ structure and I only make reference to the root folder which will contain all sub-folders with the compiled classes, in theory should this setup still work?

My sample project works perfectly fine, but now I am trying with my actual project and it seems again I cannot find or load main class..please advise

⇜Krishnan Mahadevan⇝

unread,
Apr 9, 2021, 1:02:24 AM4/9/21
to testn...@googlegroups.com
You would usually resort to executing a piece of java code via batch files or shell scripts (typically called as startup scripts) when you would like to build a command line utility that you want someone else to basically just download and use.

I remember you mentioning that you would like your tests to run via Jenkins (A continuous integration tool). I noticed that your sample project is a maven project.

That brings me to the most important question.

Why are you not using the Maven Surefire plugin to run your tests ? If you use surefire plugin, all you would need to do is setup the goal "clean test" in your Jenkins build job and the rest of the things would be taken care of by Jenkins.

This is usually how most of the folks run their tests.

Your current approach of trying to setup your CLASSPATH on your own, kind of is like you trying to re-invent the wheel.

Build tools such as maven already manage all of this stuff for you.

So I would suggest that you please take sometime and go through this https://maven.apache.org/guides/getting-started/maven-in-five-minutes.html to get yourself oriented with maven in general.

Then you spend some time in going through https://www.softwaretestinghelp.com/integration-of-maven-with-testng-using-surefire-plugin/ to understand how to use maven surefire plugin.

This is going to save you a lot of time, rather than you trying to figure out how to setup your CLASSPATH and then create a shell script/batch file that can be used via Jenkins to trigger your tests.


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribblings @ https://rationaleemotions.com/

Rii Rii

unread,
Apr 9, 2021, 9:17:25 AM4/9/21
to testng-dev
Thank you for this, I will educate myself on the maven stuff that you provided, I don't have extensive experience in maven but highly appreciate the material.
Reply all
Reply to author
Forward
0 new messages