[英]How to access pom.xml values from a testng listener
我有一个testng侦听器,它需要从pom.xml中检索以下值。
<groupId></groupId>
<artifactId></artifactId>
<version></version>
我尝试过[1],但它提供了监听器pom的值。 我需要获取的是pom.xml的值,我将最终使用此lisetner
简介:我有一个testng侦听器实现“ listener.jar”,它是“ Project A”中的依赖项,需要在“ Project A”中读取以上参数。
[1] 在运行时获取Maven工件版本
解决了! 这是怎么做的。
在maven-surefire-plugin上,我将所需的值添加为“ systemPropertyVariables”
<systemPropertyVariables>
<component.name>${artifactId}</component.name>
<component.version>${version}</component.version>
</systemPropertyVariables>
所以插件看起来像这样;
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<systemPropertyVariables>
<component.name>${artifactId}</component.name>
<component.version>${version}</component.version>
</systemPropertyVariables>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
在testng.xml中,我们需要提及它们作为参数,以便通过侦听器访问它们。
<suite name="SampleTest_TestSuite1" verbose="1">
<parameter name="component" value="${component.name}"/>
<parameter name="version" value="${component.version}"/>
<test name="SampleTest" preserve-order="true" parallel="false">
<classes>
...
</classes>
</test>
</suite>
然后我们通过testng监听器访问这些参数。
public class DataBaseReporterListener implements IReporter {
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites, String s) {
String componentName = suites.get(0).getParameter("component");
String componentVersion = suites.get(0).getParameter("version");
在POM.xml中提供一个属性标签,并为其添加一个适当的名称。 添加您需要在自定义节点中添加的属性,例如
<properties>
<property>
<id>ABC</id>
...
<customprop1>property value</customprop1>
</property>
</properties>
现在,激活该配置文件后,您只需使用以下命令即可访问任何jsp文件中的值
${customprop1}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.