0

I am getting Testng FileNotFoundException when running from command line, following is the command line parameters i am using

java -cp MyTestAutomation-06252019.jar org.testng.TestNG ZaleniumMiniRegression.xml

Following is the stack-trace:

[SuiteHTMLReporter] [ERROR] test-output\testng.css (The system cannot find the path specified)
java.io.FileNotFoundException: test-output\testng.css (The system cannot find the path specified)
        at java.base/java.io.FileOutputStream.open0(Native Method)
        at java.base/java.io.FileOutputStream.open(FileOutputStream.java:292)
        at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:235)
        at java.base/java.io.FileOutputStream.<init>(FileOutputStream.java:185)
        at org.testng.internal.Utils.writeResourceToFile(Utils.java:263)
        at org.testng.reporters.HtmlHelper.generateStylesheet(HtmlHelper.java:32)
        at org.testng.reporters.SuiteHTMLReporter.generateReport(SuiteHTMLReporter.java:55)
        at org.testng.TestNG.generateReports(TestNG.java:1062)
        at org.testng.TestNG.run(TestNG.java:1005)
        at org.testng.TestNG.privateMain(TestNG.java:1326)
        at org.testng.TestNG.main(TestNG.java:1294)
baitmbarek
  • 2,440
  • 4
  • 18
  • 26
deepakguna
  • 145
  • 3
  • 16
  • 1
    Please show your code. – Federico klez Culloca Jan 20 '20 at 09:51
  • 1
    `test-output\testng.css` is a relative path. It is searched into your current working directory, which is where you launched the `java` command from. If the `test-output\testng.css` file isn't there you'll get that error. – Aaron Jan 20 '20 at 09:52
  • @Aaron test-output\ is the folder created by testNG itself, i am not sure why it is looking at that locaton. – deepakguna Jan 20 '20 at 10:13
  • Did you specify that path anywhere or is it a default of testNG? If you specified it yourself somewhere I'd check if it works better when rewritten as `test-ouput/testng.css`. Otherwise I'd also check that the user launching the `java` command can actually write into this directory – Aaron Jan 20 '20 at 10:25
  • @Aaron , No i didn't specify the path for output. It has no restrictions to write in to the current directory. – deepakguna Jan 20 '20 at 11:22
  • Someone reported having a [similar issue](https://stackoverflow.com/questions/10075209/testng-ant-task-fails-on-mac-os-x-with-error-no-test-suite-found?noredirect=1) when having an older version of testNG erroneously imported as a dependency, maybe that could be your problem? – Aaron Jan 20 '20 at 11:41
  • @Aaron Thank you , i will debug further and post any success here. My Testng version is 7.0.0 – deepakguna Jan 20 '20 at 12:50

1 Answers1

0

Assuming that you set up your classes properly in the XML file, you can try this:

Extract to a folder called TestNG on the C:\ directory

Set the classpath environment (TestNG folder and your Project folder)

Change directory (cd) into your project folder and then write these commands:

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

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

That's it.

If you've made a runnable jar file with a main method you could simply do:

java -jar <Your runnable jar file>.jar

If you run into trouble getting the webdriver to run from the command line, check my answer here: https://stackoverflow.com/a/60172758/1843452

Conor
  • 327
  • 6
  • 15