Thursday, 15 December 2011

Open an Excel Spreadsheet

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\gcreddy.xls")

Compare two excel files

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
Set objWorkbook1= objExcel.Workbooks.Open("E:\gcreddy1.xls")
Set objWorkbook2= objExcel.Workbooks.Open("E:\gcreddy2.xls")
Set objWorksheet1= objWorkbook1.Worksheets(1)
Set objWorksheet2= objWorkbook2.Worksheets(1)
For Each cell In objWorksheet1.UsedRange
If cell.Value <> objWorksheet2.Range(cell.Address).Value Then
msgbox "value is different"
Else
msgbox "value is same"
End If
Next
objWorkbook1.close
objWorkbook2.close
objExcel.quit
set objExcel=nothing

Data Driven Testing through an External Excel Sheet


1) Set myExcel=Createobject("Excel.Application")
2) Set myFile=myExcel.workbooks.open ("C:\Documents and Settings\admin\My Documents\gcreddy.xls")
3) Set mySheet=myFile.worksheets("Sheet1")
4) Rows_Count=mySheet.usedrange.rows.count
5) For i= 1 to Rows_Count
6) Agent=mySheet.cells(i,"A")
7) pwd=mySheet.Cells(i,"B")
8) SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
9) Dialog("Login").Activate
10) Dialog("Login").WinEdit("Agent Name:").Set Agent
11) Dialog("Login").WinEdit("Password:").SetSecure pwd
12) Dialog("Login").WinEdit("Password:").Type micReturn
13) Window("Flight Reservation").Close
14) Next

Check if the Excel file exists or not, if exists open the file and enter some data , If not Exists create the file and enter some data and save the file through VB script?

Dim objExcel, FilePath
FilePath="C:\Documents and Settings\gcr.GCRC-9A12FBD3D9\Desktop\gcr.xls"
Set objExcel=CreateObject("Excel.Application")
set objFso=CreateObject("Scripting.FileSystemObject")
objExcel.Visible=True

If Not objFso.FileExists(FilePath)  Then
objExcel.Workbooks.Add
objExcel.Cells(1,1).value="QTP"
objExcel.ActiveWorkbook.SaveAs (FilePath)

Else
set myFile= objExcel.Workbooks.Open (FilePath)
Set mySheet=myFile.Worksheets("Sheet1")
mySheet.cells(1,1).value="QTP"
objExcel.ActiveWorkbook.Save
End If
objExcel.Quit
Set objExcel=Nothing

Create an Excel file, enter some data and save the file through VB script?


1) Dim objexcel
2) Set objExcel = createobject("Excel.application")
3) objexcel.Visible = True
4) objexcel.Workbooks.add
5) objexcel.Cells(1, 1).Value = "Testing"
6) objexcel.ActiveWorkbook.SaveAs("f:\exceltest.xls")
7) objexcel.Quit

Tuesday, 2 August 2011

iteration on flight reservation


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").WinEdit("Agent Name:").Set datatable("uid",1)
Dialog("Login").WinEdit("Password:").Set datatable("pswd",1)
Dialog("Login").WinButton("OK").Click


If dialog("Login").dialog("text:=Flight Reservations").Exist Then
dialog("Login").dialog("text:=Flight Reservations").winbutton("text:=OK").Click
Dialog("Login").WinButton("Cancel").Click

else

    window("Flight Reservation").WinButton("window id:=2").Click
    Window("Flight Reservation").ActiveX("MaskEdBox").Type "121212"
Window("Flight Reservation").WinComboBox("Fly From:").Select "London"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Paris"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select "1"
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Tickets:").SetSelection 0,1
Window("Flight Reservation").WinEdit("Tickets:").Set "5"
Window("Flight Reservation").WinEdit("Name:").Set "wewe"
Window("Flight Reservation").WinRadioButton("First").Set
Window("Flight Reservation").WinButton("Insert Order").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
 
End If

Wednesday, 20 July 2011

Validation on aCharacter

