尝试使用命令提示符

时间:2018-05-04 01:24:58

标签: java testng

尝试使用命令提示符执行TestNG测试时,我遇到配置失败。我已经尝试使用堆栈溢出中给出的建议,但它不起作用。当我尝试使用eclipse直接执行时,测试成功运行。

这是我的命令

java -cp C:\Users\Admin\Downloads\daily-installer-automation-master\
daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\lib\*;C:\Users\Admin\
Downloads\daily-installer-automation-master\
daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources org.testng.TestNG C:\Users\Admin\Downloads\daily-installer-automation-master\
daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources\CreateUsers.xml

pause

这是我在执行后得到的

C:\Users\Admin\Desktop>java -cp C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\lib\*;C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources org.testng.TestNG C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources\CreateUsers.xml
[TestNG] Running:
  C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources\CreateUsers.xml


===============================================
Pre-requisite test
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================


C:\Users\Admin\Desktop>pause
Press any key to continue . . .

这是我的XML

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Pre-requisite test" verbose="1" configfailurepolicy="continue">

	
	<!-- yellowfin login credentials -->
	<parameter name="yellowfinURL" value="http://10.10.5.77:8082/" />
	<parameter name="userName" value="admin" />
	<parameter name="passsword" value="test" />

	
	<test name="CreateUsers">
		<classes>
			<class name="yellow.bi.test.CreateUsers">
				<methods>

					<include name="ImportUsers"></include>
					<!-- <include name=""></include> -->

				</methods>
			</class>
		</classes>
	</test>
</suite>

这是扩展日志

C:\Users\Admin\Desktop>java -cp C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\lib\*;C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources org.testng.TestNG -log 10 C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources\CreateUsers.xml
[TestRunner] Running the tests in 'CreateUsers' with parallel mode:none
[RunInfo] Adding method selector: org.testng.internal.XmlMethodSelector@527740a2 priority: 10
[TestClass] Creating TestClass for [ClassImpl class=yellowfin.bi.test.CreateUsers]
[TestClass] Adding method CreateUsers.ImportUsers(java.lang.String, java.lang.String)[pri:1, instance:null] on TestClass class yellowfin.bi.test.CreateUsers
[XmlMethodSelector] Including method yellowfin.bi.test.setUpTheTest()
[XmlMethodSelector] Including method yellowfin.bi.test.instantiatePages()
[XmlMethodSelector] Including method yellowfin.bi.test.ImportUsers()
[TestNG] Running:
  C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources\CreateUsers.xml

[Invoker 513169028] Keeping method CreateUsers.setUpTheTest()[pri:0, instance:yellowfin.bi.test.CreateUsers@614ddd49] for class null
[Invoker 513169028] Invoking @BeforeSuite CreateUsers.setUpTheTest()[pri:0, instance:yellowfin.bi.test.CreateUsers@614ddd49]
[TestNG] INVOKING CONFIGURATION: "UNKNOWN" - @BeforeSuite yellowfin.bi.test.CreateUsers.setUpTheTest()
Failed to invoke configuration method yellowfin.bi.test.CreateUsers.setUpTheTest:com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
[TestNG] FAILED CONFIGURATION: "UNKNOWN" - @BeforeSuite yellowfin.bi.test.CreateUsers.setUpTheTest() finished in 0 ms
[TestNG] java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
[TestNG]        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
[TestNG]        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
[TestNG]        at yellowfin.bi.test.CreateUsers.setUpTheTest(CreateUsers.java:52)
[TestNG]        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[TestNG]        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[TestNG]        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[TestNG]        at java.lang.reflect.Method.invoke(Unknown Source)
[TestNG]        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
[TestNG]        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
[TestNG]        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
[TestNG]        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
[TestNG]        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
[TestNG]        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
[TestNG]        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
[TestNG]        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
[TestNG]        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
[TestNG]        at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
[TestNG]        at org.testng.TestNG.runSuites(TestNG.java:1133)
[TestNG]        at org.testng.TestNG.run(TestNG.java:1104)
[TestNG]        at org.testng.TestNG.privateMain(TestNG.java:1434)
[TestNG]        at org.testng.TestNG.main(TestNG.java:1403)
[SuiteRunner] Created 1 TestRunners
[TestRunner] Running test CreateUsers on 1  classes,  included groups:[] excluded groups:[]
===== Test class
yellowfin.bi.test.CreateUsers
    @Test CreateUsers.ImportUsers(java.lang.String, java.lang.String)[pri:1, instance:yellowfin.bi.test.CreateUsers@614ddd49]
