我试图执行位于文件路径
BuyCourse.java
中的meropadhaiseleniumframework/src/test/java/clinchtech/Tests/BuyCourse.java
文件。我的 testng.xml
文件位于 meropadhaiseleniumframework/src/test/resources/testng.xml
我的
testng.xml
文件有代码:
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<!-- To run the tests parallely, we need to add parallel="tests" thread-count="2", it means 2 <test></test>s are running parallely, which is not suggested in real world systems -->
<suite name="MyTestSuite">
<parameter name="URL" value="https://demo.meropadhai.com"/>
<listeners>
<listener class-name='TestComponents.Listeners'/>
</listeners>
<test name="java">
<classes>
<!-- Use the fully qualified class name including the package -->
<class name="Tests.BuyCourse" />
<!-- <class name="TestNG.Tut1"/> -->
</classes>
</test>
</suite>
当我尝试通过从终端运行
mvn test
来执行代码时,出现以下错误
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M3:test (default-test) on project meropadhaiseleniumframework: There are test failures.
[ERROR]
[ERROR] Please refer to /Users/meropadhai6/Documents/GitHub/meropadhai-selenium/meropadhaiseleniumframework/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] There was an error in the forked process
[ERROR] Suite file /src/test/resources/testng.xml is not a valid file
[ERROR] org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
[ERROR] Suite file /src/test/resources/testng.xml is not a valid file
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:657)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:283)
[ERROR] at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:246)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1161)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1002)
[ERROR] at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:848)
[ERROR] at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:126)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute2(MojoExecutor.java:328)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute(MojoExecutor.java:316)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:174)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.access$000(MojoExecutor.java:75)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor$1.run(MojoExecutor.java:162)
[ERROR] at org.apache.maven.plugin.DefaultMojosExecutionStrategy.execute(DefaultMojosExecutionStrategy.java:39)
[ERROR] at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:159)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:105)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:73)
[ERROR] at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:53)
[ERROR] at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:118)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:261)
[ERROR] at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:173)
[ERROR] at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:101)
[ERROR] at org.apache.maven.cli.MavenCli.execute(MavenCli.java:906)
[ERROR] at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:283)
[ERROR] at org.apache.maven.cli.MavenCli.main(MavenCli.java:206)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:283)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:226)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:407)
[ERROR] at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:348)
您的问题不够详细,请尝试以下:
检查pom.xml中是否定义了xml套件文件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version> <!-- Adjust the version as needed -->
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
要使用 Maven 运行 TestNG 测试,您可以使用以下 Maven 命令:
mvn test
此命令将触发 Maven 构建生命周期的测试阶段,它将根据您的项目配置执行 TestNG 测试,包括 pom.xml 配置中指定的 TestNG 套件 XML 文件。
运行此命令之前,请确保您位于 pom.xml 文件所在项目的根目录中。如果您的 TestNG 套件 XML 文件名为 testng.xml 并位于 src/test/resources 目录中,Maven Surefire 插件将自动查找它并执行 XML 文件中定义的测试。
如果您有多个 TestNG 套件 XML 文件或想要指定不同的套件 XML 文件,可以使用 -Dtest 选项指定文件,如下所示:
mvn test -DsuiteXmlFile=src/test/resources/your-testng-suite.xml