cancel
Showing results for 
Search instead for 
Did you mean: 

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

Highlighted
Contributor

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"
-Rajesh V V
12 REPLIES 12
Highlighted
Contributor

I don't know if this workaround can help you, but in some Keyword I have to use variables for if else condition (for example).

 

(I work with Javascript language.)

 

I write this in script :

 

function AddVar(name, type){
  Project.Variables.AddVariable(name, type);
}

function SetVar(name, value){
  Project.Variables(name) = value;
}

function DelVar(name){
  Project.Variables.RemoveVariable(name);
}

Then I can use this three functions to create and modify variables during a KeywordTest by using Project.Variables.myVar

Highlighted
Contributor

@eykxas This is related to Project level variables. I need to create variables which can be created locally for each keyword test.

-Rajesh V V
Highlighted
Contributor

I think you ca do the same thing with KeywordTest.

 

For example with this instruction (still for javascript) :

 

 

KeywordTests.NameOfKeywordTest.Variables.AddVariable()

and these :

 

 

 

var s;
 
// Get the variable value
    s = KeywordTests.KeywordTest1.Variables.MsgVar;
// -- or --
    s = KeywordTests.KeywordTest1.Variables.VariableByName("MsgVar");
  
// Set the variable value
    KeywordTests.KeywordTest1.Variables.MsgVar = "New Value";
// -- or --
    KeywordTests.KeywordTest1.Variables.VariableByName("MsgVar") = "New Value";
New Here?
Join us and watch the welcome video:
Announcements
Join TechCorner Challenge!
Want a fun and easy way to learn TestComplete? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get properties of a web page element

See replies!

Compare images using the Region Checkpoint

See replies!

Compare HTML table with Excel file and correct data in Excel file

Participate!

How to execute remote test and obtain results via Test Runner REST API

Participate!
Top Kudoed Authors