java - Maven 不想在同一个 testng 套件中的第一个测试之后运行其他测试
问题描述
当我出于某种原因通过 maven 运行测试套件时,mvn clean test
不想实例化驱动程序以在同一套件中启动另一个测试。
TestNG builder 运行相同的配置没有问题。
套件.xml
<suite name="Run Tests">
<test name="Chrome Tests">
<parameter name="platform" value="desktop"/>
<classes>
<class name="desktop.customer.CustomersListTest"/>
</classes>
</test>
<test name="Chrome 2 Tests">
<parameter name="platform" value="mobile"/>
<classes>
<class name="desktop.customer.CustomerDetailsTest"/>
</classes>
</test>
</suite>
BaseTest.class
@BeforeClass
@Parameters({"platform"})
public void beforeClass(String platform) {
setPlatform(platform);
logger.info(platform);
DriverBase.instantiateDriverObject();
driver = getDriver();
String sessionId = ((RemoteWebDriver) driver).getSessionId().toString();
logger.info("Session ID: " + sessionId);
}
@AfterMethod
public void afterMethod(ITestResult result) throws IOException {
DriverBase.closeDriverObjects();
driver().quit();
}
Pom.xml以防万一。
错误信息
INFO: Finished (success): customersListTest
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[ERROR] There are test failures.
There are test failures.
Please refer to /target/surefire-reports for the individual test results.
Please refer to dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
There was an error in the forked process
null
org.apache.maven.surefire.booter.SurefireBooterForkException: There was an error in the forked process
null
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.fork(ForkStarter.java:656)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:282)
at org.apache.maven.plugin.surefire.booterclient.ForkStarter.run(ForkStarter.java:245)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeProvider(AbstractSurefireMojo.java:1183)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:1011)
at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:857)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:210)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:156)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:117)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:305)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:956)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:192)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
日志中的Null应该是驱动程序功能。
我已经为具有日志级别功能的驱动程序添加了日志logs.enable(LogType.DRIVER, Level.ALL)
,但是它们没有显示出来。也许如果没有人知道如何解决这个问题,至少可以帮助扩展驱动程序日志?
我猜问题的根源在于maven builder..
解决方案
您需要 pom.xml 中的参数,如下所示
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<systemPropertyVariables>
<environment>${platform}</environment>
</systemPropertyVariables>
</configuration>
</plugin>
然后在cmd中传递变量
mvn clean test -Dplatform=desktop
使用 TestNG.xml 文件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<systemPropertyVariables>
<environment>${eplatform}</environment>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
推荐阅读
- r - 有没有办法从最近编写的文档(html、pdf 或 Word)中获取 R Markdown 文档?
- react-native - 是否可以使用 react-native 构建复杂的动画
- reactjs - 如何在 FastAPI 后端提供 React 构建的前端?
- java - JOOQ如何自我加入
- javascript - 使用 React Js 和 Gatsby 添加谷歌地图
- html - 推送到 AWS 后部分 HTML 和 CSS 丢失
- javascript - Angular:意外的令牌。需要构造函数、方法、访问器或属性
- python - Python getopt - 如何检查不同可能的参数组合?
- javascript - Promise... 返回类型而不是 Promise
- python - 尝试对字母数字坐标进行排序