Forum Discussion

DeepaJ's avatar
DeepaJ
Contributor
9 years ago
Solved

How to wait for batch file execution to be completed before continuing with rest of keyword tests

Hi,

 

I have a some keyword tests, but before they are executed, I need to run a batch file that gets the executable for my App.

But the batch file execution time varies with different versions of the App, so adding a delay after this is not ideal.

 

The batch file execution is carried out using a VBScript test that makes use of the 'TestedApps.AppName.Run' command.

 

I need to be able to wait for the batch file execution to be completed before I start the next keyword test in my suite.

 

Is there a way for me to add a parameter to this command to achieve this or get a return code (0) from the batch file to signal that it is completed the execution and add this as a check before I run the next test?

 

Thanks,

Deepa.

  • This works! It takes a parameter and test run resumes only after the batch file has completed it's execution.

     

    Sub Run_Build (Build_Version)

     

    dim shell, x, y, z

    x="C:\FolderA\FolderB\"

    y=x & "App_Name.bat "

    z=Project.Variables.Build_Version

    set shell=CreateObject("WScript.Shell")

    shell.run y + z, 1, true

     

    End sub

     

8 Replies

  • Not only do I need to wait for the batch file execution to complete, I also need to pass a variable to the bacth file from my calling keyword test.

     

    I've tried the following but none of these are working:

    Sys.OleObject("WScript.Shell").Exec("cmd /c """"C:\Folder1\Folder2\App_Name.bat"" versionInput=Build_Version""")

     

    Call Sys.OleObject("WScript.Shell").Run("""C:\Folder1\Folder2\App_Name.bat"", 1, true")

    Call Sys.OleObject("WScript.Shell").Run("""C:\Folder1\Folder2\App_Name.bat"" versionInput=Build_Version")

     

    Appreciate if someone can help.

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      Is your batch file set up to parse input parameters correctly? No use passing them in if it's not set up to use them!

       

      http://stackoverflow.com/questions/26551/how-to-pass-command-line-parameters-to-a-batch-file

       

      And telling if it's complete? Depends what it does. If there is something on-screen you can watch for, use that. If you want to look into using exit codes (either reading them or using them within the batch script to trigger some sort of on-screen indicator), start reading here:

       

      http://steve-jansen.github.io/guides/windows-batch-scripting/part-3-return-codes.html

       

      • DeepaJ's avatar
        DeepaJ
        Contributor

        Yes, the batch file reads my input correct and uses it to get the install files that I am looking for. I used ''TestedApps.AppName.Run' command and passed the parameter. This works correctly, but the problem is that while the batch file is still getting all the files, my test suite contines with the rest of the tests.

         

        I only want the rest of the tests to start, once the batch file execution is done. The amount of time required for this varies from 5 minutes to maybe 10 or more minutes. That is the reason I need a way to delay the rest of the tests from executing until this is finished first.

         

        The batch file also has a return code of 0 if it found all the install files correctly.