Thursday, February 28, 2008

How is CreateObject different from GetObject?

One of my junior colleague had asked the question "What is the difference between CreateObject and GetObject and in what situation GetObject is to be used?". This post is the answer that I have given him.

  1. CreateObject creates an instance of a class
  2. GetObject gets the reference of an running object to another object
  3. Always use CreateObject except for Windows Management Instrumentation (WMI) and Active Directory Service Interfaces (ADSI)

The below script demonstrates the use of these two VBScript functions.

Set objExcel = CreateObject("Excel.Application") 
objExcel.Visible = True
Set objWorkbook = objExcel.Workbooks.Add

Set objExcel2 = GetObject(, "Excel.Application")
Set objWorkbook = objExcel2.Workbooks(1)
Set objWorksheet = objWorkbook.Worksheets(1)
objExcel2.Cells(1, 1).Value = "In god I TRUST everything else I TEST."



 



-- Lakshminarasimha Manjunatha Mohan


In God I TRUST everything else I TEST.

Windows Hotfixes and Patches Enumerator

Below is a simple VBScript developed using Windows WMI that can be executed from Windows Script Host to enumerate the installed hotfixes, patches and security updates on any given machine.

You might be wondering what for this script is useful. While product testing that supports different environments it happens so that suddenly one fine day you might notice some mis-behavior or unusual defects in the application. Actually these mis-behaviors or defects are not always related to the application. However, it may be a compatibility issue with one of the patches or security updates made by the windows automatic updates.

As a solution to this problem I am this script to find out all the patches, hot fixes and security updates on a server where the product is working fine and compare the that with another server where the mis-behavior or defects are seen and thus classify a defect from compatibility issue. This is really a very handy script for compatibility testing. Let me know your comments on this. I intend to extend this script for comparing two different lists of hotfixes and patches so as to make it easier to find the differences.

For executing this script it is necessary have an EXCEL file named test.xls at C:\

'========================================================
'Description: This script enumerates the Windows hotfixes
' and other security updates
'Author: Lakshminarasimha M.
'=========================================================
strComputer = "."

Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colQuickFixes = objWMIService.ExecQuery ("Select * from Win32_QuickFixEngineering")

sDataTable = "C:\test.xls"
sDataSheet = "Sheet1"

iReqRow = 2
Dim oXLApp 'As Excel.Application
Dim oWorkBook 'As Excel.Workbook
Dim oWorkSheet 'As Excel.Worksheet
Dim iRowsCount 'As Integer
Dim iColsCount 'As Integer
Dim sColHeader 'As String
Dim sReqColumn 'As String

Set oXLApp = CreateObject("Excel.Application")
'oXLApp.Visible = True
Set oWorkBook = oXLApp.Workbooks.Open(sDataTable)
Set oWorkSheet = oWorkBook.Sheets(sDataSheet)
oWorkSheet.Activate
iRowsCount = oWorkSheet.UsedRange.Rows.Count
iColsCount = oWorkSheet.UsedRange.Columns.Count
iReqRow=2
' Set Column Headers
oWorkSheet.Range("A1").Value = "Caption"
oWorkSheet.Range("B1").Value = "CSName"
oWorkSheet.Range("C1").Value = "Description"
oWorkSheet.Range("D1").Value = "FixComments"
oWorkSheet.Range("E1").Value = "HotFixID"
oWorkSheet.Range("F1").Value = "InstallDate"
oWorkSheet.Range("G1").Value = "InstalledBy"
oWorkSheet.Range("H1").Value = "InstalledOn"
oWorkSheet.Range("I1").Value = "Name"
oWorkSheet.Range("J1").Value = "ServicePackInEffect"
oWorkSheet.Range("K1").Value = "Status"

For Each objQuickFix in colQuickFixes
oWorkSheet.Range("A" & iReqRow).Value = objQuickFix.Caption
oWorkSheet.Range("B" & iReqRow).Value = objQuickFix.CSName
oWorkSheet.Range("C" & iReqRow).Value = objQuickFix.Description
oWorkSheet.Range("D" & iReqRow).Value = objQuickFix.FixComments
oWorkSheet.Range("E" & iReqRow).Value = objQuickFix.HotFixID
oWorkSheet.Range("F" & iReqRow).Value = objQuickFix.InstallDate
oWorkSheet.Range("G" & iReqRow).Value = objQuickFix.InstalledBy
oWorkSheet.Range("H" & iReqRow).Value = objQuickFix.InstalledOn
oWorkSheet.Range("I" & iReqRow).Value = objQuickFix.Name
oWorkSheet.Range("J" & iReqRow).Value = objQuickFix.ServicePackInEffect
oWorkSheet.Range("K" & iReqRow).Value = objQuickFix.Status
iReqRow = iReqRow + 1
Next
oWorkBook.Save
oWorkBook.Close
oXLApp.Quit
Set oWorkSheet = Nothing
Set oWorkBook = Nothing
Set oXLApp = Nothing
MsgBox("---Hotfixes Enumerated Sucessfully.---")




