0

According to this question, I have created a batch file and created a scheduled task for it. However, it does not run at the time it was scheduled. I tried executing the script commenting the testng.xml line and see a space in the path of bin and lib.

Could this be the reason ? Any thoughts, please.

Here is my script :

set ProjectPath=C:\Users\workspace\RestAssured 
echo %ProjectPath%
set classpath=%ProjectPath%\bin;%ProjectPath%\Lib\*
echo %classpath%
java org.testng.TestNG %ProjectPath%\testng.xml

System thrown with the following classNotFoundException :

Error: Could not find or load main class org.testng.TestNG

Caused by: java.lang.ClassNotFoundException: org.testng.TestNG

Here is the error log :

C:\Users\eclipse-workspace\RestAssured>set classpath=C:\Users\eclipse-workspace\RestAssured \bin;C:\Users\eclipse-workspace\RestAssured \lib*

C:\Users\eclipse-workspace\RestAssured>echo C:\Users\eclipse-workspace\RestAssured \bin;C:\Users\eclipse-workspace\RestAssured \lib*

C:\Users\eclipse-workspace\RestAssured \bin;C:\Users\eclipse-workspace\RestAssured \lib*

C:\Users\eclipse-workspace\RestAssured>java org.testng.TestNG >

C:\Users\eclipse-workspace\RestAssured \testng.xml

Error: Could not find or load main class org.testng.TestNG

Caused by: java.lang.ClassNotFoundException: org.testng.TestNG

Build step 'Execute Windows batch command' marked build as failure

Here is the verbose of TestNG :

> ...
... TestNG 6.9.6 by C??dric Beust (cedric@beust.com)
...

[TestRunner] Running the tests in 'Rep' with parallel mode:tests
[RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@3857f613 priority: 10
[TestClass] Creating TestClass for [ClassImpl class=com.root.com.RepZmap]
[TestClass] Adding method RepZmap.ZmapTest()[pri:0, instance:null] on TestClass class com.root.com.RepZmap
[XmlMethodSelector] Including method com.root.com.sendEmailReport()
[XmlMethodSelector] Including method com.root.com.startTest()
[XmlMethodSelector] Including method com.root.com.endReport()
[XmlMethodSelector] Including method com.root.com.initializeValues()
[XmlMethodSelector] Including method com.root.com.reportHeader()
[XmlMethodSelector] Including method com.root.com.getResult()
[TestClass] Creating TestClass for [ClassImpl class=com.root.com.RepMir112]
[TestClass] Adding method RepMir112.MirTest()[pri:0, instance:null] on TestClass class com.root.com.RepMir112
[TestClass] Creating TestClass for [ClassImpl class=com.root.com.RepMir113]
[TestClass] Adding method RepMir113.Mir113Test(java.lang.String, java.lang.String, java.lang.String)[pri:0, instance:null] on TestClass class com.root.com.RepMir113
[XmlMethodSelector] Including method com.root.com.ZmapTest()
[XmlMethodSelector] Including method com.root.com.MirTest()
[XmlMethodSelector] Including method com.root.com.Mir113Test()
[TestNG] Running:
  C:\Users\mhuntik\eclipse-workspace\RestAssured\testng.xml

[SuiteRunner] Created 1 TestRunners
[ThreadUtil] Starting executor timeOut:2147483647ms workers:1 threadPoolSize:5
[[SuiteWorker]] Running XML Test 'Rep' in Parallel
[TestRunner] Running test Rep on 3  classes,  included groups:[] excluded groups:[]
===== Test class
com.root.com.RepZmap
  @BeforeClass RepZmap.initializeValues()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
  @BeforeMethod RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
    @Test RepZmap.ZmapTest()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
  @AfterMethod RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
======
===== Test class
com.root.com.RepMir112
  @BeforeClass RepMir112.initializeValues()[pri:0, instance:com.root.com.RepMir112@6631f5ca]
  @BeforeMethod RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir112@6631f5ca]
    @Test RepMir112.MirTest()[pri:0, instance:com.root.com.RepMir112@6631f5ca]
  @AfterMethod RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir112@6631f5ca]
