Forum Discussion

dhundley's avatar
dhundley
Regular Contributor
3 years ago

powershell equivalent of running testexecute with command line arguments

in the SmartBear support documentation is this site

https://support.smartbear.com/testcomplete/docs/working-with/automating/command-line-and-exit-codes/command-line.html

 

that shows how to run testcomplete/testexecute using the command line. at the very bottom on the page is this:

 

If you want the command line to wait until the test (project and so on) execution is over, you can use the START command as shown in the example below:

start "My Title" /wait TestComplete.exe "C:\Work\My Projects\MySuite.pjs" /run /exit /SilentMode

 

 

Pay attention to the string after the START command in the example above. It is the title of the command-line window and it is needed for the command to work correctly.

 

My question is, if I'm using powershell instead of a CMD window, would this line of powershell:

 

Start-Process -FilePath "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe" -ArgumentList "C:\Work\My Projects\MySuite.pjs" -Wait

 

be the equivalent of the CMD example shown above from the smartbear support site? if not, then what would the powershell equivalent of it be? i'm curious about not including the /run, the /exit and the /SilentMode arguments and not giving it a title. 

 

since powershell appears to be the more accepted utility these days, shouldn't smartbear update their support site to give powershell examples instead of (or at least in addition to) command line arguments? just curious. 

  • This is the PowerShell command that I use,

     

    Start-Process 'C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe' -ArgumentList """C:\Sandbox\TestComplete\Proj\Proj.pjs"" /run /exit /DoNotShowLog /ExportLog:""C:\Sandbox\Log\index.html"" -Wait

     

    Make sure you use the correct single and double quotes.

  • The properties for my task schedule looks like,

     

    Username shown, has full admin access.

    I've shown you the commands that I use

     

     

    History showing completed task schedules

     

    Try to schedule a task for .ps1 script that contains only,

     

    Write-Output 'Testing schedule task'

     

    And if that doesn't work, then does the History tab show anything?

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    The properties for my task schedule looks like,

     

    Username shown, has full admin access.

    I've shown you the commands that I use

     

     

    History showing completed task schedules

     

    Try to schedule a task for .ps1 script that contains only,

     

    Write-Output 'Testing schedule task'

     

    And if that doesn't work, then does the History tab show anything?

     

    • dhundley's avatar
      dhundley
      Regular Contributor

      i think i have figured out why it wasn't working and your first screen shot above actually confirms it. what i did was to simply create a powershell script that points to notepad.exe in the start-process and to a file name  for it to open in the -argument list. again, it ran fine when i manually ran it in powershell but would not run and open the file in notepad when i used task scheduler. i found this stackoverflow article

      https://stackoverflow.com/questions/39995200/task-scheduler-powershell-start-process-is-not-running

      which made the point that

      The application was ran in background. To make it run on foreground, had to check the box Run only when user is logged on.

      so i changed the General tab from Run whether use is logged on or not to Run only when user is logged on and then the Scheduled Task worked and the file came up on notepad. i'm going to apply this to the testexecute scheduled task now and i'll report back if it is successful.  

       

      Thanks!

       

       

      • dhundley's avatar
        dhundley
        Regular Contributor

        ok. that worked. i set the task to start at a specific time then I disconnected (while keeping the RDP session up and active for testexecute) and once I reconnected several minutes later I could tell that test execute had started, ran the script and closed perfectly. i guess i got confused by the fact that my other scheduled task (which is triggered by the VM getting restarted) didn't need to "run only when user is logged in" to be successful. 

         

        thanks again for all your help

    • dhundley's avatar
      dhundley
      Regular Contributor

      Haven't actually tried it yet. wanted to get some feedback/opinions first. i will try it out in the next day or two and let you know. 

  • Kitt's avatar
    Kitt
    Regular Contributor

    Try this post [here]. With PowerShell you need to use the -Verb RunAs argument to elevate before launching TestComplete and -Wait to keep it open during runtime. 

    • dhundley's avatar
      dhundley
      Regular Contributor

      thanks! i'll take a look at that and give it a try

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    This is the PowerShell command that I use,

     

    Start-Process 'C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe' -ArgumentList """C:\Sandbox\TestComplete\Proj\Proj.pjs"" /run /exit /DoNotShowLog /ExportLog:""C:\Sandbox\Log\index.html"" -Wait

     

    Make sure you use the correct single and double quotes.

    • dhundley's avatar
      dhundley
      Regular Contributor

      there did appear to be a double quote missing from the end of your example but once i corrected that, i could manually run the powershell script and it worked exactly as i wanted it to. the problem i'm having now is that i want to created a scheduled task on that VM that runs this powershell script and the scheduled task is not even getting so far as to start running testexecute. does anyone here have some experience with getting powershell scripts to run using Task Scheduler?

  • Kitt's avatar
    Kitt
    Regular Contributor

    dhundley did you try -Verb RunAs as I posted earlier? Are there any errors when running the scheduler?

    • dhundley's avatar
      dhundley
      Regular Contributor

      i have tried adding -Verb RunAs to the arguments in Task Scheduler and then also adding -Verb RunAs onto the start-process line inside the ps1 script that attempts to run TestExecute. neither way appears to work for me. i can run the powershell ps1 script manually from the ISE and it works just fine. i've also tried to changing the user that runs the scheduled task from the logged on user (which is what works manually) to SYSTEM. that doesn't work either. i found an online article (https://techgenix.com/how-to-schedule-powershell-scripts/) that suggests you can use powershell cmdlets to schedule it to run but i'm not very familiar with those so i'm still hoping to get Task Scheduler to work if possible

      • Kitt's avatar
        Kitt
        Regular Contributor

        You could try a batch file instead of PowerShell. And also, to run the task with the option "Run whether user is logged on or not" you have to activate the option "Run with highest privileges". - so check that you have that set up correctly before attempting the batch approach. And if you still have issues, try [this post] .

         

        If there are any UAC restrictions, you can also attempt to bypass them using "-ExecutionPolicy ByPass".

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Oops, sorry about that dhundley Correct command is,

     

    Start-Process 'C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe' -ArgumentList """C:\Sandbox\TestComplete\Proj\Proj.pjs"" /run /exit /DoNotShowLog /ExportLog:""C:\Sandbox\Log\index.html""" -Wait

     

    On the VM, create a file called e.g. AutomateTC.ps1 with the above command. Create a task schedule and the program/script to run is C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe (location of your powershell.exe) followed by arguments -WindowStyle Minimized -File C:\Sandbox\AutomateTC.ps1 (window style minimized is optional; location of your .ps1 script) and start in %HOMEDRIVE%%HOMEPATH% (optional)

    While on the VM, if you right click the scheduled task you've added, select Run, it will run TC.

     

    The above will work, providing the user is logged on to the VM and the session is active. You will most likely want to run the scheduled task without having to be logged on to the VM, therefore, you'll need to use SessionCreator.

    • dhundley's avatar
      dhundley
      Regular Contributor

      i have another ps1 file on the same VM that is also run as a scheduled task and it works just fine.  all I have in its program/script box for the Action in Task Scheduler is "powershell.exe" (not the entire path). rather than containing a start-process statement, all that ps1 file has in it is a Send-MailMessage, the Arguments box has the -file switch and the fully qualified pathname and file of the ps1 file and does not have a -Verb RunAs argument.  Rather than having a scheduled start time it is triggered when the computer starts. As I said, it runs perfectly

       

      for this scheduled task the ps1 file has the start-process statement for running testexecute and I have coded it just as your recommended. i think i already mentioned that if i manually run the powershell from the ISE it completes successfully. TestExecute starts up, runs the project/unit/script and then closes. For some reason though it is not working when the task scheduler job tries to run it and I am logged on and watching it. it doesn't even fire up TestExecute. I've tried putting the -Verb RunAs on the start-process line and that doesn't help either. I've also tried bypassing the execution policy but that didn't work. 

       

      Clearly this is not an issue with TestExecute nor is there a problem with how I have written the powershell script (since it works when i run it manually) but rather there is something wonky about Task Scheduler or possibly about the VM itself. I will continue to work on it and if i ever get it running i will come back here and post the solution. Thanks for all your help. 

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Launch PowerShell command prompt and type in 'testexecute'. If you get an error, then you'll need to set your environment path variable e.g. $env:Path += ';C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin;' (include this in your .ps1 file). Type in 'testexecute' again, and it should launch.

     

    Exit TestExecute, now try your Schedule Task again.

     

    FYI, the instructions I've given, are the ones that I use on my VM.

    • dhundley's avatar
      dhundley
      Regular Contributor

      if i bring up the powershell command prompt and type in TestExecute it launches TestExecute. i get an error popup about it not specifying a valid project suite or project but powershell knows about testexecute. remember, if i run the powershell script manually (with the start-process statement that you provided) it does work. the problem is getting Task Scheduler to run it. also, as i've already said before. i have another scheduled task that is triggered at system start up which also runs powershell to send an email and that works also. so task scheduler know how to run powershell. i just can't figure out why task scheduler is having an issue with the start-process cmdlet in powershell. 

       

      i really appreciate your effort but i feel like we keep going over ground that has been covered before instead of trying something new. as i said, i'll keep after it and post the resolution when/if i ever come up with something. i'm guessing it's something weird with the VM and i'm asking our support help desk guy who set the VM up for me if he's got any ideas. thanks again!

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If I remember correctly "background" will run the application, but there won't be any visible UI. Ideally, it's used for windows services.

     

    Now that you know the mistake you made, TC should work fine - fingers crossed!