Creating array with Project variable
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022
01:37 PM
09-19-2022
01:37 PM
Creating array with Project variable
Hi,
I have a func that repeats in different Scenarios of feature.
function test() {
If (a> b) {
a = project.variable.temp
}
}
Now I need to have an array variable inside the function that stores the values of 'a' each time the function is called in Scenarios and then finally return itself from the function as a normal array. Something like when scenario1 runs this function, 'a' would be 3, then 2,6,0 in rest of the scenaris and the final array would be finalarray = {3,2,6,0} . So when I need to get its value in another function i can simply call by index.
Any help is appreciated.
Thankyou.
I have a func that repeats in different Scenarios of feature.
function test() {
If (a> b) {
a = project.variable.temp
}
}
Now I need to have an array variable inside the function that stores the values of 'a' each time the function is called in Scenarios and then finally return itself from the function as a normal array. Something like when scenario1 runs this function, 'a' would be 3, then 2,6,0 in rest of the scenaris and the final array would be finalarray = {3,2,6,0} . So when I need to get its value in another function i can simply call by index.
Any help is appreciated.
Thankyou.
Solved! Go to Solution.
Labels:
4 REPLIES 4
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2022
01:44 PM
09-19-2022
01:44 PM
dump those values into a file and pick them up each time you need them.
in scenario1 you can erase the file and re-create it, so by the time you run scenario4 you have clean data
https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqfile/methods.html
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022
02:29 AM
09-20-2022
02:29 AM
Here's a simple example,
function test1()
{
// Temporary project (or suite) variable of type Object
Project.Variables.TempArray = new Array();
// Add
Project.Variables.TempArray.push("3");
Project.Variables.TempArray.push("2");
Project.Variables.TempArray.push("6");
Project.Variables.TempArray.push("0");
// Print
for (var i = 0; i < Project.Variables.TempArray.length; i++) {
Log.Message(Project.Variables.TempArray[i]);
}
}
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022
02:38 AM
09-20-2022
02:38 AM
Thanks. How do you intialise the object type array in this case. If we don't it remains unassigned in Variables page?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2022
02:44 AM
09-20-2022
02:44 AM
You can initialise the object type at the very beginning of the script (global variable),
// Temporary project (or suite) variable of type Object
Project.Variables.TempArray = new Array();
function test1()
{
// Add
Project.Variables.TempArray.push("3");
}
function test2()
{
// Add
Project.Variables.TempArray.push("2");
}
function test3()
{
// Print
for (var i = 0; i < Project.Variables.TempArray.length; i++) {
Log.Message(Project.Variables.TempArray[i]);
}
}
