我有一个扩展报告监听器,我从testng.xml调用它,它工作得非常好。 当我从我的pom.xml调用监听器时,它不能正常工作。
我在这里有两个问题: 1.我可以在不将监听器添加到pom文件的情况下从testNG.xml调用监听器吗? 2.如何从testNG.xml和pom.xml获取相同的输出? 如果需要,我也可以附上我的项目。
Can some one please suggest what may have gone wrong here:
My testng.xml file is like this:
<?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>
My pom.xml is like this:
<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>
答案 0 :(得分:0)
如果使用IDE(例如IntelliJ),则可以使用testNG插件来执行测试套件xml,而无需使用pom文件。您只需要取消选中默认的侦听器选项,然后在编辑配置窗口中添加自己的自定义侦听器即可。 testNG configuration
您必须在终端中执行mvn clean test
才能使用pom.xml文件进行构建