Forum Discussion

nageshp's avatar
nageshp
Occasional Contributor
14 years ago

How to Set Project Variables using COM

Hi All ,




I am unable to set the Project varibles through a program script using TestCompletes COM objects.


I launch instance of TestComplete using code 


        Set objTC = CreateObject("TestComplete.TestCompleteApplication")


        Set objIntegration = objTC.Integration  


        objIntegration.OpenProjectSuite "C:\Test.pjs"


......  and so on....


From here on after I open the project suite , I want to get TestComplete Project Object to set the Project varibales . 


 Like ... Project.Variables.AddVariable  "VarName" , "String"


            Project.Variables.VarName = "MyValue"




But I dont think even after I get the Project Object i will be able to set the Project variables coz there seems to be no methods supported via COM via Project Object to handle Project Variables





However I found a class in TestCompletes COM model named something like 'ItcVariablesRunTime...'  . Sorry I dont remember the exact class name. Anyways this class shows all the methods relevant to Project Varibales like Add Variables , Remove Varibale etc.




Let me know if anyone has implemented this. OR how to set Project Variables via TestCompletes COM.





Note : I have been using TestComplete v7.52




Thanks


Nagesh
















5 Replies

  • Hi Nagesh,



    You can access the Project object via COM using the GetObjectByName method of the Integration object. Then, you can add and set project variables like this:

    ' Switch TestComplete to the playback state

    objIntegration.RunTestByName "ProjectName", "Script|Unit1|Main"



    ' Set project variables

    Set objVars = objIntegration.GetObjectByName("Project").Variables

    objVars.AddVariable "VarName" , "String"

    objVars.VarName = "MyValue"


    Please note that the COM access to the Project object is available only after the test run was started in TestComplete - therefore, there's the RunTestByName call before GetObjectByName in the script. The reason for this is that a project suite can contain multiple projects, and when no test is running, the Project object doesn't "know" which project to access.
  • nageshp's avatar
    nageshp
    Occasional Contributor
    Hi Helen,

    Thanks so much for the reply.

    I'll try out the code you have mentioned and revert.



    Thanks again !!!

  • nageshp's avatar
    nageshp
    Occasional Contributor
    Hi Helen ,



    The code you have sent works absolutely fine with TestComplete version 8.



    As I have been using v7.52 , I found that its COM does not have the 'RunTestByName' method at all .



    To make it work in 7.52 I have first run the project but the problem is that via COM how to add Project test items for a project to run..



    IntegrationObject.RunProject "ProjectName"   ' How to add a test item/Unit 1 script  to Project  .



    Set objVars = IntegrationObject.GetObjectByName("Project").Varibales.



    If I manually set the Project item it works , but i want to set the project test items through COM and then run the project.



    Thanks

    Nagesh
  • Hi Nagesh,



    Currently, there's no way to add test items via COM. However, you can configure the test items manually and then change their Enabled property via COM to control which test items will be executed during the project run.



    We also have an existing feature request for a COM way to add test items, and I've increased its rating based on your post. Thanks!