Anda di halaman 1dari 4

'***********************************************************************************************

'

Purpose of Script:- VBScript to enter values into web fields of http://newtours.demoauto.com

'

from MS Excel file.

'

Script Version:- 1.2.4

'

AutomomyV Script Changed:- Added height and width in Sub InvokeIE(url, wSleepTime) in

'

AutonomyLib.vbs file for resizing the IE window.

'

Tested for:- http://newtours.demoauto.com. No assertions tested with this script. It can be

'

scripted, by looking at the sample scripts provided along with this

'

AutonomyV tool.

'

Limitation:- AutonomyV supports IE only.

'

Credits to:- AutonomyV team and Mercury tours website (http://newtours.demoauto.com)

'

Date Revised: 10th January 2010.

'***********************************************************************************************

Option Explicit

'Declaration of variables. Dim objExcel Dim excelPath Dim worksheetCount Dim counter Dim currentWorkSheet Dim usedColumnsCount Dim usedRowsCount Dim row Dim column Dim top Dim left Dim Cells Dim curCol Dim curRow Dim cellValue

' Begining of script.

'Declaring the MS Excel file path. excelPath = "c:\testDemoAUT.xls" Set objExcel = CreateObject("Excel.Application") objExcel.Workbooks.open excelPath, false, true

'###########LOAD AUTONOMY LIBRARY############ Dim fso, f, file, sStrm file = "C:\AUTOnomyV\AutonomyLib.vbs" Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile(file, 1) sStrm = f.ReadAll executeGlobal(sStrm) '############################################

' Opening the MS Excel file as read-only. objExcel.Workbooks.open excelPath, false, true

'Counting the number of worksheet available in the MS EXcel file chosen. 'Can be used when different worksheet has data that is used for each test 'mission thought of to accomplish. workSheetCount = objExcel.Worksheets.Count

InvokeIE "http://newtours.demoaut.com",0

For counter = 1 to workSheetCount

' Setting first worksheet as the sheet to be read via variable "counter".

Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)

' Getting number of columns used in the chosen MS Excel file's worksheet. usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count

' Getting number of rows used in the chosen MS Excel file's worksheet. usedRowsCount = currentWorkSheet.UsedRange.Rows.Count

' Getting the value of 1st row of chosen MS Excel file's worksheet. top = currentWorksheet.UsedRange.Row

' Getting the value of 2nd row of chosen MS Excel file's worksheet. left = currentWorksheet.UsedRange.Column

' Getting the variable 'Cells' with the current worksheet cells. Set Cells = currentWorksheet.Cells

'Window("Welcome: Mercury Tours",0,0).all(WebLink("INNERTEXT","Flights",2)).click 'Window("Welcome: Mercury Tours",0,0).all(WebLink("INNERTEXT","Hotels",2)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","Flights",2)).click Window("Welcome: Mercury Tours",0,0).all(WebEdit("TEXT","NAME","userName",0)).value = "mercury" Window("Welcome: Mercury Tours",0,0).all(WebEdit("PASSWORD","NAME","password",0)).value = "mercury" Window("Welcome: Mercury Tours",0,0).all(WebImage("NAME","login",0)).click

'Window("Find a Flight: Mercury Tours:",0,0).all(WebLink("INNERTEXT","Flights",2)).click 'Window("Find a Flight: Mercury Tours:",0,0).all(WebLink("INNERTEXT","Hotels",2)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","Car Rentals",3)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","Cruises",2)).click 'Window("Cruises: Mercury Tours",0,0).all(WebLink("INNERTEXT","Destinations",2)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","Vacations",2)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","Home",3)).click 'Window("Welcome: Mercury Tours",0,0).all(WebLink("INNERTEXT","CONTACT",1)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","SUPPORT",1)).click 'Window("Under Construction: Mercury Tours",0,0).all(WebLink("INNERTEXT","Flights",2)).click

'Looping through each rows used in the worksheet. For row = 0 to (usedRowsCount-1)

'Looping through each columns used in the worksheet. 'For column = 0 to usedColumnsCount-1

curRow = row+top curCol = column+left cellValue = Cells(curRow,curCol).Value 'Wscript.Echo("Current row being read: "& curRow) Rem for debugging purpose. v1.2.2 'WScript.Echo("Current column being read: "& curCol) Rem for debugging purpose. v1.2.2

Window("Find a Flight: Mercury Tours:",0,100).all(WebRadioButton("NAME","tripType",Cells(curRow,1).Value)).click wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebList("NAME","passCount",0)).selectedIndex= Cells(curRow,2).Value wscript.sleep 500

Window("Find a Flight: Mercury Tours:",0,100).all(WebList("NAME","fromPort",0)).selectedIndex = Cells(curRow,3).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,0).all(WebList("NAME","fromMonth",0)).selectedIndex = Cells(curRow,4).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebList("NAME","fromDay",0)).selectedIndex = Cells(curRow,5).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebList("NAME","toPort",0)).selectedIndex = Cells(curRow,6).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,0).all(WebList("NAME","toMonth",0)).selectedIndex = Cells(curRow,7).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebList("NAME","toDay",0)).selectedIndex = Cells(curRow,8).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebRadioButton("NAME","servClass",Cells(curRow,9).Value)).click wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebList("NAME","airline",0)).selectedIndex = Cells(curRow,10).Value wscript.sleep 500 Window("Find a Flight: Mercury Tours:",0,100).all(WebImage("NAME","findFlights",0)).click wscript.sleep 700 Window("Select a Flight: Mercury Tours",0,100).all(WebRadioButton("NAME","outFlight",Cells(curRow,11).Value)).click wscript.sleep 500

