Saturday, July 26, 2014

Home page

Classroom and Online Training QTP Classes in Pune,Delhi and Mumbai-09763315036

HP Quick Test Professional Online training from Automation Infotech 91-9763315036

Comprehensive QuickTest Professional 10.0
Course Code : QTP032012
Source : AutoamtionInfotech


HP Quick Test Professional (QTP basic to In-depth concepts + VB Scripting +

Descriptive Programming + Framework Development + Certification) Training


Please find below the QTP training details.

Training: QTP Specialist with Framework plus Certification Training

Duration: 4-5 weeks

Trainer: QTP Certified with 6+ years of experience working as Automation lead

Call 09763315036 / 9922500360



Classroom and Online Training Selenium Classes in Pune,Delhi and Mumbai-09922500360

Selenium Online training from Automation Infotech 91-9922500360

Comprehensive Selenium
Course Code : Selenium 112014
Source : AutoamtionInfotech


Selenium  basic to In-depth concepts + Java + RC + Web Driver + Grid + Framework Development  Training


Please find below the Selenium training details.

Training: Selenium Specialist with Framework plus Certification Training

Duration: 9 weeks


Call 09763315036 / 9922500360



Friday, July 25, 2014

Database Scripts-II

Database Scripts-II

1) Insert Data into a database table using Database Command Object

Dim objCon,objCom Set objCon=Createobject("ADODB.connection")
objCon.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\automation.mdb;"
Set objCom=Createobject("ADODB.Command") objCom.ActiveConnection=objCon
objCom.CommandText="insert into Emp values('automation infotech',89652,30000)"
objCon.Close
Set objCom=Nothing
Set objCon=Nothing
Set objCon=Createobject("ADODB.connection")
objCon.open"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\automation.mdb;"
Set objCom=Createobject("ADODB.Command")
objCom.ActiveConnection=objCon
Datatable.AddSheet("input")
Datatable.ImportSheet "C:\automation.xls",1,"input"
Msgbox intRowcount
For i=1 to intRowcount step 1
    DataTable.SetCurrentRow(i)
    strEmpName=    DataTable.Value(1,"input")
    intEmpNo=    DataTable.Value(2,"input")
    intEmpSal=    DataTable.Value(3,"input")
objCom.CommandText="insert into Emp values( '"&strEmpName&" ',"&intEmpNo&","&intEmpSal&")"
objCom.Execute
Next
objCon.Close
Set objCom=Nothing
Set objCon=Nothing  
----------
Dim objCon, objRs, objExcel, myFile, mysheet
Set objCon=CreateObject("Adodb.Connection")
Set objRs= CreateObject("Adodb.Recordset")
Set objExcel=CreateObject("Excel.Application")
Set myFile=objExcel.Workbooks.Open ("C:\Documents and Settings\automation\Desktop\TestData2.xls")
Rc=mySheet.usedrange.rows.count
'Msgbox Rc
objCon.Provider=("Microsoft.Jet.oledb.4.0")
objCon.Open "C:\Documents and Settings\automation\Desktop\Comp.mdb"
objRs.Open "Select EMPName from Employee", objCon



Do Until objRs.EOF=True
x=objRs.Fields("EMPName")
    For j= 2 to Rc
y=mySheet.cells(j,"A")

If x=y  Then
    Reporter.ReportEvent micPass,"Res","Name: "& y &"  Available"
'    Else
'Reporter.ReportEvent micFail,"Res","Name: "& y &"  Not Available"

End If
    Next
   
objRs.MoveNext
Loop
objExcel.Quit
Set objExcel=Nothing
objRs.Close
objCon.Close
Set objRs=Nothing
Set objCom=Nothing

objRs.Open "Select EMPName from Employee", objCon


Do Until objRs.EOF=True
x=objRs.Fields("EMPName")
    For j= 2 to Rc
y=mySheet.cells(j,"A")
If x=y  Then
    Reporter.ReportEvent micPass,"Res","Name: "& y &"  Available"
'    Else
'Reporter.ReportEvent micFail,"Res","Name: "& y &"  Not Available"
End If
    Next
   
objRs.MoveNext
Loop
objExcel.Quit
Set objExcel=Nothing
objRs.Close
objCon.Close
Set objRs=Nothing
Set objCom=Nothing
objCom.Execute

2) Insert multiple sets of Data (using Excel sheet)  into a database table using Database Command Object

Dim objCon,objCom,strEmpName,intEmpNo,intEmpSal,intRowcount,i
intRowcount=Datatable.GetSheet("input").GetRowCount

3) Fetch data from a database, and compare with expected data in Excel file.
Set mySheet=myFile.Worksheets("Sheet1")
------------------------------------

Database Scripts-1

 



 Database Scripts-I

1) Get Test Data From a Database and use in Data Driven Testing (through Scripting)

