【问题标题】:Batch file for testng.xml does not run as scheduledtestng.xml 的批处理文件未按计划运行
【发布时间】:2018-09-05 21:56:01
【问题描述】:

According to this question,我已经创建了一个批处理文件并为它创建了一个计划任务。但是,它不会在计划的时间运行。 我尝试执行注释 testng.xml 行的脚本,并在 bin 和 lib 的路径中看到一个空格。

这可能是原因吗?有什么想法,请。

这是我的脚本:

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

系统抛出以下 classNotFoundException :

错误:无法找到或加载主类 org.testng.TestNG

原因:java.lang.ClassNotFoundException: org.testng.TestNG

这是错误日志:

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

C:\Users\eclipse-workspace\RestAssured>回显 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

错误:无法找到或加载主类 org.testng.TestNG

原因:java.lang.ClassNotFoundException: org.testng.TestNG

构建步骤“执行 Windows 批处理命令”将构建标记为失败

这里是 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
===============================================

【问题讨论】:

  • 我不明白这个问题有什么问题,我被给了负分。在此论坛中提问会得到减分。

标签: java shell testng


【解决方案1】:

你真的有名为“Lib”的目录吗?我期待“lib”在那里,因为 windows 是一个区分大小写的操作系统。

【讨论】:

  • 对不起,那是我的错,我确实将其修改为“lib”并进行了处理。但是,它仍然抛出相同的异常:java.lang.ClassNotFoundException: org.testng.TestNG。在网上搜索了一段时间后,我发现lib文件夹应该包含参考jar,我已经将它们添加到lib文件夹中,但仍然没有运气。有什么想法吗 ?此外,运行 echo 命令时,控制台打印如下: C:\Users\eclipse-workspace\RestAssured \bin; C:\Users\eclipse-workspace\RestAssured \lib* \bin 和 \lib 之前的路径有间隙。
  • 当你设置 ProjectPath 时,你会添加这个空格 'ProjectPath=C:\Users\workspace\RestAssured' 看看这个例子
  • 我能够成功运行批处理文件。但是,由于非法反射访问,测试用例没有通过。我已经编辑了我的问题并在问题中发布了错误日志。
  • 您使用什么版本的 Java - 8 或更高版本?这也是一个警告,而不是错误。应该还有别的。
  • 我使用的是 Java 版本 9。java 版本 "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,混合模式)
猜你喜欢
  • 1970-01-01
  • 2013-03-01
  • 1970-01-01
  • 2014-09-14
  • 2014-03-15
  • 1970-01-01
  • 2019-04-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多