Forum Discussion

someshg2's avatar
someshg2
Occasional Contributor
11 years ago

Open particular script routine from VBS file

Hi there,



I want to know how to open a Project suites Script routine from a VBS file when testcomplete is already opened with out again invoking the testcomplete



Regards,



G.Someswara Rao

7 Replies

  • someshg2's avatar
    someshg2
    Occasional Contributor
    Ok..thanks simon , I will try with that hope it works





    Regards,



    G.Someswara Rao
  • someshg2's avatar
    someshg2
    Occasional Contributor
    Hi..Simon



    I tried with the following code in vbs file 




    Sub MySub


      ' Initialize variables


      sProjectNameFileName = "C:\Users\u304080\Desktop\26_07_2013\Shakedowns\Shakedowns.pjs"


      sProjectName = "Scenarios"


      sUnitName = "aaaaaa"


      sRoutineName = "funHi"


     


      ' Creates the application object


      Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication")


     


      ' Obtains the integration object


      Set IntegrationObject = TestCompleteApp.Integration


     


      ' Opens the project


      IntegrationObject.OpenProjectSuite sProjectNameFileName


     


      ' Checks whether the project was opened


      If Not IntegrationObject.IsProjectSuiteOpened Then


        MsgBox "The project suite was not opened."


        Exit Sub


      End If


     


      ' Runs the routine


      IntegrationObject.RunRoutine sProjectName, sUnitName, sRoutineName


     


     End Sub





    It doesnot respond ..Can you please check it !!!





    Regards



    G.Someswara Rao

  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi,



    Well this works fine on my side:



       MsgBox "Start" 

      ' Creates the application object

      Set TestCompleteApp = CreateObject("TestComplete.TestCompleteApplication")

     

      ' Obtains the integration object

      Set IntegrationObject = TestCompleteApp.Integration

     

      ' Opens the project

      IntegrationObject.OpenProjectSuite "C:\myProjectSuite.pjs"

     

      ' Checks whether the project was opened

      If Not IntegrationObject.IsProjectSuiteOpened Then

        MsgBox "The project suite was not opened."

      else

       MsgBox "Project opened"

      End if

     

    MsqBox "End"



    Keep in mind that TC must not be running before starting the script. Check your tasklist for wscript.exe running forever.

    You might want to check C:\Users\yourAccount\AppData\Roaming\SmartBear\TestComplete\9.0\Sileng.log for issues.



    In this case, I would not use vbscript without a proper debugging tool. You might want to checkout Powershell.



    Sincerely
  • someshg2's avatar
    someshg2
    Occasional Contributor
    Hi..Simon,



    Thanks for the reply, well you said that TC must not opened before starting the VBS file. My requirement is "Start the Script routine when TestComplete is already opened", Can u please help me in that way.



    Regards,



    G.Someswara Rao
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi,



    It makes it easier if it not already running but you can connect to it if its running. The following works:


    function getTestRunner(){



      if (Get-Process | Where-Object {$_.ProcessName -eq "TestComplete"}){



        try {



          return [System.Runtime.InteropServices.Marshal]::GetActiveObject("TestComplete.TestCompleteApplication")



        } catch {



          Write-Host "Could not connect to running testRunner. Will kill it and try again"

        }



      } else { 



        # if the script was started with no licenses left, this function will never return.



        return New-Object -ComObject "TestComplete.TestCompleteApplication"



      }

    }



    As for VB the documentation states:



    The first step in using TestComplete as a COM server is connecting to it. To create a connection, you have to create a reference to the TestComplete object. This object implements methods and properties to connect and work with TestComplete. You can create a connection by calling Visual Basic’s CreateObject function and passing the TestComplete.TestCompleteApplication or TestComplete.TestCompleteApplication.9 program id to it as a parameter:




    Set TestCompleteObject = CreateObject("TestComplete.TestCompleteApplication")



    This line launches a new instance of TestComplete. If TestComplete is already running, use the Set TestCompleteObject = GetObject(,"TestComplete.TestCompleteApplication") line instead.





    Sincerely


  • someshg2's avatar
    someshg2
    Occasional Contributor
    Thanks..simon for the reply ....i will try that which is more helpfull for me





    Regards,



    G.Someswara Rao