Dim objCon, objRs
'Creating an automation object in database connection class, it is used for connecting to databases.
Set objCon=CreateObject("Adodb.Connection")
'Creating an automation object in database record set class, it is used for performing operations on database tables(records).
Set objRs= CreateObject("Adodb.Recordset")
'Establishing connection string for Ms-Access database.
objCon.Provider=("Microsoft.Jet.oledb.4.0")
objCon.Open "C:\Documents and Settings\automation\Desktop\Flights.mdb"
objRs.Open "Select * from Login", objCon
Do Until objRs.EOF=True
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objRs.Fields("Agent")
Dialog("Login").WinEdit("Password:").Set objRs.Fields("Pwd")
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close
objRs.MoveNext
Loop
objRs.Close
objCon.Close
Set objCon=Nothing
Set objRs=Nothing

2) Exporting Data from a Database to an Excel Sheet

1) Dim con,rs
2) Set con=createobject("adodb.connection")
3) Set rs=createobject("adodb.recordset")
4) con.provider="microsoft.jet.oledb.4.0"
5) con.open"C:\Documents and Settings\admin\My Documents\automation.mdb"
6) rs.open"select*from Login",con
7) Set ex=createobject("Excel.Application")
8) Set a=ex.workbooks.open("C:\Documents and Settings\admin\My Documents\automation.xls")
9) Set b=a.worksheets("sheet1")
10) i=1
11) Do While Not rs.EOF
12) b.cells (i,1).value=rs.fields("agent")
13) b.cells(i,2).value=rs.fields("password")
14) rs.movenext
15) i=i+1
16) Loop
17) a.save
18) a.close

3) Exporting Data from a Database to a Text file
 
Dim objCon,objRs,ObjFso,myFile,myData,rc,r
Set objCon=createobject("Adodb.connection")
Set objRs=createobject("Adodb.Recordset")
set objFso=createobject("Scripting.Filesystemobject")
Set myFile=objFso.OpenTextFile("C:\Documents and Settings\auto\My Documents\automation.txt",8)
objcon.provider=("Microsoft.jet.oledb.4.0")
objcon.open"C:\Documents and Settings\gcr\My Documents\automation.mdb"
objrs.open "select * from login",objCon
r=1
Do until objRs.EOF
a=objRs.Fields ("Agent")
b=objRs.Fields ("Pwd")
myFile.Writeline a &","& b
r=r+1
objRs.MoveNext
Loop
myFile.Close
objCon.Close

4) Connecting to a SQL Sever database

Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider=SQLOLEDB;Data Source=atl-sql-01;" & _
"Trusted_Connection=Yes;Initial Catalog=Northwind;" & _
"User ID=fabrikam\kenmyer;Password=34DE6t4G!;"

objRecordSet.Open "SELECT * FROM Customers", _
objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst

Wscript.Echo objRecordSet.RecordCount

5) Open a Database Using a DSN

Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Northwind;fabrikam\kenmyer;34ghfn&!j"

objRecordSet.Open "SELECT * FROM Customers", _
objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst

Wscript.Echo objRecordSet.RecordCount


6) Open Two Recordsets


Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")
Set objRecordSet2 = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider= Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=inventory.mdb"

objRecordSet.Open "SELECT * FROM GeneralProperties Where ComputerName = 'Computer1'", _
objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst


objRecordSet2.Open "SELECT * FROM Storage Where ComputerName = 'Computer1'", _
objConnection, adOpenStatic, adLockOptimistic

objRecordSet2.MoveFirst

Do Until objRecordset.EOF
Wscript.Echo objRecordset.Fields.Item("ComputerName")
Wscript.Echo objRecordset.Fields.Item("OSName")
objRecordSet.MoveNext
Loop

Do Until objRecordset2.EOF
Wscript.Echo objRecordset2.Fields.Item("DriveName"), _
objRecordset2.Fields.Item("DriveDescription")
objRecordSet2.MoveNext
Loop

objRecordSet.Close
objRecordSet2.Close
objConnection.Close


7) Searching a Database Using String Criteria

Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider = Microsoft.Jet.OLEDB.4.0; " & _
"Data Source = eventlogs.mdb"

objRecordSet.Open "SELECT * FROM EventTable " & _
"WHERE Type = 'Error'", objConnection, adOpenStatic, _
adLockOptimistic

objRecordSet.MoveFirst

Wscript.Echo "Number of records: " & objRecordset.RecordCount

objRecordSet.Close
objConnection.Close

For More Scripts visit:

VB Script Functions

Conversion Functions

1) Asc Function

Returns the ANSI character code corresponding to the first letter in a string.
Syntax:
Asc(string)
Remarks

The string argument is any valid string expression. If the string contains no characters, a run-time error occurs.
Dim MyNumber
MyNumber = Asc("A")       ' Returns 65.
MyNumber = Asc("a")       ' Returns 97.
MyNumber = Asc("Apple")   ' Returns 65.

2) CByte Function

Returns an expression that has been converted to a Variant of subtype Byte.
Syntax:

