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?


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

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

Wednesday, February 16, 2011

Concept of ADODB Connection

Connection Object : The ADO Connection Object is used to create an open connection to a data source. Through this connection, you can access and manipulate a database.

set objConnection=Server.CreateObject("ADODB.connection")

Recordset Object: The ADO Recordset object is used to hold a set of records from a database table. A Recordset object consist of records and columns (fields).

set objRecordset=Server.CreateObject("ADODB.recordset")

 Dim rs
 Dim sConStr
 Dim sQuery
 Dim sReturnVal
 Set objCon =Nothing
 sQuery = query  
 Set objCon =CreateObject("ADODB.Connection")
 If objCon.State <> 1 Then 
  db_server = "DSN:UserID:Passwd"
  dbstring = split(db_server,":")
  objCon.Open dbstring(0),dbstring(1),dbstring(2)  
  If objCon.State <> 1 then
   ReportResult("Fail","Connection state : " & objCon.State,"Unable to establish DB connection")
   ExitAction
  Else
   ReportResult("Pass","Connection state : " & objCon.State,"Unable to establish DB connection")
  End if
 End If

Set rs = CreateObject("ADODB.Recordset")
 rs.Open sQuery,objCon,3,1
 If rs.State = 1 Then
  If rs.RecordCount > 0  Then
   rs.MoveLast
   rs.MoveFirst
   sReturnVal = rs.Fields(0).Value
  End If
 Else
  sReturnVal = ""
 End If
 Set rs=Nothing
 objCon.Close
 Set objCon =Nothing