Forum Discussion

jlperez's avatar
jlperez
Occasional Contributor
9 years ago

A cache mechanism to Find GUI objects

Hi all,

I have implemented a cache mechanism (dictionary based) in order to improve performance in the
way GUI objects are searched in the system when testing a web application by
executing a battery of automated test cases. I am using the find function
(eval function was not a solution as it didn't provide good response times in my case)
and the automation code is done in c# script with TC 11. As it apparently works
well in Chrome and automation is faster now, I am experiencing some issues in
Firefox when executing the battery of automated test cases. I observe that Firefox
consumes increasingly more memory up to a point where the web application
behaviour becomes unstable. Below I show the basics of the cache mechanism
along with an explanation (sorry if it's so long). A text file is attached too for indentation

purposes.

 

If someone can help I would be very appreciated.


Thanks a lot in advance.


//Variables are declared in a global script module that will be used everywhere
//The cache mechanism is based on a dictionary object, and the search of the
//GUI objects in the system is based on the "Fullname" unique property


//dictionary (key, value) structure that contains the fullname of the
//GUI object (key) and the object returned by the find function (value)

var dict_GlobObjects;

 

//Initialization section: before any test case is called the following
//initialization code is executed. This code is placed in an initialization
//script module.


dict_GlobObjects = new ActiveXObject("Scripting.Dictionary");


//Working section: The following function is called many times during the test
//battery execution each time an interaction is needed with a panel object type
//the function LowLevel_Panel_Exec is called
//Similar functions are defined for links, pages, etc

 

function LowLevel_Panel_Exec(strAction, dict_Parameters, dict_TstCompl)
{


var myFullname;
//the fullname property of the panel object to interact with
myFullname = dict_TstCompl["Item"]("Fullname");

//local variable used to interact with the panel object
var myPanelObject;

if (dict_GlobObjects["Exists"](myFullname))
{

myPanelObject = dict_GlobObjects["Item"](myFullname);

if (!myPanelObject["Exists"])
{
//If the object does not exist, it is searched again using the
//find function
dict_GlobObjects["Item"](myFullname) = myQuickFind(myFullname);
myPanelObject = dict_GlobObjects["Item"](myFullname);
}

} //if (dict_GlobObjects["Exists"](myFullname))
else
{
//The object is not in the cache, put it into the cache, search it first
//using the find function

dict_GlobObjects["Add"](myFullname, myQuickFind(myFullname));

//local variable to work with is assigned the object content
myPanelObject = dict_GlobObjects["Item"](myFullname);

}

 

....here the function works with the myPanelObject accessing its methods and properties....
....for example a piece of code is ...
if (myPanelObject["VisibleOnScreen"])
myPanelObject["Click"](xCoord, yCoord, 0);
... but there is much more code not included as it's of no interest for the issue ...


} // LowLevel_Panel_Exec()

 


//The function myQuickFind is a function that searches the GUI object in the object hierarchy
//of the system, it is an expensive function, so if it's possible to avoid it, use the values
//in the cache. It is located in a module that can be accessed from the rest of the script modules
//It consists of a particular use of the find function in which the hierarchy of each call
//is just one (see third parameter below), it is a directed search from the parent to the last
//child in the hierarchy. The results are better than a single call like
//pParent["Find"]("FullName", strChildFullName, 100);


function myQuickFind(FullName)
{
var pChild = null;

.....Loop begins
....

pChild = pParent["Find"]("FullName", stringChildFullName, 1);
....
..... Loop Ends

return pChild;

}

 

//Ending section: once the whole battery has been executed the following code is
//executed (resources are released)

if (dict_GlobObjects.Count > 0)
{
dict_GlobObjects["RemoveAll"]();
}

  • Hi,

     

    If you can provide the Support Team with the steps to reproduce, please create a case. Send us a project, which works with a public website (e.g. smartbear.com) using your algorithm. Also, let us know the amount of the consumed memory (in Chrome/ in Firefox) during the test.