CByte(expression)
The expression argument is any valid expression.
Use the CByte function to provide conversions from any data type to a Byte subtype.
Example:
Dim MyDouble, MyByte
MyDouble = 125.5678        ' MyDouble is a Double.
MyByte = CByte(MyDouble)   ' MyByte contains 126.

3) CDate Function
Returns an expression that has been converted to a Variant of subtype Date.
Syntax:
CDate(date)
The date argument is any valid date expression.
Use the IsDate function to determine if date can be converted to a date or time.
Example:

MyDate = "October 19, 1962"   ' Define date.
MyShortDate = CDate(MyDate)   ' Convert to Date data type.
MyTime = "4:35:47 PM"         ' Define time.
MyShortTime = CDate(MyTime)   ' Convert to Date data type.

4) Chr Function

Returns the character associated with the specified ANSI character code.
Syntax:

Chr(charcode)

The charcode argument is a number that identifies a character.
Numbers from 0 to 31 are the same as standard, nonprintable ASCII codes. For example, Chr(10) returns a linefeed character.
Example:
Dim MyChar

' Returns A:
MyChar = Chr(65)  
' Returns B:
MyChar = Chr(66)  
' Returns Z:
MyChar = Chr(90)  

' Returns a:
MyChar = Chr(97)  
' Returns b:
MyChar = Chr(98)  
' Returns z:
MyChar = Chr(122) 

' Returns 0:
MyChar = Chr(48)  
' Returns 1:
MyChar = Chr(49)  
' Returns 9:
MyChar = Chr(57)  

' Returns horizontal tab:
MyChar = Chr(9)
' Returns >:
MyChar = Chr(62)  
' Returns %:
MyChar = Chr(37)  

5) CLng Function
Returns an expression that has been converted to a Variant of subtype Long.
Syntax:

CLng(expression)

The expression argument is any valid expression.
Use the CLng function to provide conversions from any data type to a Long subtype.
Example:
Dim MyVal1, MyVal2, MyLong1, MyLong2
MyVal1 = 25427.45: MyVal2 = 25427.55   ' MyVal1, MyVal2 are Doubles.
MyLong1 = CLng(MyVal1)   ' MyLong1 contains 25427.
MyLong2 = CLng(MyVal2)   ' MyLong2 contains 25428.

6) CStr Function

Returns an expression that has been converted to a Variant of subtype String.
Syntax:
CStr(expression)

The expression argument is any valid expression.
Example:
Dim MyDouble, MyString
MyDouble = 437.324         ' MyDouble is a Double.
MyString = CStr(MyDouble)   ' MyString contains "437.324"

7) Oct Function

Returns a string representing the octal value of a number.
Syntax:
Oct(number)

The number argument is any valid expression.
Example:
Dim MyOct
MyOct = Oct(4)     ' Returns 4.
MyOct = Oct(8)     ' Returns 10.
MyOct = Oct(459)   ' Returns 713.

8) CBool Function

Returns an expression that has been converted to a Variant of subtype Boolean.
Synta:
CBool(expression)

The expression argument is any valid expression.
If expression is zero, False is returned; otherwise, True is returned. If expression can't be interpreted as a numeric value, a run-time error occurs.
Example:
Dim A, B, Check
A = 5: B = 5           ' Initialize variables.
Check = CBool(A = B)   ' Check contains True.
A = 0                  ' Define variable.
Check = CBool(A)       ' Check contains False.

9) CCur Function

Returns an expression that has been converted to a Variant of subtype Currency.
Syntax:
CCur(expression)
The expression argument is any valid expression.
Example:
Dim MyDouble, MyCurr
MyDouble = 543.214588         ' MyDouble is a Double.
MyCurr = CCur(MyDouble * 2)   ' Convert result of MyDouble * 2 (1086.429176) to a Currency (1086.4292).

10) CInt Function

Returns an expression that has been converted to a Variant of subtype Integer.
Syntax:
CInt(expression)
The expression argument is any valid expression.
Example:

Dim MyDouble, MyInt
MyDouble = 2345.5678     ' MyDouble is a Double.
MyInt = CInt(MyDouble)   ' MyInt contains 2346.

11) CSng Function

Returns an expression that has been converted to a Variant of subtype Single.
Syntax:
CSng(expression)

The expression argument is any valid expression.
Example:
Dim MyDouble1, MyDouble2, MySingle1, MySingle2   ' MyDouble1, MyDouble2 are Doubles.
MyDouble1 = 75.3421115: MyDouble2 = 75.3421555
MySingle1 = CSng(MyDouble1)   ' MySingle1 contains 75.34211.
MySingle2 = CSng(MyDouble2)   ' MySingle2 contains 75.34216.

12) Hex Function

Returns a string representing the hexadecimal value of a number.
Syntax:
Hex(number)
number argument is any valid expression.
we can represent hexadecimal numbers directly by preceding numbers in the proper range with &H.
Example:
Dim MyHex
MyHex = Hex(5)   ' Returns 5.
MyHex = Hex(10)   ' Returns A.
MyHex = Hex(459)   ' Returns 1CB.

For More Functions visit:

VB Script String Functions

