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.

Wednesday, 25 July 2012

How to log in to SAP server using user ID & password.


You can use the SAPGuiutil object to open connections. All you need to do is to pass the server name taht you want to log into followed by userid and password. Please find the below code

Sapguiutil.OpenConnection “A:Test Server”
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("User").Set strUserID
 SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("Password").SetSecure strPassword
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiButton("Enter").Click

Launching SAP Using QTP



This is a common problem that most of the beginners face. How to open SAP through QTP?. I thought of posting about this.
There is an utility object from QTP for SAP . It is “SAPGuiUtil”.
SAPGuiUtil supports multiple methods. Below is the list of them with small description.
1.       Autologon -- --   Connects and logs on to an SAP Server
2.       AutoLogonByIP -----   Connects and logs on to SAP server according to its IP address.
3.       CloseConnections-----  Closes any SAP connections that were opened by QTP or by user.
4.       OpenConnection -----   Opens a connection to the specified SAP server.
5.       OpenConnectionByIP ---  Opens a connection to the specified SAP server according to its IP.
Let’s have a look at each one of them.
1. Autologon :  The AutoLogon method opens a new connection even if an open session already exists.
Syntax :
SAPGuiUtil.Autologon <ServerDescription>,<Client>,<User>,<Password>,<Language>
'The following example uses the AutoLogon method to connect to client "800" of the "Calderone" SAP server, using the logon information for the MUSTER user. The Password argument is parameterized to take the encrypted value from the Data Table.
SAPGuiUtil.AutoLogon "Calderone", 800, "MUSTER", DataTable("Password",dtLocalSheet),”EN”

2. AutoLogonByIP : Connects and logs on to an SAP server according to its IP address.
“SAPGuiUtil.AutoLogonByIP <ConnectionString>, <Client>, <User>, <Password>, <Language>, [SystemNumber], [RoutingServers]”
Below is the example
'The following example uses the AutoLogonByIP method to log on to the "Calderone" SAP server
'using its IP address instead of its name.'The Password argument is parameterized to take the encrypted value from the Data Table.
SAPGuiUtil.AutoLogonByIP "/H/212.199.95.5/S/3200", "800", "QA01", DataTable("Password", dtGlobalSheet), "en", "00"

3. CloseConnections  : Closes any SAP connections that were opened by QuickTest or by the user.
                Syntax: SAPGuiUtil.CloseConnections
4. OpenConnection   : Opens a connection to the specified SAP server.
SAPGuiUtil.OpenConnection ServerDescription

Below is an example.

Sapguiutil.OpenConnection “A:Test Server”
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("User").Set strUserID
 SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiEdit("Password").SetSecure strPassword
SAPGuiSession("Session").SAPGuiWindow("SAP").SAPGuiButton("Enter").Click

5. OpenConnectionByIP : Opens a connection to the specified SAP server according to its IP address.
Syntax: object.OpenConnectionByIP ConnectionString, [SystemNumber], [RoutingServers]
Below is the example.
SAPGuiUtil.OpenConnectionByIP "10.168.11.57", 0

Hope this would help my readers. Please note this reference was taken from QTP help.

Tuesday, 10 July 2012

Making Reusable Libraries for SAP:

As SAP works on T-codes, it would be very helpful if while creating the reusable we name them based on the T-codes. This will save a lot of our time. We can directly search for the function using T-codes. Almost all T-codes have a fixed purpose, so once we create a re-usable; we can use it at many places.
                e.g., Function SAP_Create_Order_VA01()
                        Function SAP_Display_Order_VA03()
                       Function SAP_Verify_Job_Status_SM37()

Validating Successful/Unsuccessful Operation:

  
SAP is very user friendly. It throws a message in status bar for every successful/Unsuccessful operation. From validation point of view, this will really help us in making a robust script.
A green message usually indicates a successful operation whereas Red is for any error. So we need to be careful on differentiating them.
                Red  - Error
                Green - Successful
We can use these status messages for validating the operation done on the application.
You can also differentiate whether an operation was successful or not using the object spy. There is a property “messagetype” which holds the below values.
                Messagetype = E   ----  Error
                Messagetype = W  ----  Warning
                Messagetype = S   ----  Successful

Thursday, 5 July 2012

Approach for Automating SAP Application

You can approach in the following method for SAP testing.

1. Transaction Testing: Testing a single transaction (e.g. VA01 Create Sales Order).
2. In-Stream Testing:  Testing of a flow within 1 single process. In-Stream Testing is testing chains of transactions that flow together and which reflect important business process and scenarios
3. Cross-Stream Testing: End-to-end testing of integrated processes through execution of predefined business flows.
4. Acceptance Testing: In-Stream or Cross-Stream Tests by the user community with the objective of formal
acceptance. In some cases, and for practical reasons, the Acceptance Tests are combined with Cross- or even In-Stream Tests.

Wednesday, 4 July 2012

General Error when export/Import Datatable in QTP

QTP's famed datatable is third party control similar to excel, many confuse its extension when compared to MS-Excel and implement various formatting features into the excel file, which would be imported during script run.

Since the datatable is not a excel control, there is a high percent chance of corruption, when that happens, the dreaded "General Run Error" is thrown"

Easiest way to workaround is to clear the data in the parent file, and create new one.

Noted below is the HP-Mercury KB article and detailed steps for the same

*************************************************************************
Issue 1: Exporting runtime datasheet to localpath.(Export error no:"-214746725 9")

During runtime, when we try to export the datasheet to local folder we get a general runtime error. So every time we have to kill the QTP and its process tree to proceed.
Solution: Whenever we get ‘General Run Error’ while exporting, clean up the excel sheets as mentioned below and proceed with execution:
How to clean up all Excel formatting from XLS file using QuickTest Professional (QTP)
Making use of the internal logic/functionality offered within QTP, it is possible to clean up Excel format from a XLS file by using either of following methods. By using any of the following methods a new XLS file will result with lower file size once Excel formatting gets removed:
• Using QTP's user interface
1. Open QuickTest Professional and a new blank test script
2. Access the File menu, then select "Settings"
3. Go to the "Resources" tab
4. Under the "Data Table" field, select "Other location" option and click on the browse button ("...")
5. Once the "Open Data Table" dialog appears, find and select the XLS file desired to clean format and click "Open"
6. Click on "Apply" then "Ok" to close dialogs accepting changes Note: depending on the clean up done by QTP, processing time to later show data on the Data Table pane may vary depending on XLS file size and content
7. On the Data Table pane, right click and under "File" option, select "Export..."
8. Select a location/path and name to save this new version of XLS file

Bad Length Error

This is very common issue with SAP.

There are few fields in SAP which throws 'Bad Length' error on setting values into it during run time(using Script). However you will be able to set the values manually.

The problem is with the length assigned to such field during run session. The field length is usually smaller ,say 4, at runtime. So if you are trying to set a value of length more than 4, you will get this error.

I figured out a way of doing with using the below undocumented method.

SAPGuiSession("Session").SAPGuiWindow("Display ").SAPGuiEdit("<Field>").Object.text="<Your Text>"

The above code worked fine for me.

Hope this will help few of you.

Server Busy Error for SAP

This is a common error thrown by SAP. This usually appears when the system is too slow or there is too much of load on SAP (a group of people say 10 are accessing the application when it is too slow). To overcome this issue, all you got to do is tune up your system performance, kill the unwanted/unnecessary processes which are occupying a huge memory and thus resulting the system to respond slowly. If you still get the pop up, please hit on <Retry> button.