Forum Discussion

RajeshVV's avatar
RajeshVV
Contributor
7 years ago

How to create local variables at runtime for any keyword test in TestComplete

I need to create a set of local variables at the beginning of a Keyword test and then use them later while executing the Test. Is there any possibility to create local variables dynamically as like project variables which can be created dynamically.

 

Project.variables.<variable_name> = "project_variable_value"

 

in the similar fashion can we create any variable associated to any keyword test

 

Keywordtests.<generic_keyword_test_name>.variables.<variable_name> = "local_variable_value"

12 Replies

  • shankar_r's avatar
    shankar_r
    Community Hero

    Hi,

     

    I know we have option to create Keyword test variables at runtime. refer here 

     

    But I'm not sure how we can use keyword test name in dynamic way.

    • RajeshVV's avatar
      RajeshVV
      Contributor

      When we have more control over the Keyword Test variables we may reduce the usage of variables prior to running the test.

      • shankar_r's avatar
        shankar_r
        Community Hero

        As a workaround you can do like below,

         

        Keywordtests.<generic_keyword_test_name>.variables.<variable_name> = "local_variable_value"
        
        To handle this,
        
        var str_keywordtestname = "KeywordTest1";
        
        var objKeyword = eval("Keywordtests." + str_keywordtestname);
        
        Now you will have you keyword test object then you use this object to create 
         dynamic variable.
        
        objKeyword.variable.VariableByName("MsgVar");
        
        

        I haven't worked in Keyword test but I'm guess this will have some help for you to handle dynamic