0

I have selenium testng framework, earlier we had xml files for starting and stopping the selenium grid, since it used to reflect in test reports we have removed the xmls for starting and stopping the grid and tend to use ant for this, hence I am trying to create a target which takes arguments and passes on to java function.

my function -

 public static void main(String[] args) throws Exception {
        if(args.length<1){
            System.err.println("This execution requires arguments such as startGRID or stopGRID");
            log.error("This execution requires argumentr such as startGRID or stopGRID");
        } else if(args[0].equalsIgnoreCase("startGRID")){
            System.out.println("Starting up GRID");
            log.info("Starting up GRID");
            setupSeleniumGrid();
        } else if(args[0].equalsIgnoreCase("stopGRID")){
            System.out.println("Shutting down GRID");
            log.info("Shutting down GRID");
            shutdownSeleniumGrid();
        }else {
            System.err.println("unrecognized arguments, please provide aruments such as startGRID or stopGRID");
            log.error("unrecognized arguments, please provide aruments such as startGRID or stopGRID");
        }
    }

ant target -

   <!-- start Grid -->
    <target name="startGRID" depends="compile">
        <echo>
    Please wait .... GRID is starting up...
    </echo>
        <java classname="foo.bar.framework.selenium.SetupGrid" classpath="${test.dest}" classpathref="${test.c}" />
        <echo>
        GRID Start up complete !
    </echo>
    </target>

in above target I am not sure what classpathref="${test.c} does as it is in the legacy code and we are continuously using it.

Please if somebody can suggest working target to accomplish this task via ant.

Shek
  • 1,543
  • 6
  • 16
  • 34
  • possible duplicate of [Use Ant for running program with command line arguments](http://stackoverflow.com/questions/3730880/use-ant-for-running-program-with-command-line-arguments) – ewan.chalmers Feb 11 '15 at 12:34

3 Answers3

0

According to the documentation, there must be a path element with id="${test.c}" in your build.xml. More here: http://ant.apache.org/manual/using.html#references

erosb
  • 2,943
  • 15
  • 22
0

Go through this thread from stackoverflow Use Ant for running program with command line arguments

In your "java" tag pass "arg" tag by getting argument from the command line. Clearly explained with examples in the thread...

Community
  • 1
  • 1
gubs
  • 439
  • 3
  • 11
0

This worked for me -

  <target name="controlGRID" depends="compile">
                <echo>
            Please wait .... GRID is starting up...
            </echo>
                <java classname="foo.bar.framework.selenium.SetupGrid" classpath="${test.dest}" classpathref="test.c">
                <arg value="${arg}"/>
                </java>
                <echo>
                GRID Start up complete !
            </echo>
            </target>

and for command line

ant -Darg=startGRID controlGRID
Shek
  • 1,543
  • 6
  • 16
  • 34