Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:30:27+00:00 2026-06-15T03:30:27+00:00

I need to pass on following values … exeEvironment (Test environment) , testGroup (Group

  • 0

I need to pass on following values …

exeEvironment (Test environment) ,
testGroup (Group in testNG)

from Command-Line -> POM -> TestNG -> Test cases.

Based on these two posts ….

pass a java parameter from maven

How to pass parameters to guicified TestNG test from Surefire Maven plugin?

I did the following configuration ..

In surefire plugin, I tried following two options, none seem to work.

=====

(1)

  <execution>
<id>default-test</id>
    <goals>
        <goal>test</goal>
    </goals>
    <configuration>
        <properties>
            <exeEnvironment>${exeEnvironment}</exeEnvironment>
            <testGroup>${testGroup}</testGroup>
        </properties>
        <suiteXmlFiles>
            <suiteXmlFile>testng.xml</suiteXmlFile>
        </suiteXmlFiles>
    </configuration>
</execution>

(2)

<execution>
<id>default-test</id>
<goals>
    <goal>test</goal>
</goals>
<configuration>
    <systemPropertyVariables> <exeEnvironment>${exeEnvironment}</exeEnvironment> 
        <testGroup>${testGroup}</testGroup> </systemPropertyVariables> 
    <suiteXmlFiles>
        <suiteXmlFile>testng.xml</suiteXmlFile>
    </suiteXmlFiles>
</configuration>
</execution>

In testNG.xml , can I use the the variable testGroup like …

<test name="Web Build Acceptance">
    <groups>
        <run>
            <include name="${testGroup} />
        </run>
    </groups>
    <classes>
        <class name="com.abc.pqr" />
    </classes>
</test>

This doesn’t seem to work as well, do I need to define a parameter.


In the test cases , I tried to get he variables in following two ways ….
(1)

testEnv = testContext.getSuite().getParameter("exeEnvironment");
testGroup = testContext.getSuite().getParameter("testGroup");

(2)

testEnv = System.getProperty("exeEnvironment");
testGroup = System.getProperty("testGroup");

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:30:29+00:00Added an answer on June 15, 2026 at 3:30 am

    This is the exact thing I was looking for my automation test and I got it working.

    Command Line argument

    mvn clean test -Denv.USER=UAT -Dgroups=Sniff
    

    My Pom Xml

    <?xml version="1.0" encoding="UTF-8"?>
    <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>TestNg</groupId>
        <artifactId>TestNg</artifactId>
        <version>1.0</version>
    
        <dependencies>
            <dependency>
                <groupId>org.testng</groupId>
                <artifactId>testng</artifactId>
                <version>6.8</version>
                <scope>test</scope>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.12.4</version>
                    <configuration>
                        <systemPropertyVariables>
                            <environment>${env.USER}</environment>
                        </systemPropertyVariables>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    TestNG test

    import org.testng.annotations.Parameters;
    import org.testng.annotations.Test;
    
    
    public class TestAuthentication {
    
        @Test (groups = { "Sniff", "Regression" })
        public void validAuthenticationTest(){
            System.out.println(" Sniff + Regression" + System.getProperty("environment"));
        }
    
        @Test (groups = { "Regression" },parameters = {"environment"})
        public void failedAuthenticationTest(String environment){
            System.out.println("Regression-"+environment);
        }
    
        @Parameters("environment")
        @Test (groups = { "Sniff"})
        public void newUserAuthenticationTest(String environment){
            System.out.println("Sniff-"+environment);
        }
    }
    

    The above works well. Additionally, if you need to use testng.xml, you can specify the suiteXmlFile like …

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <systemPropertyVariables>
                        <environment>${env.USER}</environment>
                    </systemPropertyVariables>
                    <suiteXmlFiles> 
                        <suiteXmlFile>testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
    

    Also, I prefer using @Parameters instead of parameters in @Test() as the later is deprecated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to increase my PermGen. Currently I pass the following as command line
I need to pass some values from the database to the <li> tag. Is
I need to pass an array of numeric values from jQuery to a php
I need to pass two values to a javascript function from inside another javascript
I am creating a function that I need to pass in values from an
I need to pass an extra parameter :mobilejs => true from jQuery to a
I need to pass a variable which is captured from client side via jquery
I need to pass a parameter from an EditText and when I click the
I have a JSON object that I need to pass from the server to
I need to pass values to a method, along with an indication of whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.