【问题标题】:Unable to send email after tests run using Maven Postman plugin使用 Maven Postman 插件运行测试后无法发送电子邮件
【发布时间】:2014-02-03 17:19:48
【问题描述】:

我整个早上都在尝试,但是在使用 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>conner@mysite.com</from>
                            <subject>Automation Test Results</subject>
                            <mailhost>relay.mysite.com</mailhost>
                            <htmlMessageFile>target/surefire-reports/emailable-report.html</htmlMessageFile>
                            <receivers>
                                <receiver>conner@mysite.com</receiver>
                                <receiver>conner@gmail.com</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>

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

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

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

【问题讨论】:

    标签: java maven selenium maven-plugin surefire


    【解决方案1】:

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

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

    这应该可以解决您的问题。

    【讨论】:

      【解决方案2】:

      也许这会有所帮助!

      将故障保护插件添加到您的 pom.xml 即使有测试失败,这也将有助于 Maven 生成报告。然后邮递员插件将起作用。 另外,我正在使用以下路径和标签作为电子邮件附件,它对我来说很好。

      <fileSets>
          <fileSet>
              <!-- Report directory Path -->
              <directory>${project.build.directory}/site/serenity</directory>
              <includes>
                  <!-- Report file name -->
                  <include>**/serenity-summary.html</include>
              </includes>
              <!-- Use Regular Expressions like **/*.html if you want all the html files to send-->
          </fileSet>
      </fileSets>
      

      我的故障保护插件配置是:

      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-failsafe-plugin</artifactId>
          <version>3.0.0-M3</version>
          <configuration>
              <testFailureIgnore>true</testFailureIgnore>
          </configuration>
          <executions>
              <execution>
                  <goals>
                      <goal>integration-test</goal>
                      <goal>verify</goal>
                  </goals>
              </execution>
          </executions>
      </plugin>
      <plugin>
      

      总而言之,这里发生的事情是故障安全将允许 maven 完全执行,即使有测试失败,然后文件集似乎是发送附件的正确标签。

      【讨论】:

        猜你喜欢
        • 2020-10-14
        • 1970-01-01
        • 1970-01-01
        • 2015-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-06
        • 1970-01-01
        相关资源
        最近更新 更多