通过概要文件的Maven插件未在指定阶段执行

时间:2018-07-03 03:45:39

标签: maven selenium-webdriver testng maven-surefire-plugin

我要求执行testng.xml文件以运行自动化脚本并在执行完成后发送邮件。我将定义要从testng.xml文件运行的测试。

因此,我决定使用maven配置文件概念来运行testng.xml文件并发送执行报告,如下所示。当我使用运行命令 “ MVN测试-P Code_Compile,Run_Tests,Mail_Reports”,下面提到的配置文件不会执行。请让我知道我在这里想念的东西。

<profiles>  
    <profile>
        <id>Code_Compile</id>
            <build>
                  <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.7.0</version>                        
                        <executions>
                            <execution>
                                <id>codecompile</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>testCompile</goal>
                                </goals>
                                <configuration>
                                  <source>1.8</source>
                                  <target>1.8</target>
                                </configuration>
                            </execution>
                        </executions>                       
                  </plugin>                           
                </plugins>
            </build>
        </profile>


    <profile>
    <id>Run_Tests</id>
        <build>
              <plugins>                   
                  <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.0</version>
                        <executions>
                            <execution>
                                <id>runtests</id>
                                <phase>test</phase>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <configuration>
                                <testFailureIgnore>true</testFailureIgnore>
                                  <suiteXmlFiles>
                                    <suiteXmlFile>testng.xml</suiteXmlFile>
                                  </suiteXmlFiles>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>                         
            </plugins>
        </build>
    </profile>

    <profile>
        <id>Mail_Reports</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>ch.fortysix</groupId>
                    <artifactId>maven-postman-plugin</artifactId>
                    <version>0.1.6</version>
                    <executions>
                        <execution>
                            <id>send a mail</id>
                            <phase>test</phase>
                            <goals>
                                <goal>send-mail</goal>
                            </goals>
                            <inherited>false</inherited>
                            <configuration>
                                <from>xx@gmail.com</from>
                                <subject>Latest Automation Report...</subject>
                                <failonerror>true</failonerror>
                                <mailhost>smtp.gmail.com</mailhost>
                                <mailport>465</mailport>
                                <mailssl>true</mailssl>
                                <mailAltConfig>true</mailAltConfig>
                                <mailuser>xx@gmail.com</mailuser>
                                <mailpassword>xxxxx</mailpassword>
                                <htmlMessage><![CDATA[<p>Hi, Please find enclosed latest Automation reports.</p>]]></htmlMessage>
                                <receivers>
                                    <receiver>xxxx@gmail.com</receiver>
                                </receivers>
                                <fileSets>
                                    <fileSet>
                                        <directory>${basedir}/TestReports</directory>
                                        <includes>
                                            <include>LatestAutomationReport.zip</include>
                                        </includes>
                                    </fileSet>
                                </fileSets>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    </profiles>

我尝试通过如下所示将每个插件的阶段设置为“ test”,从而在build标签中仅包含插件,而不是配置文件,如下所示,并尝试运行“ mvn test”命令。如下所示,在每个插件中进行测试。此尝试也没有选择插件的执行方式。请通过配置文件或插件帮助我解决此问题。

<build>
<plugins>  
      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>                        
            <executions>
                <execution>
                    <id>codecompile</id>
                    <phase>test</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                    <configuration>
                      <source>1.8</source>
                      <target>1.8</target>
                    </configuration>
                </execution>
            </executions>                       
      </plugin>

      <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.0</version>
            <executions>
                <execution>
                    <id>runtests</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                    <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                      <suiteXmlFiles>
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                      </suiteXmlFiles>
                    </configuration>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>ch.fortysix</groupId>
            <artifactId>maven-postman-plugin</artifactId>
            <version>0.1.6</version>
            <executions>
                <execution>
                    <id>send a mail</id>
                    <phase>test</phase>
                    <goals>
                        <goal>send-mail</goal>
                    </goals>
                    <inherited>false</inherited>
                    <configuration>
                        <from>vikascool4@gmail.com</from>
                        <subject>Latest Automation Report...</subject>
                        <failonerror>true</failonerror>
                        <mailhost>smtp.gmail.com</mailhost>
                        <mailport>465</mailport>
                        <mailssl>true</mailssl>
                        <mailAltConfig>true</mailAltConfig>
                        <mailuser>vikascool4@gmail.com</mailuser>
                        <mailpassword>vikaschinna</mailpassword>
                        <htmlMessage><![CDATA[<p>Hi, Please find enclosed latest Automation reports.</p>]]></htmlMessage>
                        <receivers>
                            <receiver>vikas.voladri@gmail.com</receiver>
                        </receivers>
                        <fileSets>
                            <fileSet>
                                <directory>${basedir}/TestReports</directory>
                                <includes>
                                    <include>LatestAutomationReport.zip</include>
                                </includes>
                            </fileSet>
                        </fileSets>
                    </configuration>
                </execution>
            </executions>
        </plugin>  
</plugins>

1 个答案:

答案 0 :(得分:0)

如果运行mvn fr.jcgay.maven.plugins:buildplan-maven-plugin:1.3:list -P Code_Compile,Run_Tests,Mail_Reports,则将输出maven正在执行的插件及其执行ID,您可能会从命令的输出中看到,您的执行可能不会覆盖默认执行(因为它们具有不同的ID)

使用下面定义的默认属性代替定义Code_Compile个人资料:https://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

如果您要使用特定版本的编译器,请使用pluginManagement进行定义。