======
[TestNG] RUNNING: Suite: "CreateUsers" containing "1" Tests (config: C:\Users\Admin\Downloads\daily-installer-automation-master\daily-installer-automation-master-e26d3512b5f2770b8388270ffcc3078e32571d9a\src\test\resources\CreateUsers.xml)
[Invoker 513169028] Keeping method CreateUsers.instantiatePages(java.lang.String)[pri:0, instance:yellowfin.bi.test.CreateUsers@614ddd49] for class null
[TestNG] SKIPPED CONFIGURATION: "CreateUsers" - @BeforeTest yellowfin.bi.test.CreateUsers.instantiatePages(java.lang.String) finished in 0 ms
[Invoker 513169028] No configuration methods found
[Invoker 513169028] No configuration methods found
[TestNG] SKIPPED: "CreateUsers" - yellowfin.bi.test.CreateUsers.ImportUsers(java.lang.String, java.lang.String)(value(s): "admin", "test") finished in 0 ms
[TestNG] java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
[TestNG]        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
[TestNG]        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
[TestNG]        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
[TestNG]        at yellowfin.bi.test.CreateUsers.setUpTheTest(CreateUsers.java:52)
[TestNG]        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[TestNG]        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[TestNG]        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[TestNG]        at java.lang.reflect.Method.invoke(Unknown Source)
[TestNG]        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
[TestNG]        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
[TestNG]        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
[TestNG]        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
[TestNG]        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
[TestNG]        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
[TestNG]        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
[TestNG]        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
[TestNG]        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
[TestNG]        at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
[TestNG]        at org.testng.TestNG.runSuites(TestNG.java:1133)
[TestNG]        at org.testng.TestNG.run(TestNG.java:1104)
[TestNG]        at org.testng.TestNG.privateMain(TestNG.java:1434)
[TestNG]        at org.testng.TestNG.main(TestNG.java:1403)
[Invoker 513169028] No configuration methods found
[Invoker 513169028] No configuration methods found
===== Invoked methods
  CreateUsers.setUpTheTest()[pri:0, instance:yellowfin.bi.test.CreateUsers@614ddd49] 1632492873
    CreateUsers.ImportUsers(java.lang.String, java.lang.String)[pri:1, instance:yellowfin.bi.test.CreateUsers@614ddd49]admin test  1632492873
=====
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\Pre-requisite test\CreateUsers.xml
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\Pre-requisite test\CreateUsers.xml
FAILED CONFIGURATION: @BeforeSuite setUpTheTest
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
        at yellowfin.bi.test.CreateUsers.setUpTheTest(CreateUsers.java:52)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
        at org.testng.TestNG.runSuites(TestNG.java:1133)
        at org.testng.TestNG.run(TestNG.java:1104)
        at org.testng.TestNG.privateMain(TestNG.java:1434)
        at org.testng.TestNG.main(TestNG.java:1403)

SKIPPED CONFIGURATION: @BeforeTest instantiatePages
SKIPPED: ImportUsers("admin", "test")
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)V
        at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:124)
        at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
        at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
        at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:339)
        at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
        at yellowfin.bi.test.CreateUsers.setUpTheTest(CreateUsers.java:52)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:104)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:515)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:217)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:144)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:326)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1293)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1218)
        at org.testng.TestNG.runSuites(TestNG.java:1133)
        at org.testng.TestNG.run(TestNG.java:1104)
        at org.testng.TestNG.privateMain(TestNG.java:1434)
        at org.testng.TestNG.main(TestNG.java:1403)


===============================================
    CreateUsers
    Tests run: 1, Failures: 0, Skips: 1
    Configuration Failures: 1, Skips: 1
===============================================

[TestNG]
[TestNG] ===============================================
[TestNG]     CreateUsers
[TestNG]     Tests run: 1, Failures: 0, Skips: 1
[TestNG]     Configuration Failures: 1, Skips: 1
[TestNG] ===============================================

===============================================
Pre-requisite test
Total tests run: 1, Failures: 0, Skips: 1
Configuration Failures: 1, Skips: 1
===============================================

[TestNG] Time taken by org.testng.reporters.jq.Main@b7f23d9: 33 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@6591f517: 5 ms
[[Utils]] Attempting to create test-output\testng-failed.xml
[[Utils]]   Directory test-output exists: true
Creating C:\Users\Admin\Desktop\test-output\testng-failed.xml
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\Pre-requisite test\testng-failed.xml
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\Pre-requisite test\testng-failed.xml
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 5 ms
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\toc.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\toc.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\CreateUsers.properties
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\CreateUsers.properties
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\index.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\index.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\main.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\main.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\groups.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\groups.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\classes.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\classes.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\reporter-output.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\reporter-output.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\methods-not-run.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\methods-not-run.html
[[Utils]] Attempting to create C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\testng.xml.html
[[Utils]]   Directory C:\Users\Admin\Desktop\test-output\old\Pre-requisite test exists: true
Creating C:\Users\Admin\Desktop\test-output\old\Pre-requisite test\testng.xml.html
[[Utils]] Attempting to create test-output\old\index.html
[[Utils]]   Directory test-output\old exists: true
Creating C:\Users\Admin\Desktop\test-output\old\index.html
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@279ad2e3: 37 ms
[[Utils]] Attempting to create test-output\junitreports\TEST-yellowfin.bi.test.CreateUsers.xml
[[Utils]]   Directory test-output\junitreports exists: true
Creating C:\Users\Admin\Desktop\test-output\junitreports\TEST-yellowfin.bi.test.CreateUsers.xml
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@4461c7e3: 5 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@1b68b9a4: 7 ms

C:\Users\Admin\Desktop>pause
Press any key to continue . . .

1 个答案:

答案 0 :(得分:1)

你的CLASSPATH有问题。

请仔细查看错误

[TestNG] java.lang.NoClassDefFoundError:yellowfin/bi/utils/BrowserFactory

我强烈建议您使用java -cp之类的构建工具进行编译,运行测试,管理类路径等,而不是使用Ant/Maven/Gradle/Kobalt/Buck来运行TestNG测试。使用构建工具来运行测试。

TestNG在这里没有任何问题。请修复您的java -cp命令,将该文件夹包含在包含此类的jar中,然后重试。