Tuesday

QTP and AutoIt - A deadly combination!



From the last post about creating COM objects , here is another solution that can help you create AutoIt objects within QTP:
  1. Go to http://www.autoitscript.com/autoit3/downloads.shtml and download the zip file.
  2. Extract the file and traverse to the Install -> AutoItX folder.
  3. Copy the AutoItX3.dll file to the following path Windows Drive:\WINDOWS\system32 folder.
  4. Now register the dll by typing "regsvr32 AutoItX3.dll" in the cmd and look for the message "Registration succeeded"
  5. Set oAutoIt = CreateObject("AutoItX3.Control") 
That's how easy it is to start using AutoIt from within QTP.

Thursday

CreateObject Methods


We often create automation objects and assign the object returned by CreateObject to an object variable. Once the object is created we access properties and methods of the new object using the object variable. There are times that we don't know what are the objects that can be accessed using the CreateObject method. 


Though there is no list which can tell us all the objects that can be accessed as it depends on the COM Objects with IDispatch interface registered on your computer. To find available objects, the simplest way is to look at the HKEY_CLASSES_ROOT hive in the registry: Here is a list that might help as a quick reference:

Syntax: CreateObject(Class) here a class would be Servername.typename
Servername would be the application providing the object and typename would be the type or the class of the object created.


Set objEmail = CreateObject( "CDO.Message" )
Set objIE = CreateObject( "InternetExplorer.Application" )
Set objInet = CreateObject( "InetCtls.Inet.1" )
Set objHTTP = CreateObject( "WinHttp.WinHttpRequest.5.1" )
Set objExcel = CreateObject( "Excel.Application" )
Set objOutlook = CreateObject( "Outlook.Application" )
Set objPpt = CreateObject( "PowerPoint.Application" )
Set objWord = CreateObject( "Word.Application" )
Set objCal = CreateObject( "MSCAL.Calendar" )
Set objQPro = CreateObject( "QuattroPro.PerfectScript" )
Set objWP = CreateObject( "WordPerfect.PerfectScript" )
Set objConn = CreateObject( "ADODB.Connection" )
Set objRecSet = CreateObject( "ADODB.Recordset" )
Set objDic = CreateObject( "Scripting.Dictionary" )
Set objFSO = CreateObject( "Scripting.FileSystemObject" )
Set wshNetwork = CreateObject( "WScript.Network" )
Set wshShell = CreateObject( "WScript.Shell" )
Set objRandom = CreateObject( "System.Random" )
Set objArrList = CreateObject( "System.Collections.ArrayList" )
Set objSortList = CreateObject( "System.Collections.SortedList" )
Set xmlDoc = CreateObject( "Microsoft.XmlDom" )
Set xml2Doc = CreateObject( "Msxml2.DOMDocument.5.0" )
Set objiTunes = CreateObject( "iTunes.Application" )
Set objPlayer = CreateObject( "WMPlayer.OCX" )
Set objWMPlayer = CreateObject( "WMPlayer.OCX.7" )
Set objReal = CreateObject( "rmocx.RealPlayer G2 Control.1" )
Set objFSDialog = CreateObject( "SAFRCFileDlg.FileSave" )
Set objFODialog = CreateObject( "SAFRCFileDlg.FileOpen" )
Set objDialog = CreateObject( "UserAccounts.CommonDialog" )
Set SOAPClient = CreateObject( "MSSOAP.SOAPClient" )
Set objWOL = CreateObject( "UltraWOL.ctlUltraWOL" )
Set objSearcher = CreateObject( "Microsoft.Update.Searcher" )
Set objShell = CreateObject( "Shell.Application" )
Set objDeviceReplay=CreateObject("Mercury.DeviceReplay")

Monday

Automation of the .NET ToolbarsManager

If you use QTP for automating .NET apps and the app is built using infragistics, you know that it is not easy to use the .NET spy . After a lot of effort I was able to find solution to perform operations on a infragistics toolbar where the swftoobar object was getting identified as a swfobject:

Here is the code how to work with .net toolbarsmanager:

set cToolbars = SwfWindow("").SwfObject("").Object.ToolbarsManager.Toolbars
Set oMyTool = GetToolFromToolbar(cToolbars,"", "")
omyTool. 'Operation you want

