Forum Discussion

Ravikaanth's avatar
Ravikaanth
Contributor
11 months ago
Solved

Can't trigger TestExecute through Task Scheduler

I am trying to trigger TestExecute by using a .bat file through Task Scheduler. When I try trigger .bat file manually TestExecute triggered successfully. But if I try to trigger by using Task Scheduler the status is changed from Ready to Running, but we can't see anything in the background. Please check below screenshot.

 

Below code is the .bat file, Please verify it.

 

Echo off
cd "C:\Program Files (x86)\SmartBear\TestExecute 15\Bin"
start "" /wait "C:\Program Files (x86)\SmartBear\TestExecute 15\Bin\TestExecute.exe" "C:\Users\ravikaanth.ns\Documents\MB_Automation\TestProject2\MBAutomation1.pjs" /run /project:"MBAutomation1" /unit:"CampaignReadProd" /routine:"readCampaign"

 

 

 

  • I've just ran the same, these are the results. Also, TC has generated log files too.

    My batch file has only this command,

     

     

    start "TestExecute" /wait "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe" "C:\Sandbox\TestComplete\Project Flow\Project Flow.pjs" /run /exit /DoNotShowLog /project:"TestProject2" /ExportLog:"C:\Sandbox\Log\TestProject2\index.html"

     

     

    And task schedular

     

     

    How are you running your Task? Is this on your local machine?

43 Replies

  • dhundley's avatar
    dhundley
    Regular Contributor

    i am trying to do this for the first time. normally i don't try to schedule a testcomplete automation script to run on a VM using the task scheduler but i would like to figure out how its done. i have been at this all day trying one thing and then another but nothing works. it should be noted however that the project/testitem does run successfully if i manually kick it off so there's nothing wrong with the script, per se. this is essentially it

    "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe" -ArgumentList "/exit /run  <full qualified path>\<project suite>.pjs /p:<project name> /t:ProjectTestItem1"

    First, i attempted the simple approach and just configured the Edit Actions of the scheduled task to start the testexecute application and put the command line arguments in the Add arguments box. that resulted in a Run Result message of "the request operation requires elevation"

    Next, i created a powershell file called runTcAsAdmin.ps1 containing a single line with a "Start-Process -FilePath" appended to the front of the call to TestExecute followed by its list of command line arguments. I put powershell.exe in the program/script box of the task scheduler and put the following powershell arguments in the Add arguments box

    -Command Start-Process PowerShell -ArgumentList '-File <fully qualified path name>\runTcAsAdmin.ps1' -Verb RunAs

    That one finished with "The operation completed successfully" in the Run Result message but it didn't do anything that the automation script was designed to do. 

    Finally, i tried creating a bat file called runTcAsAdmin.bat with the following contents and in the same location as the runTcAsAdmin.ps1 file and i changed the Task Scheduler Action so that it points to this bat file

    Echo OFF
    PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"

    but that had the same result as the previous attempt. Does anyone have something working for this? what step or parameter am i missing?

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    It is my guess that you are trying to execute tests against the GUI-based application.

    If my guess is correct, than not locked active user session must exist for the user that is used to run the test.

    In order to get this you must:

    -- Always keep this user logged-on and desktop for this user must never be locked;

    -- Task in the Task Scheduler must be configured to be executed on behalf of this user and be allowed to interact with the desktop.

     

    https://support.smartbear.com/testcomplete/docs/testing-with/running/scheduling.html

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    I've just ran the same, these are the results. Also, TC has generated log files too.

    My batch file has only this command,

     

     

    start "TestExecute" /wait "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe" "C:\Sandbox\TestComplete\Project Flow\Project Flow.pjs" /run /exit /DoNotShowLog /project:"TestProject2" /ExportLog:"C:\Sandbox\Log\TestProject2\index.html"

     

     

    And task schedular

     

     

    How are you running your Task? Is this on your local machine?

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If you Program/script location is,

    C:\Users\ravikaanth.ns\Desktop\TestExecuteRun.bat

    Then can you put the following path in Start in (optional),

    C:\Users\ravikaanth.ns\Desktop\

     

    • Ravikaanth's avatar
      Ravikaanth
      Contributor

      I tried your suggestion but still it looks same. Status changed to running but nothing is triggering.

       

       

      • dhundley's avatar
        dhundley
        Regular Contributor

        i have a testcomplete project/testitem that i would like to be able to schedule using the Task Scheduler and I have been trying everything I can think of and have been able to research on the internet and simply cannot get it to work. First, it should be said that i can bring up a command prompt window on the VM where I want this to run and i can manually run testexecute with a command line argument list that runs it perfectly. if i simply try to stick that into the task scheduler i get a message indicating that the "requested operation requires elevation". so i have placed the call to testexecute with the argument list into a powershell script called runTcAsAdmin.ps1 and I can manually run that successfully. i created a bat file called runTcAsAdmin.bat into which I placed the following code 

        Echo OFF
        PowerShell.exe -NoProfile -Command "& {Start-Process PowerShell.exe -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""%~dpn0.ps1""' -Verb RunAs}"

        and directed by Task Scheduler job to run the bat file. After i run it the Last Run Result message indicates "the operation completed sucessfully" but it didn't do anything that was in the script (like it does when i run the script manually using the command prompt or the powershell script). 

        my ps1 file looks essentially like this:

        Start-Process -FilePath "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe" -ArgumentList "/exit /run  <fully qualified path>\<project suite name>.pjs /p:<project name> /t:ProjectTestItem1"

        what step or parameter am i missing? does it matter the order of the command line parameters for testexecute?

         

         

         

  • rraghvani Thanks for your guidance, Your code works when I try to run it manually. But in Task Scheduler it is showing only Task triggered message but we can't see anything in the background. Please check below image I am using the .bat file location for Program/Script and we are not passing any arguments or parameters.

     

     

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Can you try with just this command line.

    start "TestExecute" /wait "C:\Program Files (x86)\SmartBear\TestExecute 15\x64\Bin\TestExecute.exe "C:\Users\ravikaanth.ns\Documents\MB_Automation\TestProject2\MBAutomation1.pjs" /run /exit /DoNotShowLog /project:"MBAutomation1"

    Run your batch file manually, just to test that it works.

     

    What command and parameters are you using to call you batch file in Task Scheduler?