Welcome To Automation Testing

Before starting with tips of automation of SAP using QTP Let me give a small introduction of SAP and QTP.

SAP stands for System Applications and Products. It is the name of both the online financial and

Administrative software and the company that developed it. SAP is made up of individual modules that perform various organizational system tasks.



Quick Test Professional (QTP) is an automated functional Graphical User Interface (GUI) testing tool that allows the automation of user actions on a web or client based computer application.

It is primarily used for functional regression test automation. QTP uses a scripting language built on top of VBScript to specify the test procedure, and to manipulate the objects and controls of the application under test. It supports many applications through the support of add-ins.



We will be using SAP add-in with QTP to work on the SAP automation.

Monday, 6 August 2012

Close running Process from task manager


Below function will close running process from task manager.


Function CloseProcess(strProgramName)
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run "TASKKILL /F /IM " & strProgramName
Set objShell = Nothing
End Function


Taskkill is a commancd which ends one or more tasks or processes. Processes can be killed by process ID or image name.

"TASKKILL /F /IM " & strProgramName

/F :: Forcefully closing the application
/IM :: Image Name. Nothing but the visible exe file in task manager. Since we dont know the process id, i hv used Image name to kill the process. strProgramName contains the .exe file name which has to be killed.



To close browser say IE, just call the function as

Call CloseProcess("iexplorer.exe")'Closes IE
Call CloseProcess("Excel.exe") ''Closes excel.


Friday, 3 August 2012

Round function returns wrong result/ Round to Larger

I remember working with Round function. There was a scenario where it was returning wrong value.

'Let us see the example
dblValue=30.745
dblRoundedValue=Round (dblValue,2) 'Round for two digits after decimal

***************
Output was 30.74 instead of 30.75.

***************
Reason behind this is

The Round function performs round to even, which is different from round to larger. ... If expression is exactly halfway between two possible rounded values, the function returns the possible rounded value whose rightmost digit is an even number.
This is not what i was looking for. For me the values has to be 30.75. I developed a small piece of code which works absolutely fine for rounding values to larger.

Function Generic_RoundToLarger(dblNumber, intNumDigitsAfterDecimal)
   dblRoundedValue= CDbl(FormatNumber(dblNumber, intNumDigitsAfterDecimal))
   Generic_RoundToLarger=dblRoundedValue
End Function


Now when i call this function i get the expected value. 30.745 is returned as 30.75.

Hope this helps my reader.


Wednesday, 1 August 2012

Navigating to one t-code from another using QTP

Many of us may be aware of this topic which i am posting. But for me it took almos 5 months to discover this trick.:(

Let me explain what i use to do before discovering this cool trick.
Suppose you are on a t-code page , say VA01. After completing your operation, you need to navigate back to home page. I use to click on back button for this, which inturn was increasing OR size. This was not reliable too.
'Navigate back
SAPGuiSession("Session").SAPGuiWindow("").SAPGuiButton("Back").click

'Or to jump to another T-code from here, i was using /n in the t-code box

SAPGuiSession("Session").SAPGuiWindow("").SAPGuiOKCode("OK").Set "/nVA03"

For the above code to run, all the objects must be present in OR. Miss of any will result in error.

To resolve this we can use the 'Reset' option available in QTP.

SAPGuiSession("Session").Reset  // This code will take you to home page, doesnt matter where you are.
SAPGuiSession("Session").Reset "VA03"  //This code will take you to VA03 t-page from anywhere.

This will save lot of time and will optimize memory as well.

Wasn't it cool? Go ahead, use this option in your code.