Tuesday, May 15, 2012

Pass values from command line to java program/ant file

In order to pass values from command line to java program we can use "sysproperty"
Sample usage

   <target name="run_tests" depends="compile">
       <echo message="running tests" />
       <testng classpathref="classpath" haltOnfailure="true">
               <xmlfileset file="${xml}" />
            <sysproperty key="env" value="${env}"/>
            <sysproperty key="driver" value="${driver}"/>
       </testng>
    </target>

   @Test
    @Parameters ({"env","driver"})
    public void setUp(String env, String driver) {
           System.out.println(env+" success "+driver);
  }

 Execution : ant run_tests -Denv=test -Ddriver=ff


No comments:

Post a Comment