-- Lakshminarasimha Manjunatha Mohan



In God I TRUST everything else I TEST.

Sunday, January 13, 2008

How to automatically delete unused folders?

Below is a Visual Basic Script that can delete all the sub folders older than 30days from the current date. The folder from which the sub folders need to be deleted can set by  changing the value for strMainFolder variable. This script can also be used to manage files and folder in remote computers just by setting the required computer name/IP to strComputer variable.

The script can be used very effectively by scheduling a job from Windows Task Scheduler.

strComputer = "."
strMainFolder = "C:\"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colSubfolders = objWMIService.ExecQuery("Associators of" _
& {Win32_Directory.Name='" & strMainFolder _
& "'} Where AssocClass = Win32_Subdirectory ResultRole = PartComponent")

For Each objFolder in colSubfolders
   dtmFolderCreationDate= CDate(Mid(objFolder.CreationDate,5,2) _
    & "/" & Mid(objFolder.CreationDate, 7, 2) & "/" _
    & Left(objFolder.CreationDate, 4) & " " _
    & Mid (objFolder.CreationDate, 9, 2) & ":" _
    & Mid(objFolder.CreationDate, 11, 2) & ":" _
    & Mid(objFolder.CreationDate,13, 2))
    If (DateDiff("d",dtmFolderCreationDate,Now)>30) Then
    'Wscript.Echo objFolder.Name
    'Wscript.Echo objFolder.CreationDate 
    errResults = objFolder.Delete
    End If
Next

-- Lakshminarasimha Mohan

In God I TRUST everything else I TEST.

Friday, January 11, 2008

IE popup window disappears while QTP Script Execution!!

A strange problem of Mercury QuickTest Pro 9.2 with Internet Explorer 7.0 is discussed with solution.

Problem: While executing scripts in IE 7.0 if another browser is opened by the script as a result of an operation or test step, the pop up window automatically disappears. The issues looks strange but the window disappears without any clue.  

Due to this issue there are many other problems including problem in executing Navigate method of IE object etc., I have not tested it on IE6. However, the problem might also exist in IE6 as well.

Example scenario: A QTP 9.2 automation script for the following scenario in the admin mode of EPiServerCMS web site fails to execute on IE 7.0.

Steps for Simulation:

  1. Login to EPiServerCMS Admin Mode (Ensure that the Role and membership providers are set to Multiplexing providers with SQL Server providers as default provider)
  2. Click on Administer Groups
  3. Create a new Group
  4. Click on the Delete button corresponding to the newly created Group the pop up window disappears only when a QTP script for this scenario is executed. However, the scenario works perfectly fine on manual execution of the same steps.

 

Solution: The solution for this problem is just enable the "BHOManager Class" Add-on in the IE. (This can be done by going to IE-> Tools -> Manage Add-ons -> Enable/Disable Add-ons...)

What is "BHOManager Class" add-on or BHOManager.DLL?

A Browser Helper Object, or BHO, is just a small program that runs automatically every time the Internet explorer browser is started.

BHOManager.DLL is installed on the system when QTP is installed. This is a helper class that assists QTP for execution of QTP scripts on the browser. BHOManager.DLL is located in the folder C:\Windows\System32. The unique ID or CLSID of this BHO is {474264BC-9571-47C1-85B9-780F756DC9CE}.

Additional Information about BHOs:

BHOs are not stopped by personal firewalls, because they are identified by the firewall as browser itself. They are also known to conflict with other running programs, causing a variety of page faults, run time errors, and the like, and generally impede browsing performance.

BHODemon is small tool that can be used to view, enable or disable all the BHO's on a computer. It is a free tool that can be downloaded from BHODemon.

Other known BHOs:

The other known BHOs include the following:

  1. Microsoft.VisualStudio.QualityTools.RecorderBarBHO.dll - This BHO is used by Visual Studio Team Suite for web tests

For more information BHOManager.dll and other BHOs refer to

http://www.file.net/process/bhomanager.dll.html

http://www.sysinfo.org/bhoinfo.html

Monday, December 10, 2007

Performance Testing: Resource Monitoring

What is Load Testing?

The behavior of the application and the utilization of the resources by the application under test is monitored under different load patterns and it is validated against the expected measurements to identify any potential performance errors or bottlenecks.