Dim nChar,s
     s=inputbox("input name")
          nChar = Asc(s)
  
    If nChar >= 65 And nChar <= 90 Then
          msgbox "The first character is UPPERCASE"
    ElseIf nChar >= 97 And nChar <= 122 Then
          msgbox "The first character is lowercase"
         Else
          msgbox "The first character isn't alphabetical"
    End If



OUTPUT:-

The following example uses the InputBox function to display an input box and


Option Explicit
Dim
sPrompt, sTitle, sHelpFile, sRes
Dim
vDef
Dim
sPrompt =
vDef = "
nXPos =
nYPos, nXPos, nContext"Where do you live?" : sTitle = "Personal Data"Israel"100 : nYPos = 100 : nContext = 1001
sHelpFile = "
sRes =
C:\WINDOWS\system32\winhelp.hlp"InputBox(sPrompt, sTitle, vDef, nXPos, nYPos, sHelpFile, nContext)

Sunday, 17 July 2011

How to change character's into ASCII number's

sChars = inputbox("Character")   'enter character
MsgBox Asc(sChars)                  'converstion into no.

Validation Script on characte

=========================================================
Dim sChars
Dim nCharCode
sChars = "QuickTest Professional"
If Len(sChars) > 0 Then
nCharCode = Asc(sChars)
If nCharCode >= 97 And nCharCode <= 122 Then
MsgBox "The first character must be uppercase"
Else
MsgBox nCharCode
End If
End If

===================================================================

Tuesday, 12 July 2011

Simlple Validation on Flight Reservation system.

http://www.nitesh10.blogspot.com



'Leave Username and password field blanck

'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").Type micTab
Dialog("Login").WinButton("OK").Click
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click

'Again leaves Username field blank

'----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure "4ab7a2d45ab7f90a0279430e6836a126be044819"
Dialog("Login").WinButton("OK").Click
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click

'Enters valid Username
'-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dialog("Login").WinEdit("Agent Name:").Set "xyz"

'Again enters invalid Password and then Valid password
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dialog("Login").WinEdit("Password:").SetSecure "4ab7a30e3dbc0045618cadbeddd91a436bba513d3632"
Dialog("Login").WinButton("OK").Click
Dialog("Login").Dialog("Flight Reservations").WinButton("OK").Click
Dialog("Login").WinEdit("Password:").SetSecure "4ab7a3162eda9514506206d258cec02e4e57fb1f"
Dialog("Login").WinButton("OK").Click



http://www.nitesh10.blogspot.com

Tuesday, 5 July 2011

static script for flight reservation system


systemutil.Run "iexplore.exe","www.gmail.com"
browser("name:=Gmail: Email from Google").page("title:= Gmail: Email from Google").webedit("name:=email").Set "abcdefgh"
browser("name:=Gmail: Email from Google").page("title:= Gmail: Email from Google").webedit("name:=Passwd").Setsecure "dsdo947u5juo4u85i459859jkuoit9rr5465ret3s"
browser("name:=Gmail: Email from Google").page("title:= Gmail: Email from Google").webbutton("name:=Sign in").click
browser("name:=Gmail - Inbox").page("title:=Gmail - Inbox").link("name:=Compose Mail").click
browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webedit("name:=to").set "
xyz@gmail.com"
browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webedit("name:=bcc").set "
abc@gmail.com"
browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webedit("name:=subject").set "gmail assignment...,"
browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webedit("name:=body").set "good morning sir..."
browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webbutton("abs_x:=139","abs_y:=251").Click
'browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webbutton("name:=Save Draft","index:=0").Click
'browser("name:=Gmail - Compose Mail").page("title:=Gmail - Compose Mail").webbutton("name:=Save Draft","index:=0").Click


browser("name:=Gmail - Inbox").page("title:=Gmail - Inbox").link("text:=Sign out").click








Monday, 4 July 2011

Script for validation on flight reservation system


                                                                     
                                                                     
                                                                     
                                             
invokeapplication"C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe"      'path of the the application flight Reservation
Dim ag_enb
ag_enb = Dialog("text:=Login").WinEdit("attached text:= Agent Name:").CheckProperty("enabled",1)     'for checking the state of the agent name edit box
If ag_enb=true Then
       Dim agname,agval