String Functions 

1) Left Function


Returns a specified number of charectors of a given string from left side
Syntax:
variable=Left(string,Lengh)
Example:
Dim val,x
val="Hyderabad"
x=Left(val,3)
msgbox x ' Output: Hyd

val="9247837478"
x=Left(val,1)
msgbox x ' Output: 9

val="H92yderabad"
x=Left(val,3)
msgbox x ' Output: H92

x=Left(9247837478,5)
msgbox x ' Output: 92478
val=#10-10-10#
x=Left(val,3)
msgbox x ' Output: 10/
2) Right Function
Returns a specified number of charectors of a given string from Right side
Example:
Dim val,x
val="Hyderabad"
x=Right(val,3)
msgbox x ' Output: bad

val="9247837478"
x=Right(val,1)
msgbox x ' Output: 8

val="H92yderabad"
x=Right(val,3)
msgbox x ' Output: bad

x=Right(9247837478,5)
msgbox x ' Output: 37478
val=#10-10-10#
x=Right(val,5)
msgbox x ' Output: /2010
3) Mid function
Returns a specified number of charectors of a given string

Example:
Dim val,x
val="Hyderabad"
x=Mid(Val,5,3)
msgbox x ' Output: rab
val="Hyderabad"
x=Mid(Val,5)
msgbox x ' Output: rabad
val="9247837478"
x=Mid(val,6,5)
msgbox x ' Output: 37478

val="H92yderabad"
x=Mid(val,1)
msgbox x ' Output: H92yderabad

x=Mid(9247837478,5)
msgbox x ' Output: 837478
val=#10-10-10#
x=Mid(val,5)
msgbox x ' Output: 0/2010
4) StrReverse
retuns reverse value of a string
Example:
Dim val,x
val="Hyderabad"
x=StrReverse(val)
msgbox x 'Output dabaredyH
val="001"
x=StrReverse(val)
msgbox x 'Output: 100
val=1002
x=StrReverse(val)
msgbox x 'Output: 2001
val=#10-10-10#
x=StrReverse(val)
msgbox x 'Output: 0102/01/01
x=StrReverse("Hyderabad")
msgbox x 'Output: dabaredyH
x=StrReverse(100)
msgbox x 'Output: 001
5) StrComp Function
It compares two string (Binary and textual)
if
a) Both are equal, returns 0(zero)
b) String 1 greater than string 2, returns 1(one)

b) String 2 greater than string 1, returns -1
Example:
Dim str1,str2,x
str1="India"
str2="India"
x=StrComp(str1,str2,1)
msgbox x 'Output 0
str1="india"
str2="INDIA"
x=StrComp(str1,str2,1)
msgbox x 'Output 0
str1="India"
str2="Indian"
x=StrComp(str1,str2,1)
msgbox x 'Output -1
str1="Indian"
str2="Ndia"
x=StrComp(str1,str2,1)
msgbox x 'Output -1
str1="Indian"
str2="India"
x=StrComp(str1,str2,1)
msgbox x 'Output 1
str1=100
str2=100
x=StrComp(str1,str2,1)
msgbox x 'Output 0
str1=100
str2=101
x=StrComp(str1,str2,1)
msgbox x 'Output -1
6) Lcase function
Coverts Upper case values into Lower case
Dim val,x
val="HYDERABAD"
x=Lcase(val)
msgbox x 'Output hyderabad
val="Hyderabad"
x=Lcase(val)
msgbox x 'Output hyderabad
val="HederabaD"
x=Lcase(val)
msgbox x 'Output hyderabad
val="hyderabad"
x=Lcase(val)
msgbox x 'Output hyderabad
x=Lcase("HYDERABAD")
msgbox x 'Output hyderabad

7) Ucase function
Coverts Lower case values into Upper case
Example:
Dim val,x
val="HYDERABAD"
x=Ucase(val)
msgbox x 'Output HYDERABAD
val="Hyderabad"
x=Ucase(val)
msgbox x 'Output HYDERABAD
val="HederabaD"
x=Ucase(val)
msgbox x 'Output HYDERABAD
val="hyderabad"
x=Ucase(val)
msgbox x 'Output HYDERABAD
x=Ucase("HYDERABAD")
msgbox x 'Output HYDERABAD


8) LBound, UBound Functions


Example:


Dim x(3), y(4,5)


Msgbox Lbound(x) '0


Msgbox UBound(x)'3


'Find size of the Array


Msgbox UBound(x)+1


Msgbox Lbound(y,1) '0


Msgbox Lbound(y,2) '0


Msgbox UBound(y,1) '4


Msgbox UBound(y,2) '5

VB Script Functions

Built-In Functions of VB Script



  • Conversions (25)
  • Dates/Times (19)
  • Formatting Strings (4)
  • Input/Output (3)
  • Math (9)
  • Miscellaneous (3)
  • Rounding (5)
  • Strings (30)
  • Variants (8)

Important Functions


1) Abs Function
Returns the absolute value of a number.

