1

I need to detect if current running autoit script is failed or not.

I tried to wait for 1 min in the following code, if in this time 1st Autoit script doesn't complete then it will move on to 2nd script but in the output Console it will show that 1st Script is Passed.

@Test (priority=1)
public void CreateNew() throws Exception
{       
   Process process = Runtime.getRuntime().exec("exeFiles\\CreateNew.exe");
   process.waitFor(1, TimeUnit.MINUTES);      
}

Is there a Way to detect wheather the following script is failed?

Possible Solution can be :

  • Is to detect wheather script is skipped/stoped due to process.waitFor(1, TimeUnit.MINUTES) and if it is so then fail the script.

So Can any one suggest me a solution for this Issue or a way to Implement the above Possible Solution?

2 Answers 2

1

What you are wanting to do is look for the exit code from AutoIT.

You can set the exit code using the exit keyword.

Typically, an exit code of 0 is success anything else is a failure or gives other information. By using different exit codes in your AutoIT script you can then check the code in your Java.

   Process process = Runtime.getRuntime().exec("exeFiles\\CreateNew.exe");
   Integer exitCode = process.waitFor(1, TimeUnit.MINUTES); 
   Assert.assertEquals(exitCode,0);

This will cause the first test case to fail if the exit code is not 0. You can change it to other integers by using the Exit code. For example, you may want to use a different exit code if x happens instead of y.

1
  • I am not currently using Java nor do I have an IDE installed for it. This is mainly from memory so there may be some issues with the syntax. If there is, please let me know and I will try and update.
    – Paul Muir
    Commented Jul 29, 2016 at 13:10
0

Mind, this is only a suggestion.
I have some knowledge of AutoIt but little or no experience with Selenium/Java, so you will have to check out if this works for yourself.

AutoIt has good Windows integration. You can use it to create a file. So if you have AutoIt create a file with a certain name on completion you can then detect the existence of this file through Selenium.

The AutoIt command looks like this.

  _FileCreate ( $sFilePath )

There is a topic describing file detection with Selenium/Java here.

  File dir = new File(downloadPath);
  File[] dirContents = dir.listFiles();

...and then cycle through the list to find it

If this works, you can of course use it to detect completion as well as result.
Actually the first thing I'd try would be to let AutoIt return an exit code. But that may be cumbersome to get to work?

References:
https://www.autoitscript.com/autoit3/docs/libfunctions/_FileCreate.htm
https://stackoverflow.com/questions/30726126/detecting-a-file-downloaded-in-selenium-java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.