Function GetToolFromToolbar(byref cToolbars, sToolbarKey, sToolKey)
   Dim oToolbar ' Toolbar object
   Dim bToolbarFound
   Dim bToolFound

   bToolbarFound = false
   bToolFound = false

   For x = 0 to cToolbars.Count - 1
      If sToolbarKey = cToolbars.GetItem(x).Key Then
          set oToolbar = cToolbars.GetItem(x)
          bToolbarFound = true
          Exit for
      End If
   Next

   If bToolbarFound = true Then
       For x = 0 to oToolbar.Tools.Count - 1
           If sToolKey = oToolbar.Tools.GetItem(x).Key Then
                 Set GetToolFromToolbar = oToolbar.Tools.GetItem(x)
                 bToolFound = true
                 Exit for
           End If
       Next

       If bToolFound = false Then
       msgbox"Tool Not Found"
    End If
  End If
End Function

And if you are lucky that the toolbar is recognized as swftoolbar then its easier:

set obj = SwfWindow("SwfWindow").SwfToolbar("SwfToolbar").Object.Buttons
msgbox obj.Count
For i = 1 to obj.Count   
    msgbox obj.Item(i).tooltiptext // or any other operation
Next

Wednesday

Download QC OTA API Reference Handbook - Blogs In WATiN

