Tuesday, April 26, 2011

Distinguish obsolute path and relative path in QTP & How to access them..?

Absolute path means we have to mention full path in script.
Example: ExecuteFile "E:\project name\libraries\main.vbs"

Relative path means the path which you want to access from the rootfile you need.
Example: ExecuteFile "main.vbs"

But here if you want to convert this Absolute file path as Relative path. Steps to produce:

Tools->options->Folder->check the checkbox "Relative path ...."
here you have to add this path example "E:\project name\libraries"

then you can use direct filename as above mentioned in the relative path example instead of absolute path example.

Basically it's good to prefer relative path as, if the location of the root folder changes you do not get any errors.

How to lock the computer after completion of script execution in QTP?

The good thing about Automation Testing is that Scripts are run in an unattended mode. Usually, people do - prepare the batch of scripts and leave for their homes. After the batch got executed, no matter even if it passes or even get failed, the PC has to be locked .So that, avoiding others to view your information related to your project which makes us a good practice.

Set obj = CreateObject("WScript.Shell")
sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
obj.Run sCmnd, 0, False

Monday, April 25, 2011

Can a function return a dictionary object?

Answer# 1
Dim dicObj
Set dicObj = CreateObject("Scripting.Dictionary")
Set obj=getname

Public Function getname()
dicObj.add "name","Uday Kumar"
Set getname=dicObj
End function

Answer# 2
Public Sub GetValue()
Set obj = getname
MsgBox (obj.Item("name"))
End Sub

Public Function getname()
Dim dicObj
Set dicObj = CreateObject("Scripting.Dictionary")
dicObj.Add "name", "Uday Kumar"
Set getname = dicObj
End Function