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 :-)