Tuesday, November 10, 2009

Conencting to open internet explorer instance

We come across this situation many times wherein we need to connect to some application already invoked by some other part of code. Simple goggling gives examples about invoking an application but there are very few examples which explains connecting to already open application. Here is small snippet which enables user to connects to existing IE.
Dim objInstances, objIE, strURL
strURL = ""
Set objInstances = CreateObject("Shell.Application").windows
If objInstances.Count > 0 Then ' To make sure we have IE instance open.
For Each objIE In objInstances
Dim sName
sName = UCASE(objIE.FullName)
If Right(sName, 12) = "IEXPLORE.EXE" Then ' Searching for internet explorer
objIE.Navigate strURL ' Navigate to intended URL
Exit For
End if
Next
Else
wscript.echo "No explorer windows are open."
End if


Sometimes there are simple solutions to complex problems, isn't it ?

Friday, August 28, 2009

Testing WebServices using QTP

It is tricky but extremely simple to test web services using QuickTest. I was given this task of creating a framework for testing a particular set of Use Cases which had to be done using services as no UI was available. I started with using the Web Services wizard to pass input parameters and get the output data sets or values. Later I found that the same could not be extended as the Object Repository holds the Webservice name with wsdl path and port name. This forced me think differently to make every parameter configurable.Let's first know few points:

1) SOAP : SOAP, which stands for Simple Object Access Protocol, is defined by the SOAP standard available at http://www.w3.org/TR/SOAP. The SOAP protocol defines the format of standard XML messages that are used to communicate among systems. Because the message format is standardized and based on the XML standard, SOAP can be used to communicate among multiple computer architectures, languages, and operating systems. SOAP enables a new class of applications called Web services, which expose services in a standard way so that application developers can create new applications by putting together services from many different sources on the Web.There are four main areas covered by the SOAP specification: a required SOAP Envelope format that defines what the envelope that surrounds the XML content of a SOAP message must look like; an optional set of encoding rules that defines how language types are mapped to XML in a SOAP message (since this is defined in section 5 of the specification, it is referred to as "section 5 encoding"); an optional RPC format that defines how function calls are expressed in SOAP messages; and an HTTP binding that defines how SOAP messages may be exchanged through HTTP.

2) WSDL: WSDL stands for Web Service Description Language. In order to successfully call a Web service you will need to know how to get to the service, what operations the service supports, what parameters the service expects, and what the service returns. WSDL provides all of this information in an XML document that can be read or machine-processed.
The next necessary steps to call this SOAP method using the high-level SOAP API are:create a SOAPClient objectinitialize the SOAPClient object with the WSDL fileand call the method
Below is a snippet for same:
Set oSOAPClient = CreateObject("MSSOAP.SoapClient")

oSOAPClient.mssoapinit wsdl_path, service_name, port_name

oSOAPClient.Methodname param1, param2, return_param1

Above snippet might give error while running on windows 2003 of ActiveX component. To correct it download the SOAP Tool kit from msdn version 3.0 and install it and following change to first line of script:

Set oSOAPClient = CreateObject("MSSOAP.SoapClient30")


Reply back to me if you need any clarifications or updates.

Tuesday, August 18, 2009

Recursive search in vbscript.

It was this particular thing in vbscript which was lurring me from many days. I had written a small script for downloading Test Cases from Quality Center to Excel. QC 9.5 provides this as in built functionality but we had some old systems where in we had to pull all existing cases in Excel. The code was ready and I found that it needed exact path from QC logical folder structure to find all cases within it. There was a dire need to search within the given path to find all sub folders and test cases within them.

There was another requirement to replace one particular string from many script files stored on a server where quality center was installed. I had to replace all scripts which get saved on qc file system which had a particular string present in it. All test cases of type QUICK_TEST get saved with Script.mts file holding the actual textual part of script.

Here is a snippet to find particular file type (e.g.: Here i have searched for .mts file type as it was our requirement) within given folder and it searches in all sub folders present in it:

strDir = "D:\rohan\test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDir = objFSO.GetFolder(strDir)RecursiveFunc (objDir)

Sub RecursiveFunc(Dir_Passed)
For Each Item_File In Dir_Passed.Files
If LCase(Right(CStr(Item_File.Name), 3)) = "mts" Then
wscript.Echo Dir_Passed & "\" & Item_File.Name
End If
Next

For Each Item_Fldr In Dir_Passed.SubFolders
'wscript.Echo Item_Fldr.Name & " recursed"
RecursiveFunc (Item_Fldr)
Next
End Sub

Wednesday, May 20, 2009

QTP issue 'Sheet already in use'.

