VB Script Pocedures

May 13, 2018 | Author: G.C.Reddy | Category: Computer File, Microsoft Excel, Scripting Language, Databases, Login
Share Embed Donate


Short Description

VB Script Procedures/Functions; String functions, Array functions, Date & Time Functions and Math Functions....

Description

Visit:

www.gcreddy.com for QTP Examples

-------------------------------------------------------------

VB Script Procedures/Functions ---------------------------------------------------------------Sub Login(Agent, Password) SystemUtil.Run "C:\Program Files\HP\QuickTest Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Progr Professional\samples\f light\app\flight4a.exe","","C:\Program am Files\HP\QuickTest Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set Agent Dialog("Login").WinEdit("Password:").Set Dialog("Login").WinEdit("Passw ord:").Set Password wait 1 Dialog("Login").WinButton("OK").Click If Window("Flight Reservation").Exist(10) Then Msgbox "Login Operation Sucessful" Else SystemUtil.CloseDescendentProcesses Msgbox "Login Failed" End If  End Sub Call Login("acd","mercur Login("acd","mercury") y") ----------------------------Function Login(Agent, Password) SystemUtil.Run "C:\Program Files\HP\QuickTest Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Progr Professional\samples\f light\app\flight4a.exe","","C:\Program am Files\HP\QuickTest Files\HP\QuickTest Professional\samples\flight\app\","open" Dialog("Login").Activate Dialog("Login").WinEdit("Agent Name:").Set Agent Dialog("Login").WinEdit("Password:").Set Dialog("Login").WinEdit("Passw ord:").Set Password wait 1 Dialog("Login").WinButton("OK").Click If Window("Flight Reservation").Exist(10) Then Window("Flight Reservation").Close Reservation").Close Login= "Login Operation Sucessful" Msgbox Login Else SystemUtil.CloseDescendentProcesses Login= "Login Failed" Msgbox Login End If  End Function Call Login("accd","mercury") Login("accd","mercury") ----------------------------------'Write a Function to Count all Opened Browsers on desktop and close them all Function Close_Browsers() Close_Browsers() Dim oBrowser, Browsers, TotBrowsers

1

Visit:

www.gcreddy.com for QTP Examples

Set oBrowser=Description.Create oBrowser=Description.Create oBrowser("micclass").value="Browser" Set Browsers=Desktop.ChildObjects(oBrows Browsers=Desktop.ChildObjects(oBrowser) er) TotBrowsers=Browsers.count For i= 0 to TotBrowsers-1 Step 1 Browsers(i).close Next End Function Call Close_Browsers() Close_Browsers() -----------------------------------------------------'Write a Function to Count Links in any opened webpage Function Count_Links() Dim oLink, Links, TotLinks Set oLink=Description. oL ink=Description.Create Create oLink("micclass").value="Link" Set Links=Browser("title:=.*").Page("title:=.*").C Links=Browser("title:=.*").Page("title:=.*").ChildObjects(oLink) hildObjects(oLink) TotLinks=Links.count Next End Function Call Count_Links() ----------------------------------------Function Count_Buttons() Dim oButton, Buttons,TotButtons, i, myButton Set oButton=Description. oButton=Description.Create Create oButton("Class Name").Value="WinButton" Set Buttons=Dialog("text:=Login Buttons=Dialog("text:=Login").ChildObjects(oButton) ").ChildObjects(oButton) TotButtons=Buttons.count Msgbox TotButtons For i= 0 to TotButtons-1 myButton=Buttons(i).Getroproperty("text") Msgbox myButton Next End Function Call Count_Buttons() -----------------------------Function Count_Objects(object) Count_Objects(object) Dim oobject, objects,Totobjects Set oobject=Description. oobject=Description.Create Create oobject("Class Name").Value=object Set objects=Window("text:=Flight objects=Window("text:=Flight Reservation").ChildObjects( Reservation").ChildObjects(oobject) oobject) Totobjects=objects.count Msgbox Totobjects End Function Call Count_objects("WinButton") Count_objects("WinButton") Call Count_objects("WinEdit") Count_objects("WinEdit") Call Count_objects("WinRadioButton") Count_objects("WinRadioButton") Call Count_objects("WinComboBox") Count_objects("WinComboBox") -----------------------------------------------------------------

2

Visit:

www.gcreddy.com for QTP Examples

