You are on page 1of 9

uesday, November 3, 2009

Dotnetfactory 2: DATE/TIME format conversion Reactions:


Earlier i have created a .dll built in vb to convert the given date/time to a specified format. There are two problems with it: Companies(most of them) won't allow people to use external dlls or exes to be used or downloaded. There was no way to specify the input date format ie if the i/p date is in "MMyydd" format you can not convert it. So here is a work around: 'Start of code************************************************************************* msgbox DateTimeConverter("670919","yyMMdd","dd-MMM-yyyy") Function DateTimeConverter(InputDate,InputFormat,OutputFormat) Set DateTime =DotNetFactory.CreateInstance("System.DateTime").ParseExact(InputDate, InputFormat, culture ) DateTimeConverter = DateTime.tostring(OutputFormat) Set DateTime = Nothing : Set culture = Nothing End Function 'End of code************************************************************************** Enjoy...
Posted by Hari Sreekanth Upadrasta at 3:45 AM 2 comments

Dotnetfactory 1: Searching Files in a directory/folder including the subdirectories Reactions:


I have decided to post tips or my findings on using .net in QTP .So the first tip is searching files in side a folder. This piece of code retrieves the file names and the file path with the specified pattern even if they are in the subfolders. 'Start of code ************************************************************************* Set SearchOpt = DotNetFactory.CreateInstance( "System.IO.SearchOption") Set dirInfo = DotNetFactory.CreateInstance( "System.IO.Directoryinfo",,"C:\New Folder" ) Set Ofiles= dirInfo.GetFiles( "*.pdf",SearchOpt.AllDirectories) For i = 0 to Cint(Ofiles.Length)-1 Print Ofiles.getvalue(i).DirectoryName & "\" & Ofiles.getvalue(i).Name Next 'End of Code ************************************************************************* Please help yourself by creating functions that you want.
Posted by Hari Sreekanth Upadrasta at 12:52 AM 0 comments

Wednesday, September 2, 2009

When not to place positive condition in "If" Reactions:


It is general practice to keep positive conditions(some thing we are expecting to happen) in If part of the "If Else". But there will be situations which you have to be really careful about doing so. Consider a Test Automation Project where you want to run some 100 Test Script in a batch. So in this condition you may ask your Test not to stop if an error occours. So you use "On Error Resume Next" here is a sample script: On Error Resume Next If Browser("brow").Page("pag").link("lnk").exist Then Reporter.reportevent micpass,"checking link","link lnk exists" Else Reporter.reportevent micfail,"checking link","link lnk does not exists" End If Just copy the code(no need of any object repository) and run it in QTP. WoW you will observe the your script passed(with out object repository or any thing). Similarly cpoy and run the below code: On Error Resume Next If not(Browser("brow").Page("pag").link("lnk").exist)Then Reporter.reportevent micfail,"checking link","link lnk does not exists" Else Reporter.reportevent micpass,"checking link","link lnk exists" End If Now the script fails and it explains my statement.I know that i am not good at explaining things so i leave the rest to you.Thanks for reading
Posted by Hari Sreekanth Upadrasta at 6:56 AM 0 comments Labels: On Error Resume Next, QTP, VBscript

Tuesday, August 11, 2009

Skip the Page Object Reactions:


But why? Because i don't need it(Page). Use? Reduces time by a fraction of actual time. How to use? Just delete the Page Object

Browser("Google").link("Advanced Search").click
Posted by Hari Sreekanth Upadrasta at 8:27 AM 2 comments

Saturday, June 6, 2009

On How i was fooled by Debugger using Dictionary Object in QTP Reactions:

Recently i was working on a project where i have been using Dictionary object a lot. In a function i had to retrieve the number of Items that i have added to the Dictionary. But to my utter dismay I found that the number of items in the dictionary turned out to be two more than the items actually added to it. So I tried to find out of how did that happened, when I was not able to, I googled a lot (thinking that dictionary objects may be collecting some garbage value)but found nothing that could satisfy me. So I just left it there. The other day I started working on other things where I had to add some variables to debug viewer and verify their values in runtime. After the second run of the test I found that the values of the variables that I added to the debug viewer are having value as EMPTY. Then I realized the real culprit for making me and my dictionary object go bonkers is THE DEBUG VIEWER How did this happen: I entered two dictionary items in to the debug viewer for which the keys are non existent. And the next time I ran my script, the items got initialized to empty (Dictionary can take Empty values). So as a victim of the Debug Viewer I just want to tell you a few things. Points that should be kept in mind while using debugger while debugging Remove all the items from the debug viewer after debugging. QTP can hang if you have placed exist statement in the debug viewer and start your script. QTP can be very slow if you debug your scripts with lot of Exist statements in it(debug viewer). And Finally dont do the mistake I have done(Dictionary can take Empty values)