Dim num
num=abs(-50.33)
msgbox num

2) Array Function
Returns a variant containing an Array

Dim A
A=Array("hyderabad","chennai","mumbai")
msgbox A(0)
ReDim A(5)
A(4)="nellore"
msgbox A(4)

3) Asc Function
Returns the ANSI character code corresponding to the first letter in a string.

Dim num
num=Asc("A")
msgbox num
* It returns the value 65 *

4) Chr Function
Returns the character associated with the specified ANSI character code.

Dim char
Char=Chr(65)
msgbox char
* It returns A *

5) CInt Function
Returns an expression that has been converted to a Variant of subtype Integer.

Dim num
num=123.45
myInt=CInt(num)
msgbox MyInt

6) Date Function
Returns the Current System Date.

Dim mydate
mydate=Date
msgbox mydate

7) Day Function
Ex1) Dim myday
myday=Day("17,December,2009")
msgbox myday

Ex2) Dim myday
mydate=date
myday=Day(Mydate)
msgbox myday

8) DateDiff Function
Returns the number of intervals between two dates.

Dim Date1, Date2, x

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("yyyy", Date1, Date2)
Msgbox x 'Differnce in Years

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("q", Date1, Date2)
Msgbox x 'Differnce in Quarters

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("m", Date1, Date2)
Msgbox x 'Differnce in Months

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("w", Date1, Date2)
Msgbox x 'Differnce in weeks

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("d", Date1, Date2)
Msgbox x 'Differnce in days

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("h", Date1, Date2)
Msgbox x 'Differnce in Hours

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("n", Date1, Date2)
Msgbox x 'Differnce in Minutes

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("s", Date1, Date2)
Msgbox x 'Differnce in Seconds

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("y", Date1, Date2)
Msgbox x  'Differnce in day of years

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff("a", Date1, Date2)
Msgbox x 'Error

Date1=#10-10-09#
Date2=#10-10-11#
x=DateDiff(Date1, Date2)
Msgbox x 'Error

9) Hour Function
Returns a whole number between 0 and 23, inclusive, representing the hour of the day.

Dim mytime, Myhour
mytime=Now
myhour=hour (mytime)
msgbox myhour

10) Join Function
Returns a string created by joining a number of substrings contained in an array.

Dim mystring, myarray(3)
myarray(0)="Chandra "
myarray(1)="Mohan "
myarray(2)="Reddy"
mystring=Join(MyArray)
msgbox mystring

11) Eval Function

Evaluates an expression and returns the result.

12) Time Function
Returns a Variant of subtype Date indicating the current system time.

Dim mytime
mytime=Time
msgbox mytime

13) VarType Function

Returns a value indicating the subtype of a variable.

Dim x,y
x=100
y=VarType(x)
Msgbox y '2 (Integer)

x="Hyderabad"
y=VarType(x)
Msgbox y '8 (String)

x=#10-10-10#
y=VarType(x)
Msgbox y '7(Date format)

x=100.56
y=VarType(x)
Msgbox y ' 5(Double)


y=VarType(a)
Msgbox y '0 (Empty)

Set x =CreateObject("Scripting.FileSystemObject")
y=VarType(x)
Msgbox y '9(Automation Object)

14) Left Function

Dim Val, x,y
Val="Hyderabad"
x=Left(Val,3)
Msgbox x 'Hyd

Val=100
x=Left(Val,1)
Msgbox x '1

Val="Hyderabad"
x=Left(Val,0)
Msgbox x 'Null

Val="Hyderabad"
x=Left(Val,12)
Msgbox x 'Hyderabad

Val=#10-10-10#
x=Left(Val,3)
Msgbox x '10/

Val="Hyderabad"
x=Left(Val)
Msgbox x 'Error (Lengnth is Manditory)

14) Right Function
Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.
MyStr = Right(AnyString, 1) ' Returns "d".
MyStr = Right(AnyString, 6) ' Returns " World".
MyStr = Right(AnyString, 20) ' Returns "Hello World".

15) Len Function
Returns the number of characters in a string or the number of bytes required to store a variable.

Ex 1):
Dim Mystring
mystring=Len("G.C.Reddy")
msgbox mystring

Ex 2):
Dim Mystring
Mystring=Inputbox("Enter a Value")
Mystring=Len(Mystring)
Msgbox Mystring

16) Mid Function
Returns a specified number of characters from a string.

Dim Val, x,y
Val="Hyderabad"
x=Mid(Val,3,4)
Msgbox x 'dera

Val=100
x=Mid(Val,1)
Msgbox x '100

Val="Hyderabad"
x=Mid(Val,6,7)
Msgbox x 'abad

Val="Hyderabad"
x=Mid(Val,6,1)
Msgbox x 'a

Val="Hyderabad"
x=Mid(Val,6,0)
Msgbox x 'Null

Val="Hyderabad"
x=Mid(Val,12)
Msgbox x 'Null

Val=#10-10-10#
x=Mid(Val,3,3)
Msgbox x '/10

