【问题标题】:How to invoke listener from pom.xml如何从 pom.xml 调用监听器
【发布时间】:2017-11-08 05:41:46
【问题描述】:

我有一个范围报告侦听器,并且正在从 testng.xml 调用它,它工作得非常好。当我从我的 pom.xml 调用侦听器时,它不能正常工作。

这里有两个问题:

  1. 能否在不将侦听器添加到 pom 文件的情况下从 testNG.xml 调用侦听器?
  2. 如何从 testNG.xml 和 pom.xml 获得相同的输出?

如果需要,我也可以在此处附加我的项目。有人可以建议这里可能出了什么问题。

我的 testng.xml 文件是这样的:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<suite name="Suite" verbose="2" parallel="tests" thread-count="2">
<listeners>
       <listener class-name="ExtentReporterNG.ExtentTestNGIReporterListener"/>
   </listeners>

 <test name="Regression1">
    <classes>
             <class name="org.Sample1.AppTest"/>
             <class name="org.Sample2.AppTest"/>
    </classes>
  </test>
 </suite>

我的 pom.xml 是这样的:

<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.test.sample</groupId>
  <artifactId>SampleProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <name>SampleProject</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>   
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.9.10</version>
            <scope>test</scope>
        </dependency>
          <dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>3.0.7</version>
</dependency>
<dependency>
    <groupId>sample</groupId>
    <artifactId>com.sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>C:\\Users\\pchand\\Desktop\\ExtentReport-0.0.1-SNAPSHOT.jar</systemPath>
</dependency>
  </dependencies>
  <modules>
    <module>Sample1</module>
    <module>Sample2</module>
  </modules>
    <build>  
    <pluginManagement>
     <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.7.0</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

     <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.19.1</version>
           <configuration>
              <testFailureIgnore>true</testFailureIgnore>
             <suiteXmlFiles>
                         <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
           <properties>
    <!--         <property>
              <name>usedefaultlisteners</name>
              <value>false</value> disabling default listeners is optional
            </property> -->
            <property>
              <name>listener</name>
              <value>ExtentReporterNG.ExtentTestNGIReporterListener</value>
            </property>
          </properties>
    </configuration>
    </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

【问题讨论】:

    标签: maven extentreports extent


    【解决方案1】:
    1. 如果你使用IDE(比如IntelliJ),你可以使用testNG插件来执行测试套件xml,而不需要使用pom文件。您只需要取消选中默认侦听器选项并在编辑配置窗口中添加您自己的自定义侦听器。 testNG configuration

    2. 您必须在终端中执行 mvn clean test 才能使用 pom.xml 文件进行构建

    【讨论】:

    • 这是一个实际的答案,还是只是一个评论?
    猜你喜欢
    • 2014-11-18
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-20
    • 1970-01-01
    • 2019-10-10
    • 2012-09-20
    相关资源
    最近更新 更多