Monday 9 December 2013

Handling dynamic function calls in TestComplete

Here, we will be discussing on handling the dynamic function call in TestComplete.
Consider a scenario where you perform the steps like


scenario 1 will have a flow like below:

1)Login
2)createPlan
3)addItem1ToPlan
4)savePlan
5)Logout


To handle this scenario, we will have created a function to perform each step and call them in the above order, which will ultimately create a scenario, as shown.
In most automation projects, when functionalities are grouped together, almost 60% of functions will have the same flow. To put it more clear,

scenario 2 will have a flow like below:

1)Login
2)createPlan
3)addItem 2ToPlan
4)savePlan
5)Logout

So, rather than calling the base functions again and again, you can call the expected functions dynamically, with the same flow,which avoids code repeatation and optimizes it.Below the strategy for the same


Generalized Function:

//here, get the expected function name from excel
//var FunctionName="addItem 2ToPlan"
1)Login
2)createPlan
3)eval(FunctionName)
4)savePlan
5)Logout

Problems with eval():
 Passing object as parameter to function called by eval().....
Though, eval() in Javascript handles the problem of dynamically calling the expected functions.
When, the Function that has to be called contains Strings as parameters, eval() will work fine.
But, when the parameter for the function to be called contains objects, eval will not work. To overcome this, in TestComplete, we can make use of Project variables. The project variables can contain variables of any type(String,integer and object) that you will be needing throughout your project.(These, are similar to Environment variables in QTP).

So, add the required object that has to be passed as a function parameter to eval, in Project variables and receive the variable in the function definition , which will be a good work around.

ex:
/*here, get the expected function name from excel, if the param2 is an object,add it to project variables at the start*/

var FunctionName="addItem 2ToPlan"+"('"+param1+"');";



Project.Variables.AddVariable("param2", "Object");
Project.Variables.param2=ExcelObj;//some excel object, that you have got.


1)Login
2)createPlan
3)eval(FunctionName)
4)savePlan
5)Logout


 In function definition:

function addItem 2ToPlan{

var ExcelObj;ExcelObj=Project.Variables.VariableByName("param2");
//now proceed further

}


 Hope this helps :-)





 

Tuesday 3 December 2013

Basics of Automation with TestComplete

Hi,

I will here be discussing my learning experience with testcomplete..

Identifying objects in TestComplete through object spy:

All automation tools, intend in capturing the object properties and perform the automation, by comparing the values it has versus with the object properties obtained during run time, in the application.
TestComplete and QTP does this property capture of objects using object spy.

Object Spy
 
The object spy screen shot is shown above. Just a click and drag of the highlighted icon, on the required object will fetch the properties of that object and we may use those properties in our scripts(which will be discussed later in this section).


Keyword driven script/Record-playback in TestComplete:


As like any other Automation tools available in the market, TestComplete provides option to Record the user's activity on the screen, saves the object propoerties, to identify the object and replays the same activities when playback button is clicked.
The above screenshot shows, how to start recording and the script generated after recording.

But, in a typical Automation environment, mere record -palyback is not enough.We will need lot more than that, like if-else ,switch conditions and many more.But, the neverthless we can rule out the use of object spy and Record options.