Saturday, November 12, 2011

Automating PDF Using QTP

Well i am working on a QTP project and had this task of automating PDF using QTP.

I have had no experiences in automating pdfs before but after some survey i find that there are so many ways in which we can do so.I found some guidelines here and there but most of them were misguides and asking me to purchase software/licences.

In this blog post i am sharing some insight on the different techniques.
For basic QTP users i must first explain what is an object creation.This would enable to understand the below with ease.

When you want to add objects in the object repository you just open the repository and click on the + sign.But now you can improvise by creating objects.For that you must know the name of the appropriate application.
Lets explain with an example of opening internet explorer.

SystemUtil.Run ( FileName, Parameters, Path, Operation ) OR InvokeApplication "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.google.com"

Now if you can create an object of internet explorer then we can view a lot of options as dropdown.Here is the syntax:  createobject(Servername.typename) where Servername would be the application providing the object and typename would be the type or the class to create object for.
Set NewOBj = createobject("InternetExplorer.Application")
NewOBj .visible=true
NewOBj .navigate"http:\\www.google.com" 
When you type .(dot) after  NewOBj you will find a lot of options to choose from.

When you have created an object of an application you can get a lot of options to choose from.

Coming back to our case with PDF automation,we can automate PDF in the below mentioned ways based on our requirement.

---------------------------------------ADOBE READER-------------------------------
1.If Adobe Reader is installed in the machine
Then we can use Set NewOBj = createobject("AcroPDF.PDF").
Example: To Print a pdf file
Set objAcroPDF = CreateObject("AcroPDF.PDF")
objAcroPDF.LoadFile("C:\D2\Scanner\test.pdf")
objAcroPDF.PrintAll
Set objAcroPDF = Nothing
This technique is limited and contains only a very few options and can be used for purposes like printing the pdf file.Haven't noticed anything significant about this. 

----------------------------------------ADOBE ACROBAT------------------------------

2  .If Adobe Acrobat is installed in the machine
Then we can use  
  a)  Set oPDFDoc = CreateObject( "AcroExch.PDDoc" )
Example To get the number of pages of a pdf file
 Set oPDFDoc = CreateObject( "AcroExch.PDDoc" )
    If oPDFDoc.Open( FileName ) Then
        GetNumPagesInPDF = oPDFDoc.GetNumPages()
        Set oPDFDoc = Nothing
    Else
        GetNumPagesInPDF = -1
    End If

   b)  Set PdfForm = CreateObject("AFormAut.App")--to manipulate from pdf forms
   c)  Set objAcrApp = CreateObject("AcroExch.App")--creating acrobat application object
   d)  Set objAVDoc = CreateObject("AcroExch.AVDoc")--we have to create one avdoc object per displayed document.
    
 Example: To open a pdf file display it for sometime and then close it.
Set objAcrApp = CreateObject("AcroExch.App")
objAcrApp.Show()
Set objAVDoc = CreateObject("AcroExch.AVDoc")
objAVDoc.open "PATH of PDF","Title"
wait(200)
objAVDoc.CloseAllDocs
objAVDoc.exit
Set objAVDoc=nothing
We can use  objAVDoc.FindText("text") before closing,if we want to find if a text is present or not.

--------------------------- LEARNQUICKTEST.MANIPULATEPDF.DLL-----------


3.  If you have do not have Adobe Acrobat but only have the Adobe Reader,then you can download a copy of  an API from this link  http://www.learnqtp.com/learnquicktestpdf-api-manipulating-pdfs-in-qtp/
The instruction for the download and usage is given
Once it is installed on the system then you can create an object of the DLL file LearnQuickTest.ManipulatePDF.dll
Note:This Dll file can also be installed alternatively by registering it in the RegAsm.exe.
Search for the RegAsm.exe file in your system.Once found goto Run and type cmd.Once the command screen opens type "PATH of RegAsm.exe\RegAsm.exe" "PATH of Dll File\LearnQuickTest.ManipulatePDF.dll"   
Set oPDF=createobject("LearnQuickTest.ManipulatePDF")
You will get a dropdown option after you type oPDF.

----------------------------------- PLUG-IN ADOBE APTT----------------------------------

4.     If you want QTP to read PDF files and add objects directly then all you need is to download ADOBE APTT plugin.If you install ADOBE APTT plugin, QTP starts identifying the objects in PDF.This can be downloaded from the link http://labs.adobe.com/technologies/aptt/
 


--------------------------------------------------------N.B---------------------------------------------------------------------

The following will be needed to grasp a better understanding
1)How to install/uninstall DLL files(explained above in case #3)
2) If qtp is not installed but you want to test codes
Ans) write the codes in text file.save the file in .vbs fromat.Then double click this file for autorun without QTP
3)How to know the names of applications of which we can create an object of.
Ans)Goto Run.Type regedit.Registry editor will open and you can view all the registry files.Typical names like AcroExch.PDDoc can be found under adobe or you can manually search for all applications under adobe acrobat.