What is necessity for Monitoring Resources?

Any normal ASP.NET web application will be developed using three tier architecture of Presentation, Business and Data Layers. When a request is made by the client to the server the request is processed by the web server which in turn would be forwarded to the application server and then to the database server. During this processing the System, web server application server and the database server resources are utilized. It is necessary to monitor these resources utilization under load before the application is moved to production in order to identify the performance errors and bottlenecks before it breaks the application and impacts the business of the application.

What Resources need to be monitored?

It is necessary to monitor every logical or physical layer of the web application. In a simple scenario where the application is hosted on a web server and application interacts with the database the sources to be considered for monitoring are System resources, the web server resources and the database resources.It is necessary to identify the specific resources and counters (with their threshold levels) to be monitored at each layer. This identification needs expertise and experience in performance testing. Below is the list of counters that can be used for first level of performance analysis. This table applies for the general ASP.NET applications. However, it needs to be tailored for the specific requirements.

Note: The counters column in the below table to be read as shown in the example: % Processor Time (Processor _Total). Here, the Processor is the Object, % Processor Time is the Counter and _Total is the instance.

How to Monitor the Resources? What tools to use?

On a Windows based machine it is possible to monitor the resources using a utility called perfmon. The same way as perfmon Linux/Unix based machines facilitate the resource monitoring by means of utility known as rstdmon.
Almost every Load Testing tools has integration with Windows Perfmon or has some other has means to provide the facility to monitor the resources. E.g. LoadRunner, Visual Studio 2005 Team Edition for Testers, WebLoad, etc., 

Conclusion

The table of counters provided here provides a possible list of counters that can be monitored for while Load Testing an ASP.NET application. However, it needs to be tailored for specific requirements. For example, while testing a application that uses ADAM process one would be interested to know the processor and memory utilization by the ADAM worker process (dsamain) in specific. It is advised to use the minimum number of high level counters for the first round analysis. Based on the first level analysis one can added more detailed and specific counters for the areas that warrant performance and remove few counters related to areas where the performance seems be good.

-- Lakshminarasimha Mohan

"In god I TRUST, everything else I TEST."

Sunday, October 21, 2007

Object Identification Mechanism

QTP identifies the objects by mandatory properties set as default. If the mandatory property values are not sufficient to uniquely identify an object in the Application Under Test (AUT), QTP adds some assistive properties and/or an ordinal identifier in order to create a unique description.

The default Mandatory, Assistive Properties and Ordinal Identifiers can be changed for a specific Class of objects in QTP at Tools -> Object Identification.

The Smart Identification can also be enabled to ensure more comprehensive object identification. The User defined Class of Objects can be mapped to the standard class of Objects so that QTP identifies the user defined objects as standard objects.

What is Smart Identification?

QTP makes use of the special feature Smart Identification when it  fails to identify objects using the defined properties finds an ambiguity in identifying objects. 

The Smart Identification mechanism is more complex and more flexible. If configured logically, a Smart Identification definition can probably help QTP identify an object, if it is present, even when the learned description fails.

The Smart Identification mechanism uses two types of properties, Base Filter Properties and Optional Filter Properties.

Base Filter Properties: The most fundamental properties of a particular test object class; those whose values will not be changed. E.g. html tag = <A> for a object of Link Class

Optional Filter Properties: Other properties that can help identify objects of a particular class.

Smart Identification Process

The QTP follows the below process to identify the objects using Smart Identification Mechanism:

  1. QTP creates a new object candidate list within the Objects Parent Object containing all the objects that match all of the properties defined in the Base Filter Properties list.
  2. New Object Candidate List (OCL) is created by filtering out the objects in the OCL that does not match the first property listed in the Optional Filter Properties list.
  3. The OCL is evaluated in the following manner:
    1. If the new object candidate list still has more than one object, QTP uses the new (smaller) OCL to repeat elimination process for the next optional filter property in the list.
    2. If the new object candidate list is empty, QTP ignores this optional filter property, returns to the previous object candidate list, and repeats the elimination process for the next optional filter property in the list.
    3. If the object candidate list contains exactly one object, then QTP concludes that it has identified the object and performs the statement containing the object.
    4. QTP continues the process described above until it either identifies one object, or runs out of optional filter properties to use.

Summary

  • QTP Identifies the Object using the learnt description.
  • If unable to identify the objects using learnt description Smart Identification is invoked.
  • If after completing the Smart Identification elimination process, QTP still cannot identify the object, then QTP uses the learned description plus the ordinal identifier to identify the object.
  • If the combined learned description and ordinal identifier are not sufficient to identify the object, then QTP stops the run session and displays a Run Error message.