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

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

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

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

@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

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

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
Script Wanted
Let's start July with new challenges!

Create a script to pass custom command-line arguments as a test parameter for the TechCorner tag!

Will you dare to take the challenge?


Top Kudoed Authors