======
===== Test class
com.root.com.RepMir113
  @BeforeClass RepMir113.initializeValues()[pri:0, instance:com.root.com.RepMir113@5ace1ed4]
  @BeforeMethod RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir113@5ace1ed4]
    @Test RepMir113.Mir113Test(java.lang.String, java.lang.String, java.lang.String)[pri:0, instance:com.root.com.RepMir113@5ace1ed4]
  @AfterMethod RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir113@5ace1ed4]
======
[Invoker 1303063064] Keeping method RepUtils.startTest()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class null
[Invoker 1303063064] Invoking @BeforeTest RepUtils.startTest()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
[Invoker 1303063064] Keeping method RepZmap.initializeValues()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class [TestClass name=class com.root.com.RepZmap]
[Invoker 1303063064] Invoking @BeforeClass RepZmap.initializeValues()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
[Invoker 1303063064] Keeping method RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class [TestClass name=class com.root.com.RepZmap]
[Invoker 1303063064] Keeping method RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class [TestClass name=class com.root.com.RepZmap]
[Invoker 1303063064] Keeping method RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class [TestClass name=class com.root.com.RepZmap]
[Invoker 1303063064] Invoking @BeforeMethod RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
[Invoker 1303063064] Invoking com.root.com.RepZmap.ZmapTest
--------- Sending IPs To Receiver --------------------
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.poi.openxml4j.util.ZipSecureFile$1 (file:/C:/Users/mhuntik/eclipse-workspace/RestAssured/lib/fillo-1.18.jar) to field java.io.FilterInputStream.in
WARNING: Please consider reporting this to the maintainers of org.apache.poi.openxml4j.util.ZipSecureFile$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[Invoker 1303063064] Keeping method RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class [TestClass name=class com.root.com.RepZmap]
[Invoker 1303063064] Invoking @AfterMethod RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
[Invoker 1303063064] Keeping method RepMir112.initializeValues()[pri:0, instance:com.root.com.RepMir112@6631f5ca] for class [TestClass name=class com.root.com.RepMir112]
[Invoker 1303063064] Invoking @BeforeClass RepMir112.initializeValues()[pri:0, instance:com.root.com.RepMir112@6631f5ca]
[Invoker 1303063064] Keeping method RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir112@6631f5ca] for class [TestClass name=class com.root.com.RepMir112]
[Invoker 1303063064] Keeping method RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir112@6631f5ca] for class [TestClass name=class com.root.com.RepMir112]
[Invoker 1303063064] Keeping method RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir112@6631f5ca] for class [TestClass name=class com.root.com.RepMir112]
[Invoker 1303063064] Invoking @BeforeMethod RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir112@6631f5ca]
[Invoker 1303063064] Invoking com.root.com.RepMir112.MirTest
--------- Sending IPs To Receiver --------------------
[Invoker 1303063064] Keeping method RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir112@6631f5ca] for class [TestClass name=class com.root.com.RepMir112]
[Invoker 1303063064] Invoking @AfterMethod RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir112@6631f5ca]
[Invoker 1303063064] Keeping method RepMir113.initializeValues()[pri:0, instance:com.root.com.RepMir113@5ace1ed4] for class [TestClass name=class com.root.com.RepMir113]
[Invoker 1303063064] Invoking @BeforeClass RepMir113.initializeValues()[pri:0, instance:com.root.com.RepMir113@5ace1ed4]
[Invoker 1303063064] Keeping method RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir113@5ace1ed4] for class [TestClass name=class com.root.com.RepMir113]
[Invoker 1303063064] Keeping method RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir113@5ace1ed4] for class [TestClass name=class com.root.com.RepMir113]
[Invoker 1303063064] Keeping method RepUtils.endReport()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class null
[Invoker 1303063064] Invoking @AfterTest RepUtils.endReport()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
===== Invoked methods
  RepUtils.startTest()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] 1607792885
  RepZmap.initializeValues()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] 1607792885
  RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]public void com.root.com.RepZmap.ZmapTest() throws java.lang.Throwable  1607792885
    RepZmap.ZmapTest()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] 1607792885
  RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepZmap@5fd4f8f5][TestResult name=ZmapTest status=FAILURE method=RepZmap.ZmapTest()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] output={null}]  1607792885
  RepMir112.initializeValues()[pri:0, instance:com.root.com.RepMir112@6631f5ca] 1714550218
  RepUtils.reportHeader(java.lang.reflect.Method)[pri:0, instance:com.root.com.RepMir112@6631f5ca]public void com.root.com.RepMir112.MirTest() throws java.lang.Throwable  1714550218
    RepMir112.MirTest()[pri:0, instance:com.root.com.RepMir112@6631f5ca] 1714550218
  RepUtils.getResult(org.testng.ITestResult)[pri:0, instance:com.root.com.RepMir112@6631f5ca][TestResult name=MirTest status=FAILURE method=RepMir112.MirTest()[pri:0, instance:com.root.com.RepMir112@6631f5ca] output={null}]  1714550218
  RepMir113.initializeValues()[pri:0, instance:com.root.com.RepMir113@5ace1ed4] 1523457748
  RepUtils.endReport()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] 1607792885
