Ask a Question

Creating array with Project variable

SOLVED
TestQA1
Contributor

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.
4 REPLIES 4
TCYKPB
Contributor

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 

rraghvani
Super Contributor

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]);
    }
}

 

Thanks. How do you intialise the object type array in this case. If we don't it remains unassigned in Variables page?

rraghvani
Super Contributor

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]);
    }
}

 

cancel
Showing results for 
Search instead for 
Did you mean: