Monday, 10 March 2014

QTP Data Types

Declarations: Dim  City, intNum, myDate, objexcel City = "Visakhapatnam" intNum=100 myDate=#15/11/2012# Set  objExcel = CreateObje... thumbnail 1 summary
Declarations:

Dim  City, intNum, myDate, objexcel

City = "Visakhapatnam"

intNum=100
myDate=#15/11/2012#


Set  objExcel = CreateObject("Excel.Application")

Set mypage = Browser("Google").Page("Google")


'************************************************************************************************
Data Types
-----------
'Checking Data Sub Types using VarType Function
Dim x

Msgbox VarType(x) '0 for Uninitialized / empty

x="Input"
Msgbox VarType(x) '8 for String

x=100
Msgbox VarType(x) '2 for Integer

x=100.45
Msgbox VarType(x) '5 for double

x=#10/10/201#
Msgbox VarType(x) '7 for date

Set x= CreateObject("Scripting.FileSystemObject")

Msgbox VarType(x) '9 for Automation Object

x="100"
Msgbox VarType(x) '8 for String
------------------------------------------------------------------------------------------------------
'Converting the Data using Conversion functions

'Reading from Input devices
Dim val, Tickets
val=InputBox ("Enter a Value")
Msgbox VarType(val) '8 for string


 Variant
           Sub Datatypes
           Typename and vartype funtions
                  Data Conversion Functions



val= Cint (val) 
Msgbox VarType(val) '2 for Integer

'Reading from Application Objects

Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetVisibleText()
Msgbox VarType(Tickets) '8 for String

Tickets=Cint (Tickets)
Msgbox VarType(Tickets) '2 for Integer
---------------------------------------------------------------------------------------------------------
'Converting the Data using Conversion functions

'Reading from Input devices
Dim val, Total
val=InputBox ("Enter a Value")
Msgbox VarType(val) '8 for string

val= Cdbl (val) 
Msgbox VarType(val) '5 for Double

'Reading from Application Objects

Total = Window("Flight Reservation").WinEdit("Total:").GetROProperty("text")
Msgbox VarType(Total) '8 for String

Total=Cdbl (Total)
Msgbox VarType(Total) '5 for Double


Constatns
          Operators:
                 Assignment Operators
                 Logical Operators
                 Concatination Operators
                 Relational Operators



Variables
---------------

'Implicit and Explicit Declaration of Variables
Dim num1, sum
num1=100 'Explicit Variable
num2=200 'Implicit
sum=num1 + num2
Msgbox sum

-----------------------------------------------------------
Option Explicit 
Dim Tickets, Price, Total
Tickets=5
Price=120
Total= Tickets * Priee
Msgbox Total
------------------------------------------------------------------------------------------------
Dim x, a, b
'Holding the Data
x=100 

'Stroring the Value that returned by a Program
a=10 : b=20
x=(a+b)^ 2
Msgbox x


'Stroring the Value that returned by a Function
x=Date 'Built-in Function
msgbox x

x=Login("abcd","mercury") 'User defined function

'Storing object Reference
Set x = CreateObject("Scripting.FileSystemObject")
------------------------------------------------------------------------------------------
'Assigning Values to Variables
Dim a, b, c
a=100 'Initialization
b=Inputbox("Enter b Value") 'Reading
c=a+b
Msgbox c
---------------------------------------------------------------------------------------------
Naming Restrictions
------------------------
'Should start with Alfabytes

Dim abc
Dim ab9
Dim 7a 'Incorrect

'Should not contain embeded periods
Dim abc
Dim ab c 'InCorrect
Dim ab.c 'InCorrect
Dim ab-c 'InCorrect
Dim ab*c 'InCorrect
Dim ab_c 

'Must not exceed 255 Char

'Should be unique in the scope of declaration

Dim a, b, c
Dim d, e, f
Dim g, h, A


---------------------------------------------------------------------------------------
'Scope of Variables

1) Program / Script Level variables

2) Function / Procedure Level variables

Ex:
Dim a, b, c 'Script Level
a=10
b=20
c=a+b
Msgbox c '30
Function xyz()
   Dim d, e 'Function Level
   d=40
   e=b+d
   Msgbox e '60
End Function
Call xyz()
Dim f, g 'Script Level
f=70
g=a+d+f 
msgbox g '80
--------------------------------------------------------------------------------------------------
'Types of variables

1) Scalar Variables 

2) Array Variables 
-------------------------------
Dim a, b(3)
b(0)=10
b(1)="India"
b(2)=100.345
b(3)=#10/10/2011#