Val=#2010-10-10#
x=Mid(Val,5)
Msgbox x '/2010

Val="Hyderabad"
x=Mid(Val)
Msgbox x 'Error


17) Timer Function
Returns the number of seconds that have elapsed since 12:00 AM (midnight).

Function myTime(N)
Dim StartTime, EndTime
StartTime = Timer
For I = 1 To N
Next
EndTime = Timer
myTime= EndTime - StartTime
msgbox myTime
End Function
Call myTime(2000)

17) isNumeric Function

Dim MyVar, MyCheck
MyVar = 53
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
MyVar = "459.95"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
MyVar = "45 Help"
MyCheck = IsNumeric(MyVar)
msgbox MyCheck
* It Returns True/False like Result *

18) Inputbox Function

Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns the contents of the text box.

Dim Input
Input = InputBox("Enter your name")
MsgBox ("You entered: " & Input)

19) Msgbox Function

Displays a message in a dialog box, waits for the user to click a button, and returns a value indicating which button the user clicked.

Dim MyVar
MyVar = MsgBox ("Hello World!", 65, "MsgBox Example")

20) CreateObject

creates and returns reference of the filesytemobject to an Automation object. It can be used for performing operations on computer file system

Set objFso=createobject ("Scripting.FileSystemObject")

'creates and returns reference of  the Excel bject to an Automation object. It can be used for performing operations on Spreed sheet (Ms-Excel files)

Set objExcel = CreateObject("Excel.Application")

'creates and returns reference of  the Word Object to an Automation object. It can be used for performing operations on Ms-Word documents

Set objWord = CreateObject("Word.Application")

'creates and returns reference of  the Database Connection to an Automation object. It can be used for Connecting, opening and Closing databases

Set objConnection = CreateObject("ADODB.Connection")


'creates and returns reference of  the Database Recordset to an Automation object. It can be used for performing operations on database tables(Records)

Set objRecordSet = CreateObject("ADODB.Recordset")

'creates and returns reference of  the Ms-Power point object to an Automation object. It can be used for performing operations on Power point presentations

Set objPPT = CreateObject("PowerPoint.Application")

Set xmldoc = WScript.CreateObject("msxml2.domdocument")

21) Round

Returns a number rounded to a specified number of decimal places.

Dim num
num=172.499
num=Round(num)
msgbox num

22) StrReverse
It returns reverse value of the given sring
x=strreverse ("dabaraedyh")
msgbox x

23) strComp
It compares two strings based on ASCII Values and Returens -1 (1st less than 2nd ), 0 (Equal) and 1 (1st greater than 2nd)
Dim x, y
x="cd": y="bcd"
comp=strcomp(x,y)
msgbox comp

24) Replace
It replace a sub string with given value (another sub string)
mystring=Replace("kb script", "k","v")
msgbox mystring

For More Functions visit:

Looping Through Code

Flow Control (Loop Statements)


  • Looping allows us to run a group of statements repeatedly.
  • Some loops repeat statements until a condition is False;
  • Others repeat statements until a condition is True.
  • There are also loops that repeat statements a specific number of times.
  • The following looping statements are available in VBScript:
  • Do...Loop: Loops while or until a condition is True.
  • While...Wend: Loops while a condition is True.
  • For...Next: Uses a counter to run statements a specified number of times.
  • For Each...Next: Repeats a group of statements for each item in a collection or each element of an array.


1) Using Do Loops

We can use Do...Loop statements to run a block of statements an indefinite number of times.

The statements are repeated either while a condition is True or until a condition becomes True.

a)  Repeating Statements While a Condition is True

Repeats a block of statements while a condition is True or until a condition becomes True

i) Do While condition
Statements
-----------
-----------
Loop
Or, we can use this below syntax:

Example:

Dim x
Do While x<5 x="x+1<br"> Msgbox "Hello G.C.Reddy"
Msgbox "Hello QTP"
Loop

ii) Do
Statements
-----------
-----------
Loop While condition


Example:

Dim x
x=1
Do
Msgbox "Hello G.C.Reddy"
Msgbox "Hello QTP"
x=x+1
Loop While x<5 br="">

b)  Repeating a Statement Until a Condition Becomes True

iii) Do Until condition
Statements
-----------
-----------
Loop
Or, we can use this below syntax:
Example:

Dim x
Do Until x=5 x=x+1
Msgbox "G.C.Reddy"
Msgbox "Hello QTP"
Loop

Or, we can use this below syntax:

iv) Do
Statements
-----------
-----------
Loop Until condition
Or, we can use this below syntax:

Example:

Dim x
x=1
Do
Msgbox “Hello G.C.Reddy”
Msgbox "Hello QTP"
x=x+1
Loop Until x=5

2 While...Wend Statement

Executes a series of statements as long as a given condition is True.

Syntax:
While condition
Statements
-----------
-----------
Wend

Example:

Dim x
x=0
While x<5 x="x+1<br"> msgbox "Hello G.C.Reddy"
msgbox "Hello QTP"
Wend