'Window("Select a Flight: Mercury Tours",0,0).all(WebRadioButton("NAME","outFlight",2)).click 'Window("Select a Flight: Mercury Tours",0,0).all(WebRadioButton("NAME","outFlight",3)).click Window("Select a Flight: Mercury Tours",0,100).all(WebRadioButton("NAME","inFlight",Cells(curRow,12).Value)).click wscript.sleep 500 'Window("Select a Flight: Mercury Tours",0,0).all(WebRadioButton("NAME","inFlight",2)).click 'Window("Select a Flight: Mercury Tours",0,0).all(WebRadioButton("NAME","inFlight",3)).click Window("Select a Flight: Mercury Tours",0,100).all(WebImage("NAME","reserveFlights",0)).click wscript.sleep 500

If Cells(curRow,2) = 1 Then

Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst0",0)).value = Cells(curRow,13).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast0",0)).value = Cells(curRow,14).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.0.meal",0)).selectedIndex = Cells(curRow,15).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst1",0)).value = Cells(curRow,16).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast1",0)).value = Cells(curRow,17).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.1.meal",0)).selectedIndex = Cells(curRow,18).Value wscript.sleep 500

ElseIf Cells(curRow,2) = 0 Then

Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst0",0)).value = Cells(curRow,13).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast0",0)).value = Cells(curRow,14).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.0.meal",0)).selectedIndex = Cells(curRow,15).Value wscript.sleep 500

ElseIf Cells(curRow,2) = 2 Then

Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst0",0)).value = Cells(curRow,13).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast0",0)).value = Cells(curRow,14).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.0.meal",0)).selectedIndex = Cells(curRow,15).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst1",0)).value = Cells(curRow,16).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast1",0)).value = Cells(curRow,17).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.1.meal",0)).selectedIndex = Cells(curRow,18).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst2",0)).value = Cells(curRow,13).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast2",0)).value = Cells(curRow,14).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.2.meal",0)).selectedIndex = Cells(curRow,15).Value wscript.sleep 500

ElseIf Cells(curRow,2) = 3 Then

Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst0",0)).value = Cells(curRow,13).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast0",0)).value = Cells(curRow,14).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.0.meal",0)).selectedIndex = Cells(curRow,15).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst1",0)).value = Cells(curRow,16).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast1",0)).value = Cells(curRow,17).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.1.meal",0)).selectedIndex = Cells(curRow,18).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst2",0)).value = Cells(curRow,13).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast2",0)).value = Cells(curRow,14).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.2.meal",0)).selectedIndex = Cells(curRow,15).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passFirst3",0)).value = Cells(curRow,16).Value

wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","passLast3",0)).value = Cells(curRow,17).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","pass.3.meal",0)).selectedIndex = Cells(curRow,18).Value wscript.sleep 500

Else

WScript.Echo("Looks like script is reading a digit that is not supported currently for number of passengers. Sorry! Script execution is aborted.") WScript.Quit

End If

Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","creditCard",0)).selectedIndex = Cells(curRow,19).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","creditnumber",0)).value = Cells(curRow,20).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","cc_exp_dt_mn",0)).selectedIndex = Cells(curRow,21).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","cc_exp_dt_yr",0)).selectedIndex = Cells(curRow,22).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","cc_frst_name",0)).value = Cells(curRow,23).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","cc_mid_name",0)).value = Cells(curRow,24).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","cc_last_name",0)).value = Cells(curRow,25).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebCheckButton("NAME","ticketLess",1)).click wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","billAddress1",0)).value = Cells(curRow,26).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","billAddress2",0)).value = Cells(curRow,27).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","billCity",0)).value = Cells(curRow,28).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","billState",0)).value = Cells(curRow,29).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebEdit("TEXT","NAME","billZip",0)).value = Cells(curRow,30).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebList("NAME","billCountry",0)).selectedIndex = Cells(curRow,31).Value wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebCheckButton("NAME","ticketLess",Cells(curRow,32).Value)).click wscript.sleep 500 Window("Book a Flight: Mercury Tours",0,100).all(WebImage("NAME","buyFlights",0)).click wscript.sleep 500 Window("Flight Confirmation: Mercury Tours",0,100).all(WebImage("SRC","http://newtours.demoaut.com/images/forms/backtoflights.gif",0)).click

'Window("Book a Flight: Mercury Tours",0,0).all(WebImage("NAME","buyFlights",0)).click 'Window("Flight Confirmation: Mercury Tours",0,0).all(WebImage("SRC","http://newtours.demoaut.com/images/forms/Logout.gif",0)).click

Next

'Next

Set currentWorkSheet = Nothing

Next

objExcel.Workbooks(1).Close

objExcel.Quit

Set currentWorkSheet = Nothing Set objExcel = Nothing objExcel.Workbooks.close excelPath

' End of script.