--------------------------------------
Dim a, b(3)
b(0)=10
b(1)="India"
b(2)=100.345
b(3)=#10/10/2011#
b(4) =100 'Error
---------------------------------------------------------------------------
'Dynamic Arrays

Dim a, b(3), c()
ReDim c(3)
c(0)=10
c(1)=20
c(2)=30
c(3)=40
a=c(1)+c(3)
Msgbox a '60

ReDim c(5)
c(4)=50
c(5)=60
a=c(2)+c(4)
Msgbox a '50


----------------------------------------
Preserve keyword

Dim a, b(3), c()
ReDim c(3)
c(0)=10
c(1)=20
c(2)=30
c(3)=40
a=c(1)+c(3)
Msgbox a '60

ReDim Preserve c(5)
c(4)=50
c(5)=60
a=c(2)+c(4)
Msgbox a '80
------------------------------------------------------------------------------------------
Dim a, b(3), c(), d(4,5)
d(0,0)="QTP"
------------------------------------------------------------------------------------------
Assigning Series of values at a time
----------------------------------------

a) Using Array Function
Dim a
Msgbox IsArray(a) 'False
a=Array("India", 100, 100.123, #10/10/10#)
Msgbox IsArray(a) 'True

msgbox a(1) '100

b) Using Split Function
Dim a, b
a="VB@Script@Language"
Msgbox IsArray(b) 'False
b=Split(a,"@")
Msgbox IsArray(b) 'True

msgbox b(1) 'Script
-----------------------------------------------------------
Dim a, b
a="VB Script Language"
Msgbox IsArray(b) 'False
b=Split(a)
Msgbox IsArray(b) 'True

msgbox b(1) 'Script
 -----------------------------------------------------------------------------------------------------------------


Operators
-------------
Dim a, b, c
a=10
b=3

c= a ^ b
Msgbox c '1000

c= a * b
Msgbox c '30

c= a / b
Msgbox c '3.333333333333

c= a \ b
Msgbox c '3

c= a Mod b
Msgbox c '1

c= a - b
Msgbox c '7
--------------------------------------------
+ Operator

Dim a, b, c
a=10
b=3
c= a + b
Msgbox c '13

a="10"
b=3
c= a + b
Msgbox c '13

a="10"
b="3"
c= a + b
Msgbox c '103

a="Hyd"
b="3"
c= a + b
Msgbox c 'Hyd3

a="Hyd"
b="bad"
c= a + b
Msgbox c 'hydbad

a="Hyd"
b=3
c= a + b
Msgbox c 'Error

--------------------------------------------------
Concatanation Operator &
---------------------------------------------------

Dim a, b, c
a=10
b=3
c= a & b
Msgbox c '103

a="10"
b=3
c= a & b
Msgbox c '103

a="10"
b="3"
c= a & b
Msgbox c '103

a="Hyd"
b="3"
c= a & b
Msgbox c 'Hyd3

a="Hyd"
b="bad"
c= a & b
Msgbox c 'hydbad

a="Hyd"
b=3
c= a & b
Msgbox c 'Hyd3
-----------------------------------------------------------------------------------
Comparision Operators
-------------------------------------------------------------------------------
Dim a, b, c
a=10
b=3
c= a = b
Msgbox c 'False

c= a > b
Msgbox c 'True

c= a >= b
Msgbox c 'True

c= a <> b
Msgbox c 'True

c= a < b
Msgbox c 'False

c= a <= b
Msgbox c 'False
---------------------------------------------------------------------------------------------------
Logical Operators
------------------------------------------------------------------------------------

Not operator
------------------

If Not Dialog("Login").Exist(3) Then
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
End If
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "4ecb04ac4d43cadfb04bbd2a3b83f3df8e55b73c"
Dialog("Login").WinButton("OK").Click

And Operator
--------------

Dim a, b, c
a=10
b=3
c= 20

If c>a And c>b Then
Msgbox "C is a Big Number"
Else
    Msgbox "C is Not a Big Number"
End If
-------------------------------------
Result criteria
------------------

Exp1 Exp2 Result
-------------------------------------
True True True
True False false
False True False
False False False

Or Operator
------------------
Exp1 Exp2 Result
-------------------------------------
True True True
True False True
False True True
False False False

Xor Operator
------------------
Exp1 Exp2 Result
-------------------------------------
True True False
True False True
False True True
False False False
------------------------------------------------------------------------------------------------------------------------





No comments

Post a Comment