Forum Discussion

master_mind01's avatar
master_mind01
New Contributor
13 years ago

Batch File to run a test item using TestExecute.

Hi,

My batch file looks the following:


@echo off

tasklist /FI "IMAGENAME eq TestExecute.exe" | find /I "TestExecute.exe" 

IF ERRORLEVEL 2 GOTO Test2

echo start scripts

pause

@echo on

:Test2

taskkill /IM TestExecute.exe /F

Start /wait "TestExecute" "C:\Program Files (x86)\Automated QA\TestExecute 8\Bin\TestExecute.exe" "C:\TestComplete 8 Projects\MyTest\MyTest.pjs" /r /p:Project_Name /t:"KeywordTests|DoEnter_Info"

What I am trying to do is:

1. Create a main batch file to run TestExecute.

2. Create another batch file to load projects and run specific test item. This batch file that loads projects is going to be called from the main batch file.



Help will be very much appreciated :)



Thanks,

MasterMind








  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    I consulted our developers, and here is what I found out:

    * Batch files don't allow accessing the active object (for example, the opened window of TestExecute) that was activated from another batch file. That's why it's impossible to open TestExecute in one batch file and then load a test project to it from another batch file.

    * So, to perform the task you need, I recommend that you do the following:

    1. Create a main batch file that will run TestExecute.

    2. Create a VBScript file that will access the opened window of TestExecute via COM and load the project to it. Working with TestExecute via COM is similar to the approach used for TestComplete. For more information, see the Working With TestComplete via COM - Overview help topic.

    3. Run the created VBScript file from the main batch file right after you open TestExecute.


    I hope this information helps :)

  • Thanks for the reply.

    If bat file is launching TestExecute, that will be an instance of TestExecute running.

    If only one instance of TestComplete or TestExecute can be run at one time, doesn't CreateObject function try to create and run another instance of the TestExecute or TestComplete?



    I received an instance of TestExecute or TestComplete is already running error message.



    Content of main bat file:


    @echo off

    tasklist /FI "IMAGENAME eq TestExecute.exe" | find /I "TestExecute.exe" 

    IF ERRORLEVEL 2 GOTO Test2

    echo start scripts

    pause

    @echo on

    :Test2

    taskkill /IM TestExecute.exe /F

    Start /wait "TestExecute" "C:\Program Files (x86)\Automated QA\TestExecute 8\Bin\TestExecute.exe"

    call RunTest.bat



    Content of RunTest.bat file:


    @echo off

    start C:\Users\dummy_user\Desktop\TestExecuteVIACom.vbs



    TestExecuteVIACom.vbs


    Sub Test

      Dim TestCompleteApp, IntegrationObject, LastResult





      ' Creates the application object 

      Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication")





      ' Obtains the integration object 

      Set IntegrationObject = TestCompleteApp.Integration





      ' Opens the project 

      IntegrationObject.OpenProjectSuite("C:\TestComplete_Folder\Project_NameFolder\Project_Suite.pjs")





      ' Checks whether the project suite was opened 

      ' If the project suite cannot be opened, closes TestComplete 

      If Not IntegrationObject.IsProjectSuiteOpened Then 

        MsgBox "The project suite was not opened."

        ' Closes TestComplete 

        TestCompleteApp.Quit

        Exit Sub 

      End If 





      ' Needed to process errors 

      Err.Clear

      'On Error GoTo Err_Label





      ' Starts the project run 

      'IntegrationObject.RunProject "MyProject"

       IntegrationObject.RunProjectTestItem ("MyProject,Login")





      ' Waits until the test is over 

       While IntegrationObject.IsRunning

        DoEvents 

      Wend 





      ' Checks the results 

      Set LastResult = IntegrationObject.GetLastResultDescription

      Select Case LastResult.Status

        Case 0: MsgBox "The test run finished successfully."

        Case 1: MsgBox "Warning messages were posted to the test log."

        Case 2: MsgBox "Error messages were posted to the test log."

      End Select 





    Err_Label:

      ' Process errors 

      If Err.Number <> 0 Then 

        MsgBox "Cannot start the test. Reason: " + Err.Description, vbCritical, "Error"

      End If 





      ' Closes TestComplete 

      TestCompleteApp.Quit

    End Sub



    Please suggest.

    Thanks,

    MasterMind






  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi,


    As I've already mentioned in my previous post, you don't need to create a new instance of the application in VBScript. You need to access the active object of the application that is currently running. For this purpose, try using the Set TestCompleteApp = GetObject("TestComplete.TestCompleteApplication") code instead of the line with the CreateObject method.


    Does this help?