Function Launch_App() SystemUtil.Run "C:\Program Files\Internet Explorer\IEXPLORE.EXE","www.jjperfumes.com" Wait (8) Browser_Name = Browser("JJ Perfumes-Discount Perfumes-Discount perfume").GetROProperty( perfume").GetROProperty("title") "title") If Browser_Name= "JJ Perfumes-Discount Perfumes-Discount perfume cheap cheap brand name perfumes, perfumes, fragrance & cologne online" Then Launch_App="Application Launched Sucessfully" Msgbox Launch_App Else Launch_App="Application Not Launched" Msgbox Launch_App End If  End Function ------------------------------Function Registration(Email) Set myBrowser=Browser("JJ myBrowser=Browser("JJ Perfumes-Discount perfume").Page("JJ PerfumesDiscount perfume_2") Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount Perfumes-Discount perfume").Link("Register").Click myBrowser.WebList("usertype").Select myBrowser.WebList("u sertype").Select "Retailer" myBrowser.WebEdit("firstname").Set myBrowser.WebEdit( "firstname").Set "utyyruy" myBrowser.WebEdit("lastname").Set myBrowser.WebEdit( "lastname").Set "uyuu" myBrowser.WebList("gender").Select myBrowser.WebList("g ender").Select "Male" myBrowser.WebEdit("address1").Set myBrowser.WebEdit( "address1").Set "uyuytutuu" myBrowser.WebEdit("phone").Set myBrowser.WebEdit( "phone").Set "9222222223" myBrowser.WebEdit("email").Set myBrowser.WebEdit( "email").Set Email myBrowser.WebEdit("city").Set myBrowser.WebEdit( "city").Set "hyderabad" myBrowser.WebList("state").Select myBrowser.WebList("s tate").Select "MO - MISSOURI" myBrowser.WebList("state").Select myBrowser.WebList("s tate").Select "MT - MONTANA" myBrowser.WebEdit("zip").Set myBrowser.WebEdit( "zip").Set "34567" myBrowser.WebEdit("password").SetSecure "3c30b5521a58241cf85aea528e1f4148a78f" myBrowser.WebEdit("conPass").SetSecure "3c30b557ccf6dbd1b0951c84b2fefb951f55" myBrowser.WebButton("Submit").Click Confirm_Message = Browser("JJ Perfumes-Discount Perfumes-Discount perfume").Page("JJ PerfumesDiscount perfume_3").WebElement( perfume_3").WebElement("Registered "Registered successfully.").GetROProperty("innertext") If Confirm_Message="Registered Confirm_Message="Registered successfully. " Then Registration="Customer Registerd Sucessfully" Msgbox Registration Else Registration="Registration Failed" Msgbox Registration End If  End Function -------------------------------Function Login(Email, Password) Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount Perfumes-Discount perfume_3").Link("Login").Click

3

Visit:

www.gcreddy.com for QTP Examples

Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount Perfumes-Discount perfume_3").WebEdit("username").Set perfume_3").WebEdit("us ername").Set Email Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount Perfumes-Discount perfume_3").WebEdit("password").SetSecure perfume_3").WebEdit("passw ord").SetSecure Password Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount Perfumes-Discount perfume_3").WebButton("Login").Click If Browser("JJ Perfumes-Discount perfume").Page("JJ Perfumes-Discount perfume_4").Link("Logout").Exist(5) perfume_4").Link("Logout ").Exist(5) Then Login="Login Operation Sucessful" Msgbox Login Else Login="Login Operation Failed" Msgbox Login End If  End Function -----------------------------------------------------

Built in Functions ------------------1) Asc Function Dim val val="Hyderabad" Msgbox Asc(val) '72 Msgbox Msgbox Msgbox Msgbox Msgbox Msgbox

Asc("A") '65 Asc("Z") '90 Asc("a") '97 Asc("z") '122 Asc(1) '49 Asc("*") '42

2) Chr Function Dim val val=72 Msgbox Chr(val) 'H Msgbox Msgbox Msgbox Msgbox Msgbox Msgbox

Chr(65) 'A Chr(90) 'Z Chr(97) 'a Chr(122) 'z Chr(49) '49 Chr (42) '*

3) Abs Function Dim val val=100.49 Msgbox Abs(val)' 100.49 val=100.59 Msgbox Abs(val) '100.59 val=-100.49

4

Visit:

www.gcreddy.com for QTP Examples