=====
Creating C:\Users\mhuntik\eclipse-workspace\RestAssured\test-output\Repute\Rep.html
Creating C:\Users\mhuntik\eclipse-workspace\RestAssured\test-output\Repute\Rep.xml
FAILED: ZmapTest
java.lang.NoSuchFieldError: DEF_CONTENT_CHARSET
        at io.restassured.config.EncoderConfig.<init>(EncoderConfig.java:61)
        at io.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
        at io.restassured.RestAssured.<clinit>(RestAssured.java:420)
        at com.root.com.RepZmap.ZmapTest(RepZmap.java:44)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:773)
        at org.testng.TestRunner.run(TestRunner.java:623)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
        at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:391)
        at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

FAILED: MirTest
java.lang.NoClassDefFoundError: Could not initialize class io.restassured.RestAssured
        at com.root.com.RepMir112.MirTest(RepMir112.java:44)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:821)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1131)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:773)
        at org.testng.TestRunner.run(TestRunner.java:623)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
        at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:391)
        at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)

SKIPPED: Mir113Test
java.lang.RuntimeException: java.lang.NoClassDefFoundError: jxl/Workbook
        at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:162)
        at org.testng.internal.Parameters.handleParameters(Parameters.java:430)
        at org.testng.internal.Invoker.handleParameters(Invoker.java:1276)
        at org.testng.internal.Invoker.createParameters(Invoker.java:992)
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1082)
        at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:124)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
        at org.testng.TestRunner.privateRun(TestRunner.java:773)
        at org.testng.TestRunner.run(TestRunner.java:623)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:357)
        at org.testng.SuiteRunner.access$000(SuiteRunner.java:39)
        at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:391)
        at org.testng.internal.thread.ThreadUtil$2.call(ThreadUtil.java:64)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: jxl/Workbook
        at com.root.com.RepMir113.getExcelData(RepMir113.java:36)
        at com.root.com.RepMir113.createSourceIPs(RepMir113.java:57)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
        at org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:136)
        ... 16 more
Caused by: java.lang.ClassNotFoundException: jxl.Workbook
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
        at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
        ... 24 more


===============================================
    Rep
    Tests run: 3, Failures: 2, Skips: 1
===============================================

[Invoker 2014461570] Keeping method RepUtils.sendEmailReport()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5] for class null
[Invoker 2014461570] Invoking @AfterSuite RepUtils.sendEmailReport()[pri:0, instance:com.root.com.RepZmap@5fd4f8f5]
Mail sent successfully...

===============================================
Repute
Total tests run: 3, Failures: 2, Skips: 1
===============================================
user1911509
  • 133
  • 4
  • 13
  • I do not understand what is wrong with the question, I was given negative marks. Asking questions in this forum gets minus marks. – user1911509 Sep 05 '18 at 22:10

