0

I have a java selenium QA project where we use ant and testng via the powershell terminal. What I would like help with is creating a redirect if a tester enters a typo in the terminal.

If I am in the run directory and I simply type ant, it will run the default.xml file listed in the build.xml file which is what I expect.

If I enter an actual ant command with a typo though:

ant -Dtestdir= c:\dev\qa\src\tests -Dtestxml=blablabla

it will attempt to run every test.xml file in the test directory. This is especially problematic because most of the those test.xml files call java classes that contain @Factory and @Dataprovider(s) and they allocate everything at once which just causes everything to fail.

What I would like is a way to tell ant if the input is erroneous, then run the default.xml file(which I have configured to populate an html error page). I've been reviewing both testng and ant docs and I'm not finding a solution, so your guidance would be appreciated.

Other than this one issue, the system works very well.

Miek
  • 1,127
  • 4
  • 20
  • 35
  • 1
    Ant can reference the full command and parameters entered by the user with the property `${sun.java.command}`. You can use this along with the `` task and a nested `` task to validate command in the root level of your main build script. – CAustin Jul 21 '17 at 01:33

1 Answers1

0

After digging around a bit more and learning how to ask the question properly, I found 2 great examples here on SO.

1) Create an additional ant target that checks for the existence of the file the user has typed. And add it to the depends attribute of the main target , and also adding the if attribute. Example

2) Use the Ant fail task and fail the build (with a message) if the file is not available. I prefer this one because the tester can get some feedback. Example 2

Miek
  • 1,127
  • 4
  • 20
  • 35