java - 使用 Maven Postman 插件运行测试后无法发送电子邮件

标签 java maven selenium maven-plugin surefire

我整个上午都在尝试,但在使用 Maven 从命令行运行我的 Selenium 测试套件后没有成功发送电子邮件。以下是我们如何从命令行运行该套件。

mvn surefire:test

这是使用 Surefire 插件来运行一套 TestNG/Selenium 测试。这非常有效,我们想继续使用它。我需要的是一种在每次运行套件后通过电子邮件发送结果的方法。我遇到了Postman插件,它看起来很完美。唯一的问题是我根本无法让它工作。这是我的 Maven .pom 文件。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mysite.carelogic.selenium</groupId>
<artifactId>automation</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>carelogic-automation</name>
<description>automation tests for carelogic webapp</description>
<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.37.1</version>
    </dependency>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.8.7</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>20030203.000129</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>3.8-beta4</version>
    </dependency>
</dependencies>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.16</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
            <plugin>
                <groupId>ch.fortysix</groupId>
                <artifactId>maven-postman-plugin</artifactId>
                <version>0.1.6</version>
                <executions>
                    <execution>
                        <id>send surefire notification</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>send-mail</goal>
                        </goals>
                        <inherited>false</inherited>
                        <configuration>
                            <skip>false</skip>
                            <from><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d4b7bbbabab1a694b9ada7bda0b1fab7bbb9" rel="noreferrer noopener nofollow">[email protected]</a></from>
                            <subject>Automation Test Results</subject>
                            <mailhost>relay.mysite.com</mailhost>
                            <htmlMessageFile>target/surefire-reports/emailable-report.html</htmlMessageFile>
                            <receivers>
                                <receiver><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8aba7a6a6adba88a5b1bba1bcade6aba7a5" rel="noreferrer noopener nofollow">[email protected]</a></receiver>
                                <receiver><a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6d5d9d8d8d3c4f6d1dbd7dfda98d5d9db" rel="noreferrer noopener nofollow">[email protected]</a></receiver>
                            </receivers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-report-plugin</artifactId>
                <version>2.4.3</version>
                <configuration>
                    <showSuccess>true</showSuccess>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

我已与我们的 techops 确认,我们的邮件服务器是relay.mysite.com,并且可以在端口 25 上免费使用。无需用户名或密码。当我运行 maven 命令时,我的测试运行,我可以看到什么通过了,什么失败了,但我没有看到 maven 尝试发送任何电子邮件的通知。所以我不知道从哪里开始调试来看看哪里出了问题。任何帮助将不胜感激。

*编辑 这是运行上述 mvn 命令时得到的命令行输出。正如您所看到的,一般没有提及 postman 插件或电子邮件。

Results :

Failed tests: 
  Coleman.shouldBeAbleToVerifyClientCaseLoad:84->BaseSmokeTest.shouldBeAbleToVerifyClientCaseLoad:294 » NoSuchElement

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.727s
[INFO] Finished at: Mon Feb 03 11:44:49 CST 2014
[INFO] Final Memory: 20M/141M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.16:test (default-test) on project automation: There are test failures.
[ERROR] 
[ERROR] Please refer to C:\Projects\automation\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.16:test (default-test) on project automation: There are test failures.

Please refer to C:\Projects\automation\target\surefire-reports for the individual test results.
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:317)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:152)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: There are test failures.

Please refer to C:\Projects\automation\target\surefire-reports for the individual test results.
    at org.apache.maven.plugin.surefire.SurefireHelper.reportExecution(SurefireHelper.java:82)
    at org.apache.maven.plugin.surefire.SurefirePlugin.handleSummary(SurefirePlugin.java:190)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.executeAfterPreconditionsChecked(AbstractSurefireMojo.java:852)
    at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:720)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
[ERROR] 
[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/MojoFailureException

最佳答案

您的 Maven 执行永远不会到达邮件发送插件,因为存在测试失败。在 maven-surefire-plugin 的配置部分添加这些行:

                <testErrorIgnore>true</testErrorIgnore>
                <testFailureIgnore>true</testFailureIgnore>

这应该能解决你的问题。

关于java - 使用 Maven Postman 插件运行测试后无法发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21533524/

相关文章:

java - 由于 XPath 表达式不正确,Selenium "Element not found"

java - Spring Tool Suite/Maven 删除我的 .properties 文件

java - 如何在 Eclipse 中打开 Java 项目(使用 Maven)? (我使用M2E还是maven-eclipse-plugin)

java - 如何使用 Selenium WebDriver 处理 Windows 文件上传?

java - JTable 中的多行选择

java - 发送到远程服务器的 JMS 消息

java - 如何使用 QueryParser 执行包含特殊字符的 lucene 查询?

java - 线程 "main"java.lang.NoClassDefFoundError : org/openqa/selenium/WebDriver 中出现异常

python Selenium : Getting dynamic content within iframe

java - chromedriver : cannot execute binary file and SEVERE Forwarding newSession on session null to remote with ChromeDriver Selenium through Java