If you are looking for OTA (Open Test Architecture API provided by hp QC then your search will end here.
I will explain you easy way to download API reference details from QC.
a. Login to your QC
b. At Top most corner click on Help Link
c. From the pop-up window select Documentation Library as shown in below figure.



d. As soon as you will select above option a window will appear.
e. Select an option: HP QUALITY Center Open Test Architecture API reference Online
f. Click on online link next to the mentioned text
g. Save the references documentation at your drive.
h. Shown in below figure.


Hope this would be helpful !!

Source: Md. Jawed

Update:

ALM OTA API 12.5:

http://alm-help.saas.hp.com/en/12.50/api_refs/ota/webframe.html

Tuesday

Convert Excel to Text file


I was trying to convert an excel files worksheets to a single text file , there was lot of reusable code on the web for converting text to excel but not viceversa. So for all of you who want to do what  I did, here is the simple and easy code to convert excel to text file based on the rows and columns of the excel file:

'Prompts for accepting user input
strViewPath = Trim (InputBox ("Plz enter the path for the excel file",,"C:\temp\"))
strTest = Trim (InputBox ("Plz enter the text file name",,"sample"))
       
If Right (strViewPath, 1) <> "\" Then
   strViewPath = strViewPath & "\"   
End If       

strTestName = strTest
strTextFilePath = strViewPath
   
'Assign the values for the excel and text file that needs to be converted
TestToConvert = strViewPath + strTest + ".xls"
TextFile =strTextFilePath  + strTestName + ".txt"
   
'Create the excel object
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = False

'Open the excel file for conversion
oExcel.DisplayAlerts = False
oExcel.Workbooks.Open TestToConvert, True
'Call the text streamer function that will convert the file
TextStreamer TextFile, oExcel
 
'Exit the Excel file
oExcel.Quit

Private Sub TextStreamer(TextFileName, objExcel)

'Declare constants for reading,writing and appending to a text file
Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
   
Dim fs, f, ts, x, y, LastRow, LastColumn, c, objSheet, shts()
'Create the file system object for text file editing
Set fs = CreateObject("Scripting.FileSystemObject")
fs.CreateTextFile TextFileName
       
Set f = fs.GetFile(TextFileName)
Set ts = f.OpenAsTextStream(ForWriting, TristateUseDefault)
   
'Get the number of worksheets in the source excel file
intNoOfSheets = objExcel.Worksheets.count
z = intNoOfSheets
   
'Traverse through every sheet that needs to be converted
For i = 1 to intNoOfSheets
       
 'Activate the first worksheet
    objExcel.Worksheets(z).Activate
    objExcel.Worksheets(z).Select
    Set objSheet = objExcel.ActiveWorkbook.Worksheets(z)
    
    strSheetName = objsheet.name
    objSheet.Cells(1).Select

    LastRow = objSheet.UsedRange.Rows.Count + 2
    LastColumn = objSheet.UsedRange.Columns.Count   
                   
    objSheet.Cells(1).Select
                   
    ts.write "["&strSheetName&"]"
    ts.write Chr(13) & Chr(10)
           
    'Loop through the rows and columns in the excel worksheet and write the data to the text file       
    For x = 0 To LastRow
        For y = 0 To LastColumn -1
            If objExcel.ActiveCell.Offset(x, y).Value <> "" then
                ts.write (objExcel.ActiveCell.Offset(x, y).Value)
                'ts.write Chr(9)   
            End If
        Next
        ts.write Chr(13) & Chr(10)
    Next               
  z= z-1

Next
       
'Close the excel file test streamer
ts.Close
msgbox "Conversion Complete!"
End Sub

Friday

Presentation downloads from the Software Testing Conference (SofTec 2011)

 
Here is a list of presentations that were used at the Software Testing Conference (SofTec 2011) held in Chennai last week, also mentioned in my earlier post on Testing News

  • “Present problems and future solutions” - Link
  • “Economical, Robust Web Automation using Sahi - Link
  • “Notes from a problem solving tester consultant” - Link
  • “Smarter ways of doing Selenium Automation”. - Link
  • “The Emerging Trend of Cloud Computing and Software Testing” - Link
  • “I am the Bug Hunter" - Link
  • “Testing at Startups" - Link
Source: Slideshare

Thursday

Testing News - Feb 2nd 2011


  • Wipro launches Testing-as-a-Service portal -TaaS is a model of software testing, where a provider undertakes software testing for customers as a service on demand.Through the portal, potential customers would be able to browse, request for quotes and purchase services online Source: News 
  • Maveric Systems, an independent software testing specialist, is expanding its presence in UK and Europe of testing services for Metro Bank Source: News
  • India's leading event for Software Testing/QA on Saturday, this time in Chennai - Software Testing Conference (SofTec 2011), a leading event for the Software Test and QA Community this time around in Chennai on Jan 29th, 2011 Source: News
  • AdaCore Releases New GNATemulator Tool for Efficient Embedded Software Testing - GNATemulator, an efficient and flexible emulator solution for testing embedded software applications. Based on the QEMU technology, a generic and open source machine emulator and virtualizer, the new GNATemulator tool allows software developers to compile code directly for their target architecture and run it on their host platform, through an approach that translates from the target object code to native instructions on the host. Source: News

Wednesday

How to test Silverlight 4 Applications using TestComplete 8 - Darshika


TestComplete 8 provides greater support to verify Microsoft Silverlight 4 application components by using any functional test methodology such as black-box and white-box test mechanisms. In this version of test complete engine can access Silverlight internal objects, methods, properties and fields in order to automate applications.


In order to track Silverlight components by testcomplete engine, first you require to check following “Extend Silverlight Object Tree” checkbox option by navigating to Tools -> Default Project Properties -> Projects -> Open Application -> Silverlight. Subsequent that, the test complete engine will have access to Silverlight objects and their methods, properties and fields and you can employ those elements in your automated tests. (Pls. refer the following screen cap)





















Further, you can notice all Silverlight objects and their available methods and properties in the hierarchy of object tree model subsequent to explore browsers such as IE, Firefox.











Now TestComplete introduce a new SlObject method in order to automate applications with Silverlight components. Using this method, users allow obtaining a Silverlight component by its name, which was stated in the application’s source code.

Moreover, TestComplete also offers a SlApplication scripting object that is a wrapper to a Silverlight application’s main class that sum up application defined functionality and inherit methods and properties of the System.Windows.Application class.

As well as the members of this System.Windows.Application class contains the SlClasses property. This property assist you for scripting interface to namespaces and assemblies classes included in your Silverlight application package in the.xap file.








Now Testcomplete provide great opportunity to access static non visual objects and their public members by using SlClasses property. In addition to functional testing, this special feature allows you to perform unit/web component performance testing by using application’s internal classes and their associates.

Hope that the above mentioned features will facilitate you easily creates more powerful automated tests for your Silverlight applications.

To download TestComplete 8 Trial

Source: Success with TestComplete Test Automation