1 Answers1

2

Do you really have directory called "Lib"? I'm expecting "lib" to be there because windows is a case sensitive os.

RocketRaccoon
  • 2,559
  • 1
  • 21
  • 30
  • Sorry, that was my bad, I did modified it to "lib" and worked on it. However, it is still throwing the same exception : java.lang.ClassNotFoundException: org.testng.TestNG. After searching on the web for quite some time, I found that the lib folder should contain reference jars, which I have added them in the lib folder, but still no luck. Any thoughts ? Also, the console is printing as below when echo command is run : C:\Users\eclipse-workspace\RestAssured \bin; C:\Users\eclipse-workspace\RestAssured \lib\* There is a gap in the path before \bin and \lib. – user1911509 Sep 06 '18 at 19:54
  • When you set ProjectPath you add this white space 'ProjectPath=C:\Users\workspace\RestAssured ' take a look on the example – RocketRaccoon Sep 07 '18 at 11:04
  • I am able to run the batch file successfully. However, the test cases are not passing due to Illegal reflective access. I have edited my question and posted the error log in the questions. – user1911509 Sep 08 '18 at 06:46
  • What version of Java do you use - 8 or newer? Also it is a warning, not an error. There should be something else. – RocketRaccoon Sep 08 '18 at 07:02
  • I am using the Java Version 9. java version "9.0.1" Java(TM) SE Runtime Environment (build 9.0.1+11) Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode) – user1911509 Sep 08 '18 at 21:07
  • Try to run it with Java 8. Any way it would be useful if could share reproducible example. – RocketRaccoon Sep 08 '18 at 22:01
  • I ran it and tried a lot to troubleshoot with no luck, it still throws the same error. Class not found for TestNG. In fact, just by executing the testng.xml file, runs. I don't see any problems. However, when executing the batch file, the system throws the error. – user1911509 Sep 11 '18 at 18:19
  • Are you sure that you have TestNG in your classpath? Also try to use verbose option to get additional info. – RocketRaccoon Sep 11 '18 at 18:35
  • Yes, I have two of them in my classpath. I am using Extent Reports so my classpath has testng-6.9.9.jar file and before using Extent Reports, I have used testng-6.9.4.jar file. Both the files are in my classpath. – user1911509 Sep 11 '18 at 18:46
  • And what verbose says? – RocketRaccoon Sep 11 '18 at 20:26
  • Sorry, I have just added the verbose, I have set it to 10, it maybe too much but just wanted to get more information from the script that I am running. I have posted below the original question. – user1911509 Sep 11 '18 at 22:08
  • As I see rest-assured and jxl are missed in your classpath. If you could share somehow your project directly to me it will dramatically speed up investigation. – RocketRaccoon Sep 12 '18 at 06:21
  • Sure, I can share using TeamViewer. I was trying to debug the program and also trying to change the directory by creating a folder and put all the jars into that folder to reload into classpath. However, I got the - Java platform se binary has stopped working followed by "An out of memory error has occurred. Consult the "Running Eclipse" section of the read me file for information on preventing this kind of error ....." I was recommended to exit workbench. So, I was trying to figure out the problem. Can you please share your email id, I can send the invite ? – user1911509 Sep 12 '18 at 06:45
  • What is the best time to send the invite ? – user1911509 Sep 12 '18 at 06:54
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/179876/discussion-between-rocketraccoon-and-user1911509). – RocketRaccoon Sep 12 '18 at 06:57
  • Sure, Thank you. I am in US w/Time Zone PST. I see that you are in Russia. What time best works for you in chat ? – user1911509 Sep 12 '18 at 16:19
  • I have solved it using batch file method and CI/CD Building in Jenkins. The problem that I have is with the eclipse and not with my code. For some reason, eclipse Oxygen version has a bug to identify it's own project jar files. Thank you very much for your time and help. – user1911509 Sep 27 '18 at 18:56