agname=inputbox("Enter the Agent Name:")
agval =aagvalid(agname)
If agval =1 Then
Dialog("text:=Login").WinEdit("attached text:=Agent Name:").Set agname
               else
msgbox "invalid"
            End If
            Dialog("text:=Login").WinEdit("attached text:=Password:").Set "mercury"
            Dialog("text:=Login").WinButton("text:=OK").Click
       else
            msgbox " Not Enabled"
End If


Dim res_date,dvalid
res_date =inputbox("Please Enter the date in mm/dd/yy Fromat")
dvalid = datevalid(res_date)
      If dvalid =1 Then
           Window("text:=Flight Reservation").ActiveX("acx_name:=MaskEdBox").Type res_date
        else
            msgbox "invalid"
      End if


Call locvalid()


Window("text:=Flight Reservation").WinButton("text:= FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinList("From").Select 0
Window("text:=Flight Reservation").Dialog("text:=Flights Table").WinButton("text:=OK").Click


msgbox "You have to enter name before pressing the Insert Order button. "


Dim cusname,cusval
cusname=inputbox("Please Enter the Customer name")
cusval =cusvalid(cusname)


Call enab


If i= Window("Flight Reservation").WinRadioButton("Economy").Set Then
msgbox ("The Economy class Price is:-"& window("Flight Reservation").winedit("Price:").GetVisibleText())
End If
If i= Window("Flight Reservation").WinRadioButton("Business").Set Then
msgbox ("The Business class Price is:-"& window("Flight Reservation").winedit("Price:").GetVisibleText())
End If
If i= Window("Flight Reservation").WinRadioButton("First").Set Then
msgbox ("The First class Price is:-"& window("Flight Reservation").winedit("Price:").GetVisibleText())
End If


Call prcomp


Dim tickno,tickval
tickno=inputbox("Please Enter the Ticket number:")
tickval = tickvalid(tickno)


Window("Flight Reservation").WinRadioButton("Economy").Set


Window("Flight Reservation").WinButton("Insert Order").Click
wait 5


Call update


wait 8


Dim inorder
Window("text:=Flight Reservation").WinMenu("menuobjtype:=2").Select "File;Open Order..."
Window("text:=Flight Reservation").Dialog("text:=Open Order").WinCheckBox("text:=&Order No.").Set "ON"
inordr = inputbox("Please Enter the order number:")
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit_2").set inordr
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click


'Call delorder


'========================function==============================================


'===================validation function for agent name=========================
Function aagvalid(agname)
Dim aglen
aglen = len(agname)
If aglen>=4 and aglen<=10 Then
aagvalid =1
else
aagvalid=0
End If
End Function


'=========validation function for Flight reservation date=================


Function  datevalid(res_date)
Dim date1,mydate,lastdate
date1 =Cdate(res_date)
mydate = Date
lastdate = Dateadd("yyyy",28,date)
If  date1>=mydate and date1<=lastdate Then
datevalid =1
        else
datevalid =0
End If
End Function


'=========validation function for the location=================


Function locvalid()
Dim loc,loc1,loc2
loc1=inputbox("Please Enter the Fly From Location from-0-Denver,1-Frankfurt,2-London,3-Los Angeles,4-Paris,5-Portland,6-San Francisco,7-Seattle,8-Sydney,9-Zurich")
For loc1= 0 to loc1-1
Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").Getitem(loc1)
Next
loc2=inputbox("Please Enter the Fly From Location from-0-Denver,1-Frankfurt,2-London,3-Los Angeles,4-Paris,5-Portland,6-San Francisco,7-Seattle,8-Sydney,9-Zurich")
For loc2=0 to loc2-1
Window("text:=Flight Reservation").WinComboBox("attached text:=Fly From:").Getitem(loc2)
Next
       loc = strcomp (loc1,loc2)
       If loc=0 Then
msgbox "You have enter the same location"
       else
Window("text:=Flight Reservation").WinComboBox("attached text:= Fly From:").Select loc1
Window("text:=Flight Reservation").WinComboBox("attached text:= Fly To:").Select  loc2
       End If
End Function


'=========function for enabling the insert order button=================


Function enab()
Dim i
i = Window("text:=Flight Reservation").WinEdit("attached text:=Name:").CheckProperty("enabled",1)
        If i=true Then
msgbox "Not Enabled"
        else
msgbox "Now you can enter in Insert Order button because you have entered the name"
End If
End Function


'=========validation function for customer name==============================


Function cusvalid(cusname)
Dim cuslen,j,k
cuslen = len(cusname)
If cuslen<=20 Then
window("Flight Reservation").winedit("Name:").Set cusname
else
Do While cuslen>20
msgbox "Sorry you can't enter more then 20 character in customer name."
j=inputbox ("Please Enter the customer name below or equal to 20 characters:")
k=len(j)
If k<=20 Then  window("Flight Reservation").winedit("Name:").Set j
Exit do
loop
End If
End Function


'=========function for price calculation of Tickets=================


Function prcal(tickno)
Dim tkprc,tkprc1,total1
tkprc=window("Flight Reservation").winedit("Price:").GetVisibleText()
msgbox (" The Ticket Price:-" & tkprc)
msgbox (" The number of Tickets:-" & tickno)
tkprc1=mid (tkprc , 2)
total1=tkprc1* tickno
msgbox (" The total price of Tickets:-$" & total1) 
End Function


'=========validation function for Ticket numbers=================


Function tickvalid(tickno)
Dim i
If tickno<=10 Then
window("Flight Reservation").WinEdit("Tickets:").Set tickno
call prcal(tickno)
Else
Do While tickno>10
msgbox "You have enter more then 10 tickets"
i=inputbox ("Please Enter the ticket below or equal to 10:")
If i<=10 Then 
window("Flight Reservation").WinEdit("Tickets:").Set i
call prcal(i)
end if
Exit do
loop
End If
End Function


'=========validation function for price comparision of ticket price=================


Function prcomp()
i=Window("Flight Reservation").WinRadioButton("Economy").set
j=Window("Flight Reservation").WinRadioButton("Economy").set
k=Window("Flight Reservation").WinRadioButton("Economy").set
if k=3 * i and j = 2 * i then
msgbox ("First class is 3 time expensive and business class is 2 time expensive then economy class")
else
msgbox("The price of classes  are not right")
end if 
End Function




'=========function for updation the order=================


Function update()
   msgbox ("Now  you can update the information in your application")
   Window("Flight Reservation").WinButton("Update Order").Click
End Function




'=========function for deletion the order=================


Function delorder()
   msgbox("Do You want to delete the order from application")
   Window("Flight Reservation").WinButton("Delete Order").Click
Window("Flight Reservation").Dialog("Flight Reservations").WinButton("Yes").Click
End Function






www.nitesh10.blogspot.com

Wednesday, 29 June 2011

count no of child in flight reservation system,

invokeapplication "C:\Program Files\Internet Explorer\IEXPLORE.EXE"

browser("title:=Google").page("title:=Google").Link("text:=Gmail").Click

browser("name:=Gmail: Email from Google").dialog("text:=Security Information").winbutton("text:=&Yes").Click

'browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google").link("outertext:=Create an account » ").Click

'browser("name:=Google Accounts").dialog("text:=Security Information").winbutton("text:=&Yes").Click

browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google").webedit("name:=Email").set "syalde"

browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google").webedit("name:=Passwd").Set "4db7a7321cf91bdcf77d9b78f6b166ac4d1"

browser("name:=Gmail: Email from Google").page("title:=Gmail: Email from Google").webbutton("name:=Sign in").Click



invokeapplication "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight3a.exe"
'set a = dialog("text:=Login").ChildObjects()
'c= a.count()
'print c

Dialog("Login").WinEdit("Agent Name:").Set "kripal"
Dialog("Login").WinEdit("Agent Name:").Type micTab
Dialog("Login").WinEdit("Password:").SetSecure "4db7c1f5b09e1e331f28a6e7c55296847c73706d"
Dialog("Login").WinButton("OK").Click

set b = Window("text:=Flight Reservation").ChildObjects()
c= b.count
print c
For i =0 to c-1

d = b(i).getroproperty("text")

print d
Next