【问题标题】:Maven doesn't want to run other tests after first one in the same testng suiteMaven 不想在同一个 testng 套件中的第一个测试之后运行其他测试
【发布时间】:2019-08-12 10:24:32
【问题描述】:

当我通过mvn clean test maven 运行测试套件时,出于某种原因不想实例化驱动程序以在同一套件中启动另一个测试。

TestNG builder 运行相同的配置没有问题。

suite.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) loglevel 功能的驱动程序添加了日志,但是它们没有显示出来。也许如果没有人知道如何解决这个问题,至少可以帮助扩展驱动程序日志?

我猜问题的根源在于 maven builder..

【问题讨论】:

    标签: java maven testng


    【解决方案1】:

    您需要 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>
    

    【讨论】:

    • mvn中是否需要传递-Dplatform?我想避免这种情况,这就是将其存储在 suite.xml 中的重点。因为它因测试而异,例如“桌面”/“移动”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    • 1970-01-01
    • 1970-01-01
    • 2020-12-17
    • 1970-01-01
    • 2017-01-09
    相关资源
    最近更新 更多