Hope this benefits those involved in PDF QTP projects.Thanks ....

Sunday, February 20, 2011

A biker's fancy

I came to Mumbai for a job and here you can find all sorts of people and all sorts of bikes.The land prices are so high here that it is preferable that you stay in a relatively cheaper apartment which is quite far from office.So transportation must be taken care of.To solve this having a bike/car is important.Otherwise you could end up giving half of your salary to auto-rickshaw-wallas.

Here are few tips on how to decide which bike to purchase.Take a deep breadth and decide what are those criteria on which you are deciding on purchasing a bike.There are 3 bike categories.If you love to race and always want to bend forwards and keep the speedometer at its peak then go for a sports bike.

A sports bike is something thats going to keep your adrenaline pumping all the time.Its kind of limited edition because the more speed you take,the 10 kilometers will feel like few minutes only.Bikes like Ducati ,Pulsar and Yamaha ,Karizma are meant for you (assuming you are an Indian resident).Pulsar is the most common bike on Indian roads because its really affordable and gives reasonable mileage.

Welcome to a different category of bikes.Its known as Cruise bikes.Its for those people who think that   distance is too short.If you are that person who wants to keep riding and riding then you should opt for a cruise bike.Its got ingredients that keep you going and not giving you back aches when distances are long.The difference between a sports bike and a cruise bike is the seating position.Cruise bikes are a bit shorter in height whereas its longer from front to rear.So you get a better seating position when you are on a cruise bike.You can either lean forward or relax and stay back and ride.Also when you are on a cruise bike you can  feel the same comfort of driving a 4 wheeler car.Also cruise bikes give you thicker bike tyres and a better balance.Cruise bikes in India would necessarily mean Eliminator,Avenger,Enfield and sometimes Harley Davidson.

The third category of bike is the budget bike for common Indian  users.Its got good mileage and good feel when in traffic jams.Also its easy to afford and maintain.When you need to go to the local grocery shop or go to college/office this bike is meant for you.Splendor,Passion,Pulsar,Activa are common bikes in this category.

Well i own an Avenger bike and comes in the Cruise bike category.Its a brand of Bajaj.


Its got sexy looks and does not let me down.The only problem with Bajaj bikes is its gear shift.But since its got the pioneered DTSi technology it makes up for the bad.Also seating position is good for long rides and will not give you back aches easily.

Mumbai roads have a lot of slopes and riding here from a higher elevation to lower in good speeds requires shift to lower gears quickly.Mileage is reasonable.I am not opting for a different bike but will continue riding it.



Wednesday, February 16, 2011

Anyone moving from Kolkata to Mumbai?????

Recently my Computer Consultancy job required me to move to Mumbai from Kolkata.I moved here in Mumbai without doing much of a study of how this place could be for me.It was because Mumbai always stays in the news if not for anything else,then there is always Bollywood here.Also i had to take prompt decision or this job was at stake.

Well,its Mumbai u know, 'the city of dreams'.People from all places like to come here to give shape to their dreams.I had only one simple dream,to make a beautiful girlfriend.But just like sunshine  interfere with sleep so does the living costs interfere with your privacy and private life.Here you have to share apartments with strangers sometimes if you cannot afford a rental of Rs25,000 per month.So dreams could be dreams.

The first thing i noticed here in Mumbai is the language.Whenever something is told about Mumbai in Kolkata news,its always told in Hindi.I am a bit weak in Hindi but i can cope up with it.But coming to Mumbai the language problem even got more difficult.

In Mumbai people find an immense pride in speaking Marathi.Most of the shops here also have their Board names written  in Marathi.If ever i was lost in Kolkata i would have read the address that's written in the shop name and would get an idea as to where i was.But since i cannot read Hindi/Marathi its very difficult for me.To add to this Bus number are also written in Marathi.And railway stations also have names in Marathi. 


Now comes the documentation problem that i faced.I have valid voter's Id.Ration card,Passport etc.But i went on roaming charges from my mobile service provider since i could not purchase a Maharashtra SIM Card with all documents intact.They did not give me because i was from a different state.

Coming to Maharashtra feels like coming to a new country.I wonder if they will demand for a visa for coming to Maharashtra from another Indian state.


Having the joyful days with Bengali sweets are over for me.Eating foods prepared by Mom are dead.Eating at a restuarant and finding a good Bengali recipe is rare.Eating some food that does not appeal to the taste is abundant.Paying exorbitant amount to have simple dishes like Rice and Dal is just normal.Getting slim is natural.

Again there is problem.You will miss those programmes and celebrations that Kolkata is famous for.And you will have to embrace those in which you have no interests or idea.How about skipping Durga Pujas and getting holidays for some events which you have never heard of.Things are really tough here.

Well to add to this is the depression i feel when i look at a good looking girl and find her in some lucky dude's embrace.I have made few friends here and i just hope i don't feel too frustrated.I miss my City Of Joy,KOLKATA.