Forum Discussion
Let me give an example.
TestCase1 - Validate the values from a form with Fields - Field1 set to "a", Field2 set to "b"
TestCase2 - Validate the values from a form with Fields - Field1 set to "c", Field2 set to "d"
Here we have the same validations, but the "Field1" has been changed to "NewField1"
TestCase3 - Validate the values from a form with Fields - NewField1 set to "e", NewField2 set to "f"
in this case we need to rename the variable and also the values assigned to them.
Hence, the instructions to set the field name and field value should be dynamic which stalls me at the point to declare/create and set values to the variables dynamically.
I'm not sure why the variable name needs to change. All you are doing is validating the contents of two fields in your application under test. The names of those fields in the AUT are not directly related to the variable names in your test code.
What I would do is write your validation to take as string pairs the name and value, something like "Field1|e". That would then be passed as a parameter to a code routine which would take the first string as the field name and the second string as the field content (use aqString.GetListItem to get the individual pieces). Then execute your validation code using a "Find" function to find the field and validate it's contents based upon the passed in strings.
This routine could then be repeated for an field/value pair. If I was doing this ALL in script code, I would even make it an object like {Field1: e, Field2: c} and parse it out that way but I've had difficulty sending objects like that from Keyword Tests to script code so the string pair works best.
This way, you don't have to worry about dynamically changing variable names but simply use a single parameter on a libraried code function to do the validation.
There are probably a number of variations of doing this kind of thing but, generally, what you are looking to do doesn't require dynamically changing variables but a validation function that receives the field name and value as parameters and does the validation that way. No need to create/rename a variable every time you do your validation.
- Marsha_R7 years agoChampion Level 3
Yes, what tristaanogre said! I can understand not wanting a million variables to be declared, but you really can just use the same ones over. If combining everything into one pair is too confusing, then just have a few pairs, one for each different type, but making them permanent variables will take one complication out of your testing.
- eykxas7 years agoFrequent 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
- eykxas7 years agoFrequent 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";
Related Content
Recent Discussions
- 2 days agoGane195