3)  For...Next Statement

Repeats a group of statements a specified number of times.
Syntax:
For counter = start to end [Step step]
statements
Next

Example:
Dim x
For x= 1 to 5 step 1
Msgbox "Hello G.C.Reddy"
Next

4)  For Each...Next Statement

Repeats a group of statements for each element in an array or collection.

Syntax:

For Each item In array
Statements
Next

Example: (1

Dim a,b,x (3)
a=20
b=30
x(0)= "Addition is "& a+b
x(1)="Substraction is " & a-b
x(2)= "Multiplication is " & a*b
x(3)= "Division is " & a/b

For Each element In x
msgbox element
Next

Example: (2

MyArray = Array("one","two","three","four","five")
For Each element In MyArray
msgbox element
Next 

Driver Script

 Driver Script

Generally in Keyword Driven Framework Driver Script is the only QTP Script, remaining all are Vb Script files (.vbs) 
Driver script organizes Tests execution and stores Test logs in the specified file/folder

Sample Driver Script
'adding sheets to runtime data table
datatable.AddSheet ("Module")
datatable.AddSheet ("Testcase")
datatable.AddSheet ("Teststep")

'Importing sheets from an external excel file
datatable.ImportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\test data\inputdata.xls",1,"Module"
datatable.ImportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\test data\inputdata.xls",2,"Testcase"
datatable.ImportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\test data\inputdata.xls",3,"Teststep"

Mrowcount=datatable.GetSheet("Module").getrowcount
For i=1 to Mrowcount step 1
    datatable.SetCurrentRow(i)
    Mexe=datatable.Value(3,"Module")
    If ucase(Mexe)="Y"  Then
        ModuleId= datatable.Value (1,"Module")

        Tcrowcount=datatable.GetSheet ("Testcase").getrowcount
        For j=1 to Tcrowcount step 1
            datatable.SetCurrentRow (j)
            ModuleId1=datatable.Value(4,"Testcase")
            Tcexe=datatable.Value(3,"Testcase")
            If ModuleId=ModuleId1 and Ucase(Tcexe)="Y" Then
                TcId=datatable.Value(1,"Testcase")

                Tsrowcount=datatable.GetSheet("Teststep").getrowcount
                For k= 1 to Tsrowcount step 1
                datatable.SetCurrentRow(k)
                Tcid1=Datatable.Value(5,"Teststep")

                    If TcId= TcId1 Then
                        keyword= datatable.Value(3,"Teststep")
                        Select Case keyword
                        Case "ln"
                        res=Login()
                        datatable.Value(6,"Teststep")=res
                        Case "ca"
                            close_app
                        Case "op"
                            res=Openord()
                            datatable.Value(6,"Teststep")=res
                           
                        End Select
                    End If

                Next
            End If

        Next
    End If
Next
datatable.ExportSheet "C:\Documents and Settings\gcreddy\Desktop\flights\testlog\results.xls","Teststep"

Sample Initialization Script  
 Initialization Script Launches QTP Tool and Calls Driver Script, Driver Script execute Tests and Stores Results.
Finally   Initialization Script Closes QTP tool

Option Explicit
Dim qtApp
set qtApp=createobject("QuickTest.Application")
qtApp.Launch
qtApp.Visible=True
qtApp.Open "C:\Flight\Testscripts\Driver"
qtApp.Test.Run
qtApp.Quit

QTP Framework

Automation Framework

Automation:

Accessing one Software Objects from another Software is called Automation.

(AUT is one s/w and Testing Tool is another s/w.)

Automation Framework:

It is a set of guidelines, assumptions and process developed by experts in order to perform a task(s) in an effective, efficient and optimized way.

A systematic approach for automating software applications.

Why Automation Framework:

In one project test automation we use various files, we perform various tasks, in order to organize and manage them all, a systematic approach (Automation Framework) required.

files to be used:

a) Flat files (.txt),

b) Excel files (.xls)

c) Object repository files (.tsr)

d) XML files (.xml)

e) Library files (.vbs)

f) Test Scripts (.mts)

g) Test Batch Files (.mtb)

h) Recovery scenario files (.qrs)

i) Test Result file (.XML)   Etc...

Tasks to be performed:

a) Analyzing the application
We analyze the AUT in terms of Object Identification and Functionality.
Basically, QTP is an Object based test tool, here first we have to confirm
if the QTP is recognizing all the objects in our application or not.
To do this, we can follow one or more below given methods...

        i) Record and playback some End to End Scenarios.
        ii) Using Object Spy
        iii) Using Object Repository Manager


We can segregate Software Objects in 3 categories...


    i) Static Objects(Properties information is constant)
    ii) Dynamic Objects(Properties info changes dynamically)
    iii) Duplicate Objects(Having Similar property info.)

Note:We can handle dynamic Objects using Regular expressions and handle duplicate
Objects using "Index" property.

b) Selecting Areas/Test Cases for Automation 

