Forum Discussion

jhunter_dps's avatar
jhunter_dps
Occasional Contributor
4 years ago
Solved

Running Text File Containing Plink Command To Reset Server From TestComplete Script

Hello,

 

I am currently pursuing an effort to have TestComplete run a script on our machine that calls a Plink command that communicates with our database which is on a remote Linux server and can automatically reset it. This is being pursued to see if the reset process which is necessary for testing, can be done automatically at the start of a test run from in the OnStartTest event control.

 

I have found the WshShell.Run("echo -e | plink -load QA4DB -l instdlsb -pw ******* -m C:\Works\reset_qa4_commands.txt") Where the file path leads to a txt file that contains commands that refreshes our testing database.

 

However, when I try to run the tests, Test Complete throws and error like this: 

I was wondering if anyone could help point me in the right direction for the solution to this issue because I am not sure if I'm looking in the right place to begin with.

 

Thanks,

Jackson

  • jhunter_dps's avatar
    jhunter_dps
    4 years ago

    So I believe I have found a solution to the issue. in my code I have "/k" in the string before the command is listed, this is what was listed in the first link I posted there, turns out if you replace that with "/c" it should close the command console window after the process executes to completion.

     

    So it would look like this:

    "WshShell.Run("%comspec% /c anycommandhere", 1, True)"

     

    TestComplete can now call the command console, run the given command to reset the database, wait for completion, close console window and resume with the given tests successfully.

     

     

3 Replies

  • i dont have too much experience using the wshell object, but I'm guessing that the end goal is to process and execute the command line arguments from the designated txt file that you are calling on there?

     

    in which case, would it be possible to wrap the entirety of the command ( starting from echo *** {credentials} {commands from txt file}) into a batch file?

     

    in which case, testcomplete can trigger batch files as a tested application by providing the path to the file within the testedapps test items section.

    • jhunter_dps's avatar
      jhunter_dps
      Occasional Contributor

      Hello,

       

      So after some research, it appears that adding %comspec% /k to the string with the command will allow it to successfully open the command console and run the specified command from the TestComplete script. I obtained this information from this page:https://devblogs.microsoft.com/scripting/how-can-i-call-the-dir-command/

       

      So this is what I have written in the code:

      "WshShell.Run("%comspec% /k echo -e | plink -load ......", 1, True)"

       

      where the ... is just the truncated command for the sake of brevity, the 1 and True are based on the information found on this page: https://docs.microsoft.com/en-us/previous-versions//d5fk67ky(v=vs.85)?redirectedfrom=MSDN.

       

      However there is a new issue that has come up, the "True" there is a parameter that has the program wait for whatever command I ran to finish executing before the program to continue on causes the command console window to stay up and TestComplete halts from doing anything further until I manually close that command console window. I have attempted to create a method that closes any command console windows open directly after the WshShell.Run statement but TestComplete also does not execute this statement until I close that command console window. TestComplete is also unable to stop an in progress test when I select stop in the upper right corner until I am able to close that command console window.

       

      So it would appear that the parameter for having the program wait for that script to execute successfully is potentially interfering with TestComplete's ability to execute anything else, and even when the script executes successfully, the command console is continuing to stay open leading me to have to manually close it. Would you happen to know what options I could try to circumnavigate this issue or at least a method to ensure the script runs successfully before continuing on without the use of the wait parameter = True?

       

      Thanks,

      Jackson 

       

      • jhunter_dps's avatar
        jhunter_dps
        Occasional Contributor

        So I believe I have found a solution to the issue. in my code I have "/k" in the string before the command is listed, this is what was listed in the first link I posted there, turns out if you replace that with "/c" it should close the command console window after the process executes to completion.

         

        So it would look like this:

        "WshShell.Run("%comspec% /c anycommandhere", 1, True)"

         

        TestComplete can now call the command console, run the given command to reset the database, wait for completion, close console window and resume with the given tests successfully.