Monday 17 February 2014

Handling AutoComplete Text box using TestComplete

Hi,

Handling auto complete text boxes using TestComplete is little tricky, where you will have to try few combination of keys and simulate key press events.
Recently, I came across one such scenario and here is the solution for the same:

As shown above, the highlighted text field was the autoComplete , text box that gets loaded with a default value.
My purpose was to remove the existing item in the text box and to simulate user actions of entering data in to the text field.
While, using "obj.value" or "obj.setText()" methods to set value in the text box were not helpful. Because, the page did not get refreshed automatically and the expected fields didn't appear.


I had tried the Obj.Keys method as shown below, with which page got refreshed automatically, assuming user has input the data, loading the expected fields.

1) grid.Cell(1, 1).Textbox("txtAlphaCode").DblClick();  // this is to double click on the textbox to clear the                                                                                           default value      
2)  grid.Cell(1, 1).Textbox("txtAlphaCode").Keys("[Del]"); // this is siumlation of hitting delete button
3)  grid.Cell(1, 1).Textbox("txtAlphaCode").Keys(policyData.Value("alphaCode")); // this is simulation of                                                                                                                                         user input

That's it!!

Now, the simulation of user input for autoComplete text box is done :-)

Leave your comments/doubts on scenarios that you think, I may help!!

Wednesday 15 January 2014

Automating outlook for accessing mails and mail attachments using TestComplete

Hi,


Here I will be discussing on handling/automating Microsoft outlook using TestComplete:

Though there are many documents that details on handling outlook mail items using TestComplete. I couldn't find references on handling attachments that come with the mail.
Here is the code snippet for the same:
   
function isMessageReceived2010(accountName, senderEMail, eMailSubject)

{

var OutlookApplication =

 

Sys.OleObject("Outlook.Application");  

var NamespaceMAPI = OutlookApplication.GetNamespace("MAPI");

var abc=NamespaceMAPI.Accounts.Item(1);

// Check whether the specified account exists:

if (NamespaceMAPI.Accounts.Item(accountName) != null)

{

NamespaceMAPI.SendAndReceive(false);

var targetfolder="c:/";

// Get the "Inbox" folder 

var inbox = NamespaceMAPI.Folders(accountName).Folders("Inbox");

//get all mail items and store it in a variable

var items = inbox.Items; 

aqFile.WriteToTextFile("c:/sample/abc.txt",items.Count,aqFile.ctUTF8);

 //traversing through the mail items

for (var i = items.Count; i >= 1; i--)

{

//get the mail subject

aqString.Trim(items.Item(i).Subject,aqString.stAll);

//you can also get any other details on mail, as required 

aqString.Trim(items.Item(i).SenderEmailAddress,aqString.stAll);

 

 

if (items.Item(i).Subject == eMailSubject)

{

//get the number of attachments that come with the expected mail

aqFile.WriteToTextFile("c:/sample/abc.txt",items.Item(i).Attachments.Count,aqFile.ctUTF8);

 

var myItem=items.Item(i);

if(myItem.Attachments.Count>0)


aqFile.WriteToTextFile("c:/sample/abc.txt","do i have attachments,my count is "+ myItem.Attachments.Count,aqFile.ctUTF8);

//get the attachment name and print it 

attachmentName=myItem.Attachments.Item(1);

aqFile.WriteToTextFile("c:/sample/abc.txt","my attachment name" + attachmentName,aqFile.ctUTF8);

//save your attachment in the preferred path and preferred format

attachment.SaveAsFile("c:/sample/as.pdf");

/* Now, in case if the attachment has to be compared with an other item, use TestComplete checkpoint concept, by storing the base lined document in stores compare it with the attachment that is downloaded from mail – u r done! */

Files.PDS_IAL_SGIO_pdf.Check("C:\\sample\\as.pdf"); 

return true;

}

}

}

return false;

} else

{

OutlookApplication.Quit();

return false;

}

 
Hope this snippet helps :-)



 
 

 

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.