I came up with this unique issue wherein i was receiving this 'Sheet already in use error popup when i was trying to execute my QTP scripts. The QTP scripts were upgraded from 9.2 to 10.0 wherein we had lost the association between External Reusable Actions and the main script which used to call those reusable actions. The Default.xls did not loose Data Tables for the called Reusable actions. We could not help but delete those additional sheets from Default.xls and only then the scripts started running fine. Now even today i still doubt about the upgrade issues we have faced during upgrading QTP from 9.2 to 10.0. I can list atleast 10 issues here and still many to foloow i guess.
But sometimes i feel it was good that we had issues... I get paid for resolving it :)

Tuesday, May 12, 2009

Disabling the security popup for specified hostnames or IPs.

It happens many times that we get a security pop up and we haven't handled it some of our automated QTP scripts which invoke exe files on those remote locations.
Following steps would help eliminating the issue once for all:
1) Click Start, Run and type INETCPL.CPL
2) Select the Security tab, Trusted sites
3) Click Sites button Add the IP address or hostname of the remote computer to the list(You can also add the network shares to the Local Intranet zone.)
4) Uncheck Require server verification (https:) for all sites in this zone and click Close
5) Click OK, OK and close the dialog

The methodology works only for Windows.

Monday, April 27, 2009

Create or Delete Service

I know this is old now but still thought of posting it once here as it is required by most of the developers across the globe and newbies find it difficult sometimes to find it.
To create a Service follow the following steps:
1) Go to Start -> Run and type cmd in the Open: line. Click OK.
2) Type: sc create
3) Reboot the system

To Delete a Service follow the following steps:
1) Go to Start -> Run and type cmd in the Open: line. Click OK.
2) Type: sc delete
3) Reboot the system

If you are interested in deleting the service from registry you need to follow the following steps:
1) Go to Start -> Run and type regedit in the Open: line. Click OK.
2) Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services
3) Scroll down the left pane, locate the service name, right click it and select Delete.
4) Reboot the system
The procedure works for Windows Xp as well as NT.

Tuesday, March 31, 2009

QTP scripts bulk update.

We were caught in an extremely awkward situation few days back (I wonder why we always run into such situations :) ) wherein we upgraded our HP Quality Center and HP QTP to 10.0 which is their recent release. QTP 10.0 scripts were also in QC.
Before the upgrade took place we were running on QTP 9.2. We had a common vbscript for each Test Case in QC which used to call reusable actions saved at different location in QC. We also had associated those reusable actions. But after upgrade all our efforts were drained and we were left in a jeopardy where we could not even move back to 9.2 as much work had been done on QC front after the upgrade. The upgrade was done on live system without even checking on test systems whether it works or not. Management was to be blamed for it. Anyways, after the upgrade this association was lost and i was roped in to clear the debris and bring back the whole system on track.
After doing some research i came up with this unique update technique to get all the scripts updated automatically. I looked in all files which get saved when we save a QTP script and found that the 'Script.mts' file holds the actual text displayed when we open any script. I thought of updating the RunAction statement in this text with LoadAndRunAction statement. The parameters required for this new statement were different than from previous one which led to introduction of additional line of code which would call a new function and a additional vbs function. Our probelm was resolved and we were back to routine execution but the issue gave me nightmares.
Step 1:
Step 2:
Step 3:
Step 4:
Step 5:

Thursday, March 26, 2009

Comparing two different Databases

This is a tiny tool which would come handy in case you need to compare two different tables/ databases on same or different servers. I came across this unique requirement when we had to come up with a small code which would return TRUE or FALSE based on equal or unequal tables. I googled a bit and cam eup with the following code.

The code takes input from xml file. stored at disk. The code also compares SQL table with Oracle Table which is normally not provided by most DB compare tools available for free.

Mail me in case you have any issues using the tool.
Following is the snippet of xml file:








Tuesday, February 17, 2009

Populating Data on SAP server.

I was assigned this unique task of populating specific (P2P, Authorizations) data on SAP server. Specific data was required for testing purpose by both development and QA department. P2P transaction included the following parts:
Purchace Recquisition-> Purchase Order -> Goods Receipts -> Invoice Receipts -> Payments
I tried various options like writing simple vb script to connect to SAP Server like the following:

I also tried using QTP to capture SAP objects and rerun the script as many times as we needed. But QTP made the application extremely slow and required too much tweaking. We were able to generate 1000 records of P2P transactions in about 13 hours using QTP which was not enough for Performance testing. They needed millions of records per day. We were in a jinx when i found a document which mentioned about using in-build recording function by SAP and voila... It was so easy to record a transaction and the output was a vbs file which could be parameterized easily by getting values from Excel. The vbs file is very easy to understand and maintainable as well. Following are the steps to have recorded script:
1) Enable scripting on SAP Server.

2) Go To Script Recording and Playback from Customizing local layout in SAP GUI.

3) Start recording in SAP GUI after clicking the Record button on newly popped up Record window.

4) Once you are done with your recording open the vbs file saved.

5) Parameterize this file and you are ready to populate data on SAP server.


Mail me in case you have any issues regarding populating data on SAP Server using this method.

