Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Showing posts with label Operators in VBScript. Show all posts
Showing posts with label Operators in VBScript. Show all posts

Automating Using QTP Day2 Some VbScripting Techniques

What is VBScript ?Scripting Language.
Programming Language Versus Scripting Language..
Scripting - Something you want to do qckly, smply.. Qck development, limited
features,interpreting, interprtr is limited featured tool.

Programming Lanuage  is used for more cmplx featured devlopment.Compiling
My computer is noot work .. Syntax error,Compilation error,keyword is a syntax.
Compiler goes beyond syntax
My computer are not working. Semantic is wrong, checked by Compiler in addition to the Interpreter
Prototype if used is verified by compiler.





VbScripting In Operating Systems :
Large base of windows system administrator fvrom versn 1 to 2.
Batch files being removed by the vbs code lines.

VbScripting  is a litwt scrptng lang wid a fast intrprtr
Windows Scripting host is reqd for scripting engine job for executng the vbs files.
used both sides client as well as servr
Case sensitv lang
any txt editor
Defat lang being asp for server side
98/2000/xp/linux are OS that it supports
General prps scrpting lang
Dtatatype in Vbscript :
Variant.Var
Based on the contxt of usage it recgnizes the usage, such as concat, add in string addition of int context respctvly.
Declaration is a statement used to declare a variable Dim or dimension.
Dim count.
In C lanuage u need to have the datatype explctly mentnd. but herein its all free.
case insenstv
definition is next to declaration is nothing but assigning sm value
Statemt for declaring :
Dim public Private
Function is the storage limitation.
Variable scope an guidelines
Local  and global procedure oriented based.
begn wid alphabet
no keywrd or resrvd wrd.

No .,!,?
Length max 255
unique
Constatnt :
Which does not change.
Scope : ?

Operators :
Arthmetc, cmparsn, concatnmt,logcl.
Arthmtc: Exp,Unary negation, Multipication, division, Integer division, Modulus Arthmtc, Addition, Subbtratcion String concat&
Logical : not,and,or,xor,eqv,imp
Comparison : =,<>,<,>,<=,>=Is

Terminator character is Carrg return.

sopme very basic codes :

Rem Some sample codes
Const v =34
dim a,b,c
'a=8
'b=7
a=Inputbox("Nter Vales ","Value for a" )
b=Inputbox("Nter Vales ","Value for b" )
a=CInt(a)
b=CInt(b)
c=a+b

msgbox(v)
msgbox ("Sum Value : " & c)
msgbox ("Remainder Value : " & a Mod b)
msgbox ("Subtracted Value : " & a - b)
msgbox ("Multiplied Value : " & vbCRlf & a * b)
msgbox ("division Value : " & formatnumber(a / b,2))
msgbox ("Exponentiation Value : " & vbTab & a ^ b)
msgbox ("Not Value : " & NOT b)
msgbox ("Exponentiation Value : " & (a XOR b))
msgbox ("Logical Or Value : " & (a OR b))
msgbox ("Is Greater Value : " & a>b )
msgbox ("Is Less  Value : " & a
msgbox ("Is Value : " & IsNull(a))

e="viplav"
d="anand"
msgbox ("Conactentated Values : " & e+" "+d)
msgbox ("implication : "& (a imp b)) ' value will be -9


'Array Handling in VBSCript

dim arr(2,2)
arr(0,0)=203936
arr(0,1)="Viplav"
arr(1,0)=165451
arr(1,1)="Jan"
arr(2,0)=177826
arr(2,1)="Asw"

dim i
for i=0 to 2
 for j=0 to 1
msgbox (arr(i,j))
 next
next


Binary Operators most of the Arithmetic opertaors, except negation opertaor whihc is a unary opertaor
Precedence :
not and or,xor,eqv,imp

VbCrlf : Carriage return And Line Feed intrinsic constants,
Vbtab  : Tab
vbOK   : 


Conditional Looping :
IF Then Else
Select case
 
These statmnts are used for logical comparison.

WAP to find greatest among three numbers using the If Then Else
WAP to find greatest among four numbers using the If Then Else

For each IF Then there must be one End If to indicate end of the block of IF

WAP to Automate the Calculations for numbers using the Conmditionla Looping Control.


' Select case feature
Select case (i)
case 1:
Msgbox( )
case 2:
Msgbox( )
case else:
Msgbox( )
End select


Loops In Array data Accessing..

For ... Next While .... Wend Do While.... loop For Each... Next

Exit While , Exit For is used to exit the loop

CDate Function in QTP

What is CDate Function :
Returns an expression that has been converted to a Variant of subtype Date.
CDate(date)
The date argument is any valid date expression.

Remarks

Use the IsDate function to determine if date can be converted to a date or time. CDate recognizes date literals and time literals as well as some numbers that fall within the range of acceptable dates. When converting a number to a date, the whole number portion is converted to a date. Any fractional part of the number is converted to a time of day, starting at midnight.
CDate recognizes date formats according to the locale setting of your system. The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings. In addition, a long date format is not recognized if it also contains the day-of-the-week string.
The following example uses the CDate function to convert a string to a date. In general, hard coding dates and times as strings (as shown in this example) is not recommended. Use date and time literals (such as #10/19/1962#, #4:45:23 PM#) instead.
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.
 
Some more relevant posts covering the VBScript functions and other Vbscript used for coding in QTP.:



 

VBScript in QTP

When working in the Expert View, you should bear in mind the following general VBScript syntax rules and guidelines:

  • Case-sensitivity—By default, VBScript is not case sensitive and does not differentiate between upper-case and lower-case spelling of words, for example, in variables, object and method names, or constants.
  • For example, the two statements below are identical in VBScript:
    Browser("creationtime:=0").Page("micclass:=page").WebList("toDay").Select "31"
    Browser("creationtime:=0").Page("micclass:=page").weblist("today").select "31"

  • Text strings—When you enter a value as a text string, you must add quotation marks before and after the string. For example, in the above segment of script, the names of the Web site, Web page, and edit box are all text strings surrounded by quotation marks. Note that the value 31 is also surrounded by quotation marks, because it is a text string that represents a number and not a numeric value.
  • In the following example, only the property name (first argument) is a text string and is in quotation marks. The second argument (the value of the property) is a variable and therefore does not have quotation marks. The third argument (specifying the timeout) is a numeric value, which also does not need quotation marks.
    Browser("creationtime:=0").Page("micclass:=page").WaitProperty("items count", Total_Items, 20)

  • Variables—You can specify variables to store strings, integers, arrays and objects. Using variables helps to make your script more readable and flexible. For more information, see Using Variables.

  • Parentheses—To achieve the desired result and to avoid errors, it is important that you use parentheses () correctly in your statements. For more information, see Using Parentheses.

  • Comments—You can add comments to your statements using an apostrophe ('), either at the beginning of a separate line, or at the end of a statement. It is recommended that you add comments wherever possible, to make your scripts easier to understand and maintain.

  • Spaces—You can add extra blank spaces to your script to improve clarity. These spaces are ignored by VBScript.

Scripts Classification in QTP

QTP Scripting : There are various types of scripting mechanism available in Vbscript for coding in QTP . Generally they are mostly COM based objects on which they can be applied.


File System Scripts


Flat File Scripts


Database Scripts-I


Database Scripts-II


Excel Scripts


GUI Scripts


Web Scripts


Web Scripts -II


QTP Real-time Script Examples


Network Administration


System Administration


Power point Scripts


Word Scripts


XML Scripts


QTP Skills


Error Handling in QTP