Hi ,
Here is the script for finding the number of fields/columns of a Table in MS Access Database.
Code:
Dim db
Set db=createobject("ADODB.Connection")x.ConnectionString="DBQ=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app\flight32.mdb;DefaultDir=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\flight32.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
db.open
Set RecordSet=db.Execute("Select * from orders")
Set r= RecordSet.fields
msgbox r.count ' Number of the columns in the table 'ORDERS'
For i=0 to r.count-1
msgbox r(i).name ' name of the field/column
Next
db.close
Set db=nothing
Key Objective of this QTP blog is to help real time Automation testers as well as who are at Beginner Level, Intermediate Level in QTP by providing plenty of Script/code Based examples,a lot of innovative things in QTP which I developed,gathered. Anybody Have Query ? got stuck in or held up in the middle of Automation using QTP ? Just post your queries here & I will get back to u with an adeqaute solution for all your queries. I am catchable at sreekanth.chilam@gmail.com
Sunday, December 27, 2009
Import Data from Database Table to Datatable
Hi ,
Here is the script for importing the data from a specific column of MS Access Database Table to Datatable's GlobalSheet.
Code :
Dim db
Set db=CreateObject("ADODB.Connection")
db.connectionString="DBQ=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app\flight32.mdb;DefaultDir=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\flight32.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
db.Open
Set RecordSet=db.Execute("Select * from Orders")
i=1
While (NOT recordset.EOF)
Datatable.SetCurrentRow(i)
Datatable("CustomerName",dtGlobalSheet)=Recordset.Fields("Customer_Name")
msgbox Datatable("CustomerName",dtGlobalSheet)
Recordset.MoveNext
i=i+1
Wend
db.Close
Set db=Nothing
Here is the script for importing the data from a specific column of MS Access Database Table to Datatable's GlobalSheet.
Code :
Dim db
Set db=CreateObject("ADODB.Connection")
db.connectionString="DBQ=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app\flight32.mdb;DefaultDir=C:\PROGRAM FILES\HP\QuickTest Professional\samples\flight\app;Driver={Microsoft Access Driver (*.mdb)};DriverId=281;FIL=MS Access;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\flight32.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
db.Open
Set RecordSet=db.Execute("Select * from Orders")
i=1
While (NOT recordset.EOF)
Datatable.SetCurrentRow(i)
Datatable("CustomerName",dtGlobalSheet)=Recordset.Fields("Customer_Name")
msgbox Datatable("CustomerName",dtGlobalSheet)
Recordset.MoveNext
i=i+1
Wend
db.Close
Set db=Nothing
Sunday, December 6, 2009
Encrypting a String in QTP
Hi All,
Here we go !!!!
QTP has an utility Object called as "Crypt" object.
As the name implies, the "Crypt" object in HP Quicktest Professional is for encrypting the strings which can only be understood by QTP's "SetSecure" method. "Encrypt" is the only method supported by the QTP "Crypt" object.
Way1:
syntax : Crypt.Encrypt(Your String)
An example:
str="ExpertQTP"
var=Crypt.Encrypt(str)
msgbox var
The output of the above code would be "4ac6e9ba26cad2886bf331a767bfa1ce055f68e66bed5d61"
As you can see, this string is encrypted which is quite obvious.
Note:
Recording on password protected fields automatically encrypts your string for example
Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:=Password").SetSecure "4ac6e9ba26cad2886bf331a767bfa1ce055f68e66bed5d61"
Way2:
Another way , how we can encrypt a string is by using "Mercury.Encrypter"
Set var=CreateObject("Mercury.Encrypter")
Msgbox var.Encrypt("QTP")
Set var=Nothing 'Release the Object reference
Way3:
Using "Password Encoder".
Navigate to Start-> All Programs-> QuickTest Professional-> Tools-> Password Encoder
Provide your string inside the "Password" field and click on the Generate button. Your encrypted string would be displayed inside the "Encoded String" field.
Here we go !!!!
QTP has an utility Object called as "Crypt" object.
As the name implies, the "Crypt" object in HP Quicktest Professional is for encrypting the strings which can only be understood by QTP's "SetSecure" method. "Encrypt" is the only method supported by the QTP "Crypt" object.
Way1:
syntax : Crypt.Encrypt(Your String)
An example:
str="ExpertQTP"
var=Crypt.Encrypt(str)
msgbox var
The output of the above code would be "4ac6e9ba26cad2886bf331a767bfa1ce055f68e66bed5d61"
As you can see, this string is encrypted which is quite obvious.
Note:
Recording on password protected fields automatically encrypts your string for example
Browser("micclass:=Browser").Page("micclass:=Page").WebEdit("name:=Password").SetSecure "4ac6e9ba26cad2886bf331a767bfa1ce055f68e66bed5d61"
Way2:
Another way , how we can encrypt a string is by using "Mercury.Encrypter"
Set var=CreateObject("Mercury.Encrypter")
Msgbox var.Encrypt("QTP")
Set var=Nothing 'Release the Object reference
Way3:
Using "Password Encoder".
Navigate to Start-> All Programs-> QuickTest Professional-> Tools-> Password Encoder
Provide your string inside the "Password" field and click on the Generate button. Your encrypted string would be displayed inside the "Encoded String" field.
Subscribe to:
Posts (Atom)