Monday, February 9, 2009

VSTS Test Edition for automated testing.

VSTS could be used for the following:
1) Unit testing
2) Web testing
3) Load Testing

Web test in VSTS could be used for automated functional testing. It records HTTP transactions and not API calls. The language used is C++ or VB.NET
Pros of using VSTS:
1) Parameterization of test data possible
2) Add validation points( called Validation Rules)
3) Script is reliable where frequent UI changes take place

Cons of using VSTS:
1) No UI, Database validation possible.
2) No Flow control or other programming constructs provided by other auotmation languages.
3) Does require higher skill set for functional testers.

Thus Microsoft VSTS is competing with HP QTP in terms of automated testing. But I feel VSTS has a long way to go still, looking at advantages QTP provides.

Thursday, January 29, 2009

To SET date and time format settings programatically.

I came up with this unique requirement of having to SET date and time format settings programatically. It is a bit tricky to do this using vbscript.
I googled a bit to find a snippet which really works :)
It is possible to play with it here and there to get the required format.

'=======================
Private Const LOCALE_SDATE = &H1F
Private Const LOCALE_STIMEFORMAT = &H1003
Private Const WM_SETTINGCHANGE = &H1A
Private Const HWND_BROADCAST = &HFFFF&

Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String) As Boolean

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long

Private Declare Function GetLocaleInfo Lib "kernel32" Alias "GetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Public Function SetDateTime() As Boolean
Dim dwLCID As LongdwLCID = GetSystemDefaultLCID()
If SetLocaleInfo(dwLCID, LOCALE_SDATE, "dd/MM/yyyy") = False Then
SetDateTime = False
Exit Function
End If
If SetLocaleInfo(dwLCID, LOCALE_STIMEFORMAT, "HH:mm:ss") = False Then
SetDateTime = False
Exit Function
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
SetDateTime = True
End Function
'=======================
Change the LOCALE_SDATE variable value to get the desired results for Date format and LOCALE_STIMEFORMAT variable value for Time format.

Friday, January 2, 2009

Advanced scripting using OTA.

As we saw in OTA basics we were able to connect to any QC project in a matter of time. now once we have established connection with QC we can perform a variety of tasks. Before going for a long project let us divide it in smaller projects.
Think of normal everyday tasks in any software development organization using Quality Center for quality processes management. The day-to-day activities include daily builds, running basic tests, publishing reports.
We will take a large project called "AutoGenerator" which would perform following actions:
1) Verify build availability (assuming a build mail is received on build completion)
2) Kick start basic build verification tests (assuming the build is successful)
3) Execute the required tests (based on TestSets mentioned in QC)
4) Generate report (based on execution results)
5) Mail report

This is a long process which takes most of the time of any build engineer in any software organization and there are many dependencies due to which work may get delayed.
In simple words the project would work in minimizing these daily tasks by automating them.
The project would do wonders for both Dev and QA organizations as the test results would be available as the first thing in the morning and they can take approprite steps to cater it if anything goes wrong.

There are a lot of assumptions made while designing this project which are as follows:
1) The organization has a build process in place.
2) The build process also involves receival of mail using Outlook to intended recipents.
3) The organization uses QC for QA processes.
4) The organization uses QTP for automating their tests and scripts are saved in QC for execution.
5) Basic tests for verifying build are automated.
6) Reports are generated in Excel and published by mail.

Now let us divide this project in parts and have a look at one of them
Part 1 : Execute the required tests
Following is the code for same:
Set QCConnection = CreateObject("TDApiOle80.TDConnection")
QCConnection.InitConnectionEx
QCConnection.login ,
QCConnection.Connect ,
Set TestSetFact = QCConnection.TestSetFactory
Set tsTreeMgr = QCConnection.TestSetTreeManager
Set tSetFolder = tsTreeMgr.NodeByPath()
Set TestSetsList = tSetFolder.FindTestSets()
Set theTestSet = TestSetsList.Item(1)
Set gettestlist = theTestSet.TSTestFactory
Set TestSetlist = gettestlist.NewList("")
For Each gettest In TestSetlist
gettest.HostName =
gettest.Post
Next
Set TestSetlist = Nothing
Set Scheduler = theTestSet.StartExecution("")
Scheduler.Run
Set execStatus = Scheduler.ExecutionStatus
Dim RunFinished, ExecEventInfoObj, TestExecStatusObj
RunFinished = execStatus.Finished
While RunFinished = False
Sleep 300000
execStatus.RefreshExecStatusInfo "all", True
RunFinished = execStatus.Finished
Wend
Set execStatus = Nothing
Set Scheduler = Nothing
Set TestSetlist = Nothing
QCConnection.Logout
QCConnection.Disconnect
Set QCConnection = Nothing

The code above assumes that you are running the suit on some specific Host machine which will need to be replaced at the mentioned location.
We will have a look at other part in the next section.