Msgbox Abs(val) '100.49 4) Round Function Dim val val=100.49 Msgbox Round(val)' 100 val=100.59 Msgbox Round(val) '101 val=-100.49 Msgbox Round(val) '-100 val=-100.59 Msgbox Round(val) '-101 val=100.5 Msgbox Round(val) '100 5) IsArray Dim a, b(3), c(), d(4,5) Msgbox IsArray(a) 'False Msgbox IsArray(b) 'True Msgbox IsArray(c) 'True Msgbox IsArray(d) 'True 6) IsNumeric Dim val val=100 Msgbox IsNumeric(val) val=100.456 Msgbox IsNumeric(val) val="abcd" Msgbox IsNumeric(val) val="100" Msgbox IsNumeric(val)

'True 'True 'False 'True

val=#10/10/10# Msgbox IsNumeric(val) 'False 7) IsDate Dim val val=#10-10-10# Msgbox IsDate(val) 'True val=#10-10-2010# Msgbox IsDate(val) 'True val=#10/10/2010# Msgbox IsDate(val) 'True val=#20/10/2010#

5

Visit:

www.gcreddy.com for QTP Examples

Msgbox IsDate(val) 'True 'val=#20/20/10# 'Msgbox IsDate(val) 'Error val=#10/40/10# Msgbox IsDate(val) 'Error val=#Sep/20/10# Msgbox IsDate(val) 'True val=100 Msgbox IsDate(val) 'False val="asdd" Msgbox IsDate(val) 'False 8) IsEmpty Dim x,y x=100 Msgbox IsEmpty(x) 'False Msgbox IsEmpty(y) 'True y="abcd" Msgbox IsEmpty(y) 'False y=0 Msgbox IsEmpty(y) 'False y=Empty Msgbox IsEmpty(y) 'True 9) Array Dim x,y Msgbox IsArray(x) 'False x=Array("abcd",100, #10-10-10#) Msgbox IsArray(x) 'True Msgbox x(1) '100 10) Split Dim x,y x="VB Script Language" Msgbox IsArray(y) 'False y=Split(x," ") Msgbox IsArray(y) 'True Msgbox y(1) 'Script 11) DateDiff 

6

Visit:

www.gcreddy.com for QTP Examples

Dim Date1, Date2 Date1=#10-10-09# Date2=#10-10-07# Msgbox DateDiff("d",Date1,Date2)

Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("d",Date1,Date2) &" Days" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("m",Date1,Date2) &" Months" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("y",Date1,Date2) &" Days" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("yyyy",Date1,Date2) &" Years" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("w",Date1,Date2) &" Weeks" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("q",Date1,Date2) &" Quarters" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("h",Date1,Date2) &" Hours" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("n",Date1,Date2) &" Minutes" Date1=#10-10-09# Date2=#10-10-11# Msgbox DateDiff("s",Date1,Date2) &" Seconds" 12) Len Function Dim val val="Hyderabad" Msgbox Len(val) '9 Msgbox Len ("asd1234") '7 Msgbox Len (1000) '4 Msgbox Len (#10-10-10#) '10

7

Visit:

www.gcreddy.com for QTP Examples

Msgbox Len ("#10-10-10#") '10 Msgbox Len (#Sep-10-10#) '9 Msgbox Len (#Dec-10-10#) '10 13) Left Function Dim val val="Hyderabad" Msgbox Left(val,3) 'Hyd Msgbox Left(9247892478,1) '9 Msgbox Left("%*&y",2) '%* 14) Right Function Dim val val="Hyderabad" Msgbox Right(val,3) 'bad Msgbox Right(9247892478,1) '8 Msgbox Right("%*&y",2) '&y 15) Mid Function Dim val val="Hyderabad" Msgbox Mid(val,3) 'bad Msgbox Mid(9247892478,5,2) '89 Msgbox Mid("%*&y",2) '*&y Msgbox Mid(#10-10-10#,4,5) '10/20 -------------------------Dim x x="Hyderabad" Msgbox Left(x,3) 'Hyd Msgbox Mid(x,1,3) 'Hyd Msgbox Right (x,3) 'bad Msgbox Mid (x,7) Msgbox Mid(x,5,3) 'rab --------------------------16) StrComp Function Result Criteria: -----------------

8

Visit:

www.gcreddy.com for QTP Examples

a) If st1>str2 then it returns 1 a) If st1
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF