Reputation: 43
I have multiple TestSuites files.
And I want to set parameter variable in my suite files from POM file. But I couldn't get any suggestion from Google search.
Could anyone help me how can I perform it.
ABC.xml [File #1]
<parameter name="property_file" value="C:/a.properties" />
DEF.xml [File #2]
<parameter name="property_file" value="C:/a.properties" />
And I want to set Property_file parameter value from Maven pom.
I want to set "C:/123.properties" for File #1 and "C:/456.properties" for File #2.
My suite file may look like_
<suiteXmlFiles>
<suiteXmlFile>ABC.xml</suiteXmlFile>
<suiteXmlFile>DEF.xml</suiteXmlFile>
</suiteXmlFiles>
I don't want to set parameter in TestNG file, I want to do it from POM file.
Is it possible?
Upvotes: 1
Views: 1609
Reputation: 5740
@niklas-p 's answer is good but in the case of test resources, you should use testResources
instead.
<project>
...
<properties>
<property_file>C:/a.properties</property_file>
</properties>
...
<build>
...
<testResources>
<testResource>
<directory>src/test/resources</directory>
<filtering>true</filtering>
</testResource>
...
</testResources>
...
</build>
...
</project>
Then, the filtered resources will be located in the ${project.build.testOutputDirectory}
directory:
<suiteXmlFiles>
<suiteXmlFile>${project.build.testOutputDirectory}/ABC.xml</suiteXmlFile>
<suiteXmlFile>${project.build.testOutputDirectory}/DEF.xml</suiteXmlFile>
</suiteXmlFiles>
And in suite files:
<parameter name="property_file" value="${property_file}" />
Upvotes: 0
Reputation: 3507
Yes, it is possible. You can filter with the maven ressources plugin. Have a look: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html
If the article doesn't answer all your questions, don't hesitate to ask.
In summary you can do something like this:
<project>
...
<properties>
<suiteXmlFile>ABC.xml</suiteXmlFile>
</properties>
...
<build>
...
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
...
</resources>
...
</build>
...
</project>
and in your xml file within the resources folder you use
<parameter name="property_file" value="${suiteXmlFile}" />
What is not possible (at least in a simple way) is to implement a maven magic that interprets the same property differently within each xml file. In this case you have to use differently named properties. (e.g. suiteXmlFile1, suiteXmlFile2)
Upvotes: 1