Enumerating the Setting Variables - QTP

We have already seen in the "Utility Objects" chapters that there are several documented Setting variables:

  • Setting("AutomaticLinkRun")
  • SettingC'DefaultLoadTime")
  • SettingC'DefaultTimeout")
  • Setting.WebPackage("ReplayType")
  • Setting("SnapshotReportMode")
  • Setting("WebTimeout")

Now we can enumerate the settings at run-time or we can use the registry to detennine what settings are available. We will notice how easier the job becomes after knowing these settings and things that were not looking possible earlier are possible now. Let's take a look at both the methods

Method 1 - Looking for settings in Registry

First launch REGEDJT.exe from the Windows Run dialog. There are two main keys where the settings variable exists

HKEY-LOCAI__ MACHINESOFTWAREMercury Interact!veQuickTest ProfessionalMicTest Settinglnfo
HKEY„L0CAL_yACHINE5QFTWAREMercury InteractiveXQuickTest ProfessionalMicTest Packages

Let's see how to access these settings. Browse to the key as shown in the Figure.

Looking for settings in Registry

HKEY_LOCAL„MACHINESOFTWAREMercury InteractiveXQuickTest ProfessionalMicTest SettinglnfoXTSRManagerNow if we want to access the ObjRepType data inside the TSRManager key, we need to use the following codeMsgboxSetting("TSRManager")("ObjRepType")By changing the object repository type in the script and running the code mentioned above we will notice:

  1. = Per-Action repository
  2. = Shared object repository

The format is using the all the child keys after Settinglnfo and the last value name

'Access the setting value
Setting("Child Keyl")("Child Key2")("...")("Child KeyN")("ValueName")

We believe QTP gets complete registry for^the two specified keys (including sub keys). We can access any of the keys that we want by using the format specified earlier

Method 2 - Enumerating Setting Objects and Variables

The Setting object is actually the "Mercury.ScriptSetting" COM library. This library provides two undocumented arrays for enumeration. The arrays are named Keys (which contains all the keys) and items (returns all the object/value stored for a given index/key).A Setting value can be an object or a plain variable, so it's important to use the TypeName function to make this determination. The Setting.Keys property returns a 2 dimensional variant array with first dimension as 0. In the Figure we enumerate all the keys and place them into the Global DataTable in the Key, Value and Type columns:

Enumerating Setting Objects and Variables

'ObjSetting is of Type
Public Function EnumerateSettings(objSetting)
'Get arrays of key
vKeys = objSetting.Keys
'Get the 2nd dimenstion of the Keys array
i_Count = UBound(vKeys,2) On error resume next
'Loop through all the keys and get the details
For i = 0 to i_Count
DataTableC'Key",dtGlobalSheet) = vKeys(0,i)
DataTable("Value",dtGlobalSheet) = objSetting.Item(vKeys(0,i))
DataTable("Type",dtGlobalSheet) = TypeName(objSetting.Item(vKeys(0,i)))
DataTable.GlobalSheet.SetCurrentRow i+2
End Function

To enumerate current setting we can call the function as given below:

'Enumerate all settings under settings object Call EnumerateSettings (Setting)

Run the code given above and the output will appear in the run-time data table. Export the sheet and open it. The sample enumerated sheet is shown in the Figure.

sample enumerated sheet

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

QTP Topics