Overview:
100% test automation is not possible, we can go for maximum automation.

    i)Tests that we want to execute on multiple versions of software(Sanity,Regression Tests)
    ii)Tests that we want to execute with multiple sets of test data.(Data Driven Tests)

    iii) Tests having complex functionality

c) Planning (Effort estimation,Schedule,Work allocation and Automation Framework implementation)

Overview:
After selecting some areas for Automation, we have to estimate the efforts    
in terms of time and resources(Environmental and Human)
   
To estimate efforts, we can follow an one of the below given methods:

    a) Using Expert based techniques.
    b)Experienced based techniques.
    c)Function point analysis.
        1) Identifying End to End Scenarios.
        2) Identifying verification points.
        3) Identifying General and Alternate Flows.
        4) Identifying the modularity.
        5) Identifying the complex functionality.

d) Creating Generic and project specific functions.

e) Creating required Automation resources(Functions,Object repository Files,Environment variable files---etc)

f) Creating Tests(Using Object Repository or Descriptive Programming)

g) Enhancing Tests(Inserting Checkpoints,Output Values,Transaction points,Flow Control Statements,Synchronization,Parametrization---etc )

h) Debugging and running tests(Individual test execution,Test Batch execution --etc)

i) Defining and exporting test results

j) Analyzing results

k) Test reporting

l) Defect Reporting using companies defect management system.

m) Modifying tests

n) Performing re and regression testing ---etc

Types Of Automation Framework:

Automation Framework is not a qtp feature, it’s a 3rd party concept. And this is purely local concept.(framework may vary from one company to another)

1. Record/Playback or Linear Framework (1st generation framework).

In this Framework we create tests using recording,low resources maintenance, Form batches and executing tests.

Drawbacks: Modifications and maintenance are difficult,less command on scripts,low performance ---etc
2. Modular Framework.

In this Framework,reusable components can be recognized,first we concentrate on creating reusable components, then creating tests using those components.

Advantages: 

It reduces test Automation time

Performance is high than recording and playback

Drawbacks: 
Less usage of keywords,no concentration on Data driven testing and low performance than latest Frameworks like Keyword Driven Framework.

3. Data Driven Framework

In this Framework,we concentrate more on Data Driven testing.We recognize positive and negative scenarios,then collecting test data and parameterizing.

Advantages: 

We can check reliability of the system,positive and negative testing.

Drawbacks: 

Less concentration on complex Functionality Testing and low keywords usage.
4. Keyword Driven framework

5. Hybrid Framework

In the above frameworks Keyword Driven framework is very famous in the industry.
It is a mixing of more than one approach.

In this approach,we mix Data driven and Modular approaches OR Data Driven and Keyword Driven approaches---etc

Advantages: 

Scope is very high as we mix different approaches,Flexible for performing any tasks.

Drawbacks:

Organizing and managing resources are difficult,complex architecture,low in performance.

NOTE: Now a days Mix of Data driven and Keyword driven approaches is a famous Hybrid Framework in the industry.

Keyword Driven Framework

Keyword:

1. Any word used as the key to a code

2 A reserved word used to identify a specific command, function etc.

(in our test automation example keywords are :

Keywords to be used in Test Automation:

a) Test Objects (EX: Browser,page,webEdit,WinButton---etc)

b) Functions (Built-In and User defined)

c) Methods (Ex:Set,Select,Activate,Navigate---etc)

d) Statements (EX:Dim,If,For---etc)

e) Operators (EX: +,/,*,and,or,not---etc)

Keyword Driven Approach:

In this approach we use keywords for preparing tests. First we create tests and make them as functions, through framework we execute them and generate results.

Key elements of Automation Framework:

1. Well defined folder structure
2. Initialization script
3. Driver script
4. input data spreadsheet
5. process guidelines document

Why folder structure?

In order to create, store, organize and manage files a well defined folder structure required. Folder structure is a mandatory element of any framework, but folder names may vary from one framework to another and company to another .

Folder Structure:

1. Object Repository

2. Environment

3. Library

a) Company

b) Project Specific

4. Test data

5. Test log

6. Recovery scenarios

7. Miscellaneous

And

1. Initialization script (.vbs file)
2. Driver script (QTP Script file)

1) Object Repository: In this folder we store object repository files(.tsr), all team members can use this repositories.

2) Environment: In this folder we store environment variables files(.xml), all team members can use this variables.

3) Function  Library:this folder contains two sub folders one is for storing common functions of our company, another folder for storing our project specific functions(.vbs).

4) Test Data: in this folder we store test data required for data driven testing, for that we use either .xls files or .txt files or .mdb files.

5) Test Log: In this folder we store test result(excel sheet).

6) Recovery scenarios: In this folder we store qtp recovery scenarios files(.qrs).

7) Miscellaneous: in this folder we store the files other than above files(ex-process guideline doc and messages among team members and instructions by team lead etc).

And

1) Initialization script (.vbs file): It launches qtp tool and calls driver script, at end it closes qtp tool.

2) Driver script (QTP Script file): It is only the qtp script, we can associate all resources to this script