Forum Discussion

hlalumiere's avatar
hlalumiere
Regular Contributor
14 years ago

Is it possible to modify a Project.Variables before running a test via COM?

As the title says, I need to modify a project variable before running a test through TestExecute's COM access. I run individual test units through the .RunProjectTestItem of the Integration object. As I understand it, GetObjectByName throws an exception if a test is not running at the time of its calling (which really makes no sense at all to me; why would you want to modify a variable while a test is running??). How should I go around that? Start the test, pause it, change the variable, then continue? How do I pause a test without stopping execution?



Is there a more complete documentation that describes the datatypes and interfaces available through COM in detail?



Also I saw the other similar post where it is suggested to use IntegrationObject.GetObjectByName("ProjectSuite").Variables, but GetObjectByName returns an Object, what type should I cast it to to be able to access the .Variables property?

6 Replies

  • simon_glet's avatar
    simon_glet
    Regular Contributor
    Hi Aleksander,



    To test your project is opened, with TC 9.2, you have IntegrationObject.IsProjectSuiteOpened().



    Sincerely
  • simon_glet's avatar
    simon_glet
    Regular Contributor
    There is a way to change Project.Variables before running a test:



    By invoking the following generic function with RunRoutineEx from the COM interface:


    function setProjectVariable(aVariableName, aValue)


    {


      Log.Message("Before Setting value");


      Log.Message("Project.Variables." + aVariableName + " = " + eval("Project.Variables." + aVariableName +";"));


      


      eval("Project.Variables." + aVariableName + "=" + '"' + aValue + '"' + ";");


      


      Log.Message("After Setting value");


      Log.Message("Project.Variables." + aVariableName + " = " + eval("Project.Variables." + aVariableName +";"));


    }




    The project variables values will remain as long as the project is loaded. 

    To set 10 variables you will have to invoke the function 10 times. There is no way to have a variable number of function arguments through the COM interface.



    Sincerely

    Simon Glet

     

  • hlalumiere's avatar
    hlalumiere
    Regular Contributor
    That is essentially what I did, except in my case the variables to change were predictable, so a single invoke through RunRoutineEx was fine.



    Still, it's kind of sad that a tool written by programmers for other programmers makes you jump through completely unnecessary hoops like this. How hard is it to declare a public property exposing  a collection? I personnally would like to know which OOP principle this kind of design adheres to... (although I already know the answer: none...)

  • Simon Glet, can you help me? You sad:



    The project variables values will remain as long as the project is loaded. 



    In my case variables are becomes empty. How can I know that project is loaded? Is it some particular command?





    I am using RunRoutineEx and then RunProjectTestItem (here I have empty variable). 



    Thanks