Forum Discussion

beginTC's avatar
beginTC
Occasional Contributor
2 years ago

Automate Testcomplete with batch file

I would like to know if there is a way to run a batch command in Windows to run function in TestComplete, and then print the return value in stdout.

 

My overall goal is actually to run two batch commands in the same batch file. The first batch command will run a function in Testcomplete, and then the 2nd function will use the return value from the first batch command as input.

 

Thanks!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I don't think it's possible to output the results to the standard output, even with TestComplete Command Line

     

    If you explain your purpose, we might be able to come up with another solution.

    • beginTC's avatar
      beginTC
      Occasional Contributor

      Thanks for the response. My situation is that I need to launch TestComplete with different credentials. More specifically:

      1. we need to have two batch commands: the first command run TestComplete function with the 1st credential, the 2nd command run TestComplete function with the 2nd credential.

      2. The tricky part is that we would like to use the return value from the 1st function in the 2nd function, without storing the value in a file to ensure data safety.

       

      Please let me know if there is a way to do this. 

      • Bonibom's avatar
        Bonibom
        Contributor

        You need PowerShell script for your purpose instead of batch file. PS is more flexible and give you more advantages. Example of the reading output

         

         

        $pinfo = New-Object System.Diagnostics.ProcessStartInfo
        $pinfo.FileName = "nslookup.exe"
        $pinfo.Arguments = "google.com", "8.8.8.8"
        $pinfo.RedirectStandardOutput = $true
        $pinfo.UseShellExecute = $false
        $p = New-Object System.Diagnostics.Process
        $p.StartInfo = $pinfo
        $p.Start() | Out-Null
        $p.WaitForExit()
        $output = $p.StandardOutput.ReadToEnd()
        $output

         

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    You need to launch TestComplete with two different credentials? Or you want to launch an application with two different credentials?

     

    What's the return value that you are expecting from the first function, that you want to pass to the second function?

     

    Are you able to do this manually?

     

    I'm just trying to get a better understanding.

    • beginTC's avatar
      beginTC
      Occasional Contributor

      1. for credentials, for example I need to run the first function under local user, then I need to run the 2nd function using a shared user credential. I could do each step separately by using two batch commands if I hard-code the input of the 2nd function, but I want to get the return value of the 1st function to be the parameter in the 2nd function.

      2. I only want a string return from the 1st function.

      3. I'm writing to run batch file/command line for this automation process, but I don't know how/where to store this return value from the 1st function. Again, I don't want to store the intermediate value in a separate file for security.

      • Bonibom's avatar
        Bonibom
        Contributor

        As far as I understand you case you might want to take a look at the TestedApps project item and use it dinamically, E.G.

         

         

         

        # 1 function
        i = TestedApps.Add(path_to_your_app)
        p = TestedApps.Items[i].Params.RunAsParams
        p.Activate()
        p.UserName = run_as_user_1
        p.Password = run_as_password_1
        process = TestedApps.Items[i].Run(1, False, timeout)
        TestedApps.Delete(i)
        ..... return some string_1
        process.Terminate()
        
        # 2nd function
        i = TestedApps.Add(path_to_your_app)
        p = TestedApps.Items[i].Params.RunAsParams
        p.Activate()
        p.UserName = run_as_user_2
        p.Password = run_as_password_2
        process = TestedApps.Items[i].Run(1, False, timeout)
        TestedApps.Delete(i)
        ..... use value of the string_1
        process.Terminate()
        
        

         

         

        https://support.smartbear.com/testcomplete/docs/reference/project-objects/items/tested-apps/testedapps/index.html

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Ignoring batch files, functions, TestComplete etc.

     

    Are you able to do this manually?

     

    Is you application, a Windows app or a Console app?

    • beginTC's avatar
      beginTC
      Occasional Contributor

      So the application does not matter in this case, because the script can do the work separately with hard-coded data. We just want to automate the process.

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I understand you want to automate the process, but the more information you can provide, we can then provide a suitable solution if possible.

     

    • I don't understand why you would want to launch TestComplete using different credentials.
    • Is it not possible to run two testcases within TestComplete.
    • I still don't fully understand what your batch file is supposed to do, apart from calling a test in TestComplete.

    If it's a console application, then you can read the output using either Sys.OleObject("WScript.Shell") or what Bonibom has mentioned. If it's a windows application that doesn't produce any standard output, then it can't be done. Or you can use Tested Applications. For command line arguments, see TestComplete Command Line