我有一个希望通过maven运行的主类,这个主类动态创建testng.xml文件,测试就是这样开始的。但是当我通过'run as->Maven Test'运行我的项目时,我得到了'SureFireExecutionException'。下面是pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<forkMode>never</forkMode>
<parallel>tests</parallel>
<threadCount>10</threadCount>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.MainRunner</mainClass>
<arguments>
</arguments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.683 s
[INFO] Finished at: 2018-12-20T19:07:20+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.1:test (default-test) on project Automata: There are test failures.
[ERROR]
[ERROR] Please refer to D:\Git\automata\Automata\target\surefire-reports for the individual test results.
[ERROR] Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] Exception in provider
[ERROR] org.apache.maven.surefire.booter.SurefireExecutionException: Exception in provider
[ERROR] at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:91)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1166)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:154)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:146)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:290)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:194)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[ERROR] at java.lang.reflect.Method.invoke(Unknown Source)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
[ERROR] Caused by: java.lang.NoClassDefFoundError: org/testng/ITestContext
[ERROR] at java.lang.Class.getDeclaredMethods0(Native Method)
[ERROR] at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
[ERROR] at java.lang.Class.privateGetMethodRecursive(Unknown Source)
[ERROR] at java.lang.Class.getMethod0(Unknown Source)
[ERROR] at java.lang.Class.getMethod(Unknown Source)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.tryGetMethod(ReflectionUtils.java:60)
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isSuiteOnly(JUnit3TestChecker.java:66)
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.isValidJUnit3Test(JUnit3TestChecker.java:61)
[ERROR] at org.apache.maven.surefire.common.junit3.JUnit3TestChecker.accept(JUnit3TestChecker.java:56)
[ERROR] at org.apache.maven.surefire.junit.PojoAndJUnit3Checker.accept(PojoAndJUnit3Checker.java:44)
[ERROR] at org.apache.maven.surefire.util.DefaultScanResult.applyFilter(DefaultScanResult.java:102)
[ERROR] at org.apache.maven.surefire.junit.JUnit3Provider.scanClassPath(JUnit3Provider.java:147)
[ERROR] at org.apache.maven.surefire.junit.JUnit3Provider.invoke(JUnit3Provider.java:91)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
[ERROR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
[ERROR] at java.lang.reflect.Method.invoke(Unknown Source)
[ERROR] at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:206)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:161)
[ERROR] at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:84)
[ERROR] at org.apache.maven.plugin.surefire.InPluginVMSurefireStarter.runSuitesInProcess(InPluginVMSurefireStarter.java:87)
[ERROR] ... 25 more
[ERROR] Caused by: java.lang.ClassNotFoundException: org.testng.ITestContext
[ERROR] at java.net.URLClassLoader.findClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at java.lang.ClassLoader.loadClass(Unknown Source)
[ERROR] at org.apache.maven.surefire.booter.IsolatedClassLoader.loadClass(IsolatedClassLoader.java:100)
[ERROR] ... 46 more
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Surefire suite started.....
In Before Test
Starting ChromeDriver 2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90) on port 25689
Only local connections are allowed.
[1545327410.041][WARNING]: Timed out connecting to Chrome, retrying...
Dec 20, 2018 11:06:53 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
new instance
Surefire suite ended.....
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 31.895 s - in TestSuite
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 35.638 s
[INFO] Finished at: 2018-12-20T23:06:58+05:30
[INFO] ------------------------------------------------------------------------
编辑:在这里为上面的查询打开了一个新问题:无法从maven运行testNG测试
由:java.lang.ClassNotFoundException:org.testng.itestContext引起的错误表明您的类路径中缺少testng库。
请将对testng的依赖项添加到pom文件中,然后再试一次。你应该没事的。(如下所示)
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta1</version>
</dependency>
我试图通过testng运行简单的Cucumber/Java测试。xml。 所以,我有testng。xml: 我用的是runner。类,在其中我将路径/选项/etc设置为功能文件、步骤和报告: 但是当我运行testng时。xml作为TestNG套件,它: 1) 通过我自己的设想, 但是 我做错了什么?
我正在使用CSV reader从获取数据,并在使用DataProvider的测试函数中使用该数据。
我已经用maven和testNG配置了eclipse,用我的pom配置了PF。xml如下: 我是runnong,在命令提示符下点击这个目录:D:\EclipseWorkspace\iON27Feb2013\iONAutomation\common 我的cmd控制台显示:
我正在使用TestNG运行自动Selenium测试。当我作为TestNG套件运行时,一切都很好。但是当我作为Maven Test运行时,它们失败了。我非常困惑为什么他们会在一种情况下工作而不是另一种情况下。以下是测试的总体布局: base.java testbase.java
我有一个Maven项目,所有的配置都是正确的,最近我用GIT和Jenkins配置了这个项目,创建了Jenkin作业。 早些时候,我可以通过右键单击project并运行**-->**Run-->Maven test和test execution use来启动整个项目,但现在它不会抛出任何错误,而是不会启动浏览器来执行。 但是,如果我使用TestNG单独运行Java文件[单个测试用例],它就会按照预期