Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass testng.xml parameter value through mvn command line

Tags:

Below testng.xml file has three parameters. I don't want parameter customerCode to be hardcoded. I want to pass varying/diffent customerCode to the following testng.xml file, but also I want to have Peter as a default customerCode if just in case I don't provide one through mvn command line as follows:

mvn test -DcustomerCode=customer1 -Ptestng.xml

Below is the testng.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestSuite" parallel="false">

    <test name="someTest">
        <parameter name="browserType" value="chrome_win"></parameter>
        <parameter name="Url" value="http://regression.mytest.com/?customerCode=" />
        <parameter name="customerCode" value="Peter"/>

        <groups>
            <run>
                <exclude name="navigateToHomePage" />
            </run>
        </groups>
        <classes>
            <class name="com.automation.customermanagement.createTest.myIntegrationTest" >
            <methods>
                <exclude name="deleteCustomer" />
            </methods>
            </class>
        </classes>
    </test>
</suite>

How do I achieve that? Is there a way to do that?

Below is my POM file. Where do I put customerCode property inside the profile?

<profile>
    <id>AddMgmtTest</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</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>
                    <suiteXmlFiles>
                        <suiteXmlFile>admgmttestng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>
like image 767
Chuchoo Avatar asked Apr 16 '17 03:04

Chuchoo


1 Answers

Here is the solution I implemented and it is working fine!

1) Add following property to POM.xml file

                    <systemProperties>
                        <property>
                            <name>customerCode</name>
                            <value>Subaru</value>
                        </property>
                    </systemProperties>

2) Add this line to test method

String customerCode= System.getProperty("customerCode"); 

3) Above line pulls customerCode=customer1 provided in the following mvn command line

mvn test -DcustomerCode=customer1 -Ptestng.xml

If you do not provide customerCode in command line it takes the default value of Subaru that is provided in the above property in POM.xml file

like image 83
Chuchoo Avatar answered Sep 23 '22 10:09

Chuchoo