0

I am setting up my Maven project written in Java which has Cucumber framework and Runner class uses TestNG. I am getting environment details e.g. URL, user id etc from config.properties at the moment. I want to enhance my code which can take parameters from mvn command line to set environment variables in properties file and execute from there.

Would be great if someone can help me to update my pom.xml and java code to support the above feature.

I tried searching on the internet with the proper guidence and could not get the end to end modifications that are required

I am using maven-surefire_plugin at the moment with the following tags, could not get data properly to my runner file

                    <systemProperties>
                        <property>
                            <name>env</name>
                            <value>$(env)</value>
                        </property>

                    </systemProperties>

With the above tags, I am getting the 'env' value by System.getProperty(), but it seems it does not get all details

Pradeep Nayak
  • 21
  • 1
  • 2
  • 6
  • Possible duplicate https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml/7515282 – IMParasharG Jun 24 '19 at 13:47
  • Possible duplicate of [Passing command line arguments from Maven as properties in pom.xml](https://stackoverflow.com/questions/7513319/passing-command-line-arguments-from-maven-as-properties-in-pom-xml) – Greg Burghardt Jun 24 '19 at 14:28
  • Does this answer your question? [how to get property value from pom.xml?](https://stackoverflow.com/questions/26404343/how-to-get-property-value-from-pom-xml) – Ashok kumar Ganesan Jul 15 '20 at 04:09

1 Answers1

1

You don't need to go through the pom file. It's easier to just use system variables when running the maven command. For example I run some of my tests using clean install "-Dcucumber.options=--tags @ui" -Dlocal=false -Dconfig=win10Gc60 Then I get the value of the variable in my code and pick what I need: final String configuration = System.getProperty("config");

unit_1
  • 48
  • 1
  • 7