With Regards, AVictim

have been working on some issues Recently.In the process i came to know that vba is somewhat superior to vbscript in Test Automation scripts development(Check thislink).So i started creating a function library in vba for use in vbscript and succeded upto an extent.
So finally i broke the shackles and started posting in my blog.I Here is my procedure:

There are lots of Advantages of using a vba function library in qtp/vbscript which will be mentioned in my next post until then happy scripting.
Posted by Hari Sreekanth Upadrasta at 3:56 AM 1 comments Labels: MODULE, QTP, VBA, VBscript

Wednesday, October 8, 2008

Convert any DATE/TIME format to any DATE/TIME format. Reactions:


Hi,

Finally i think i have done what i have thought of doing from long time. This has been bugging me from a long time.Now we can convert almost any DATE/TIME format to any required DATE/TIME format. Suppose you want to convert 12,jan 2008 to january,08-12. you can just do that as simple as this: reformat = DTFormat("12,jan 2008","MMMM,YY-DD") Procedure:

1. 2. 3. 4. 5.

Download the Zip File DTFormat to your QTP's Bin folder(or any where you want). Unzip it (The folder contains three files DTFormat.dll , DTFormat.vbs and DTFormat.Doc). Double click on DTFormat.vbs file. Enter the name with which you want to use this functionality in QTP. Click OK button.

This is very powerful indeed Read the Document in the zip file to know the power of it. This is also a powerful time converter as well. regards,
Posted by Hari Sreekanth Upadrasta at 5:34 AM 0 comments

Tuesday, October 7, 2008

Masking Passwords Reactions:

Today i had a weird situation.i had to enter my password in a driver script before my project mates and my manager, to show them a demo of how it works.The situation is so weird that i can't ask them to turn to the other side nor was i capable of entering passwords faster(i have to enter password in a inputbox). So, i thought of exploring it a bit and did some Google search and got some piece of code it uses the property of the password element of the HTML. Here is the code: <SCRIPT LANGUAGE="VBScript"> Sub RunScript OKClicked.Value = "OK" End Sub Sub CancelScript OKClicked.Value = "Cancelled" End Sub </SCRIPT> <BODY> <font size="2" face="Arial"> Password: </font><font face="Arial"> <input type="password" name="UserPassword" size="40"></font></p> <input type="hidden" name="OKClicked" size = "20"> <input id=runbutton class="button" type="button" value=" OK "

name="ok_button" onClick="RunScript"> <input id=runbutton class="button" type="button" value="Cancel" name="cancel_button" onClick="CancelScript"> </BODY> Copy the code and paste it in note pad and save it in your C drive as "Password.htm" Now open another notepad, paste the code below and save it as Password.vbs Set objExplorer = WScript.CreateObject _ ("InternetExplorer.Application", "IE_") objExplorer.Navigate "file:///C:\Scripts\password.htm" objExplorer.ToolBar = 0 objExplorer.StatusBar = 0 objExplorer.Width = 400 objExplorer.Height = 350 objExplorer.Left = 300 objExplorer.Top = 200 objExplorer.Visible = 1 Do While (objExplorer.Document.Body.All.OKClicked.Value = "") Wscript.Sleep 250 Loop strPassword = objExplorer.Document.Body.All.UserPassword.Value strButton = objExplorer.Document.Body.All.OKClicked.Value objExplorer.Quit Wscript.Sleep 250 If strButton = "Cancelled" Then Wscript.Quit End If 'Now you can use the entered password msgbox strPassword Now double click on the Password.vbs file Remember there are other ways of doing it even more effectively but this is the most robust way(it works independent of O/S). Regards,
Posted by Hari Sreekanth Upadrasta at 4:03 AM 2 comments Labels: HTML, Mask Password, QTP

Thursday, September 4, 2008

Automation Outlook:Verify Mail in Outlook Reactions:

Hi, We have seen in my previous post on howto send email no lets look at how to verify them. olFolderInbox = 6 varSubject = "Test Mail" 'The subject of your mail Set objOutlook = CreateObject("outlook.application") Set objNameSpace = objOutlook.GetNameSpace("MAPI") Set Inbox = objNameSpace.GetDefaultFolder(olFolderInbox) Set Mail = Inbox.Items.Restrict("[Subject] = " & Chr(34) & varSubject & Chr(34) ) 'The above line is used to filter mails by subject similarly u can use "From" in place of subject. if Mail.Count = 1 then Msgbox "Mail Found" Else Msgbox "Mail Not present or there are More than one mail with same subject" End if Thats it for now .
Posted by Hari Sreekanth Upadrasta at 1:24 AM 5 comments Labels: Mail, MAPI, Outlook, Outlook Automation, QTP

Wednesday, August 27, 2008

Automating Outlook:Creating Outlook Items-Mail Reactions:


Hi, Wondering how to send a mail just check below. 'Make sure that outlook is open Set oOutlook = GetObject(,"Outlook.Application") Set oMailItem = oOutlook.CreateItem(olMailItem) oMailItem.Display oMailItem.To = "RecieverMail@mail.com" oMailItem.Subject = "AutomaticMail" oMailItem.Body = "This is Mail Body" Set oAttachment = MailItem.Attachment oAttachment.Add "C:\My Documents\Sample.xls" oMailItem.Send Here the previous sentence may give a popup so try using send keys method like this Set WshShell = CreateObject("WScript.Shell") WshShell.SendKeys "%s" So here comes the end check this blog for further tips on Outlook Automation.
Posted by Hari Sreekanth Upadrasta at 3:45 AM 0 comments Labels: Mail, Outlook, Outlook Automation, QTP Send Mail, Send Mail, VBscript

Tuesday, August 5, 2008

Before Automating SAP using QTP Reactions:


Hi, I have been working on a SAP implementation testing project from long time. I had a chance to work on Automating SAP. As you know about a famous Quote "Please read the instruction document before proceeding" is never followed either because of confidence or ignorance. OK iam done with saying philosophy. and these are the basic settings you need to enable scripting on your SAP GUI for windows apps 1) Client side setting 2) Server side setting Client side setting:Upon logging on to the SAP R/3 ,click on Customizing of Local Layout SAP toolbar button as shown below:

And click on Options button. The following window opens. Navigate to Scripting tab and select "Enable scripting" checkbox and deselect the other two options below the "Enable scripting" checkbox.This complets enabling clientside scripting. Serverside Setting:Run the transaction code RZ11 ,this opens Maintain Profile Parameters page entersapgui/user_scripting and click on Display button.

this opens

check if Profileval is set to TRUE else click on change value button and change the value of profileval to TRUE. This completes our Enable scripting process.
Posted by Hari Sreekanth Upadrasta at 2:52 AM 0 comments Labels: Client side, QTP, SAPI, Server side

Friday, July 11, 2008

A Word A Day 1st Day API Reactions:


This is a Post started by Bughunterz as a part of making test automation practitioners get updated with the jargons used in Test Automation and know how they are used.Let's get started.

API(Application Programming Interface): An API is a guide(remember it is just a guide) which keeps in it all the constants , objects and the object's methods and parameters with which the application or the application's features can be used in another program. EX: Most of you might have came across QTP automation object model documentation this is QTP's automation API. Another EX: Speech API(SAPI) is an API developed by Microsoft to allow the use of speech recognition and speech synthesis within Windows applications(Office).Here the Office applications are using the SAPI. In the same way if your manager comes to you and asks you to make your script speak once your test is completed. try the following lines in your QTP or VBscript editor and run it: '********************************************************************************** Dim voice Set voice = CreateObject("SAPI.SpVoice") voice.speak "Yahoooo, it is working" '********************************************************************************** If you get a chance to look at the SAPI you will find that SpVoice is the object and speak is the method

of the object SpVoice:

Looks interesting right.Just try some thing else now.


Posted by Hari Sreekanth Upadrasta at 6:22 AM 1 comments

You might also like