How to get all items from WinList object

1,350 views
Skip to first unread message

suhail khan

unread,
Oct 4, 2011, 3:58:57 AM10/4/11
to mercu...@googlegroups.com
Dear All

i have a query .
i have one WinList Object with following data 

Flight NO  Fly From     Fly To        Departure Time       ArivalTime   Price 
123           London       Frankfurt     12.00am                1.00 am      $123
1234         Delhi           London        3.00 am                5.00 pm      $480
134           Denver        New york      1.00 pm                4.00 am     &320

i want to print cheapest flight's Flight No 

Regards
suhail 

Anish Pillai

unread,
Oct 4, 2011, 3:17:31 PM10/4/11
to mercu...@googlegroups.com
Hi Suhail,

Usually you have the 'all items' which would give you all the values of the weblist. But if you are referring to the flight application here, then it would be difficult to differentiate among the different sets of data.

But you can try out the following approach.
Select each value from the list one by one. Once a value has been selected, use WinList.GetSelection method to get the selected value. This would give you '123           London       Frankfurt     12.00am                1.00 am      $123' as the value. To find the price , you can use the Split function.


--
Regards,
Anish Pillai
My QTP Blog

suhail khan

unread,
Oct 5, 2011, 12:14:26 AM10/5/11
to mercu...@googlegroups.com
Thanks Anish for your valuable suggestion 
exactly the same approach i used .

Regards
suhail 



--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en

Shalabh Dixit

unread,
Oct 5, 2011, 3:52:01 PM10/5/11
to mercu...@googlegroups.com
Hi Suhail,

Below is the complete code and also attached are actual script and screenshots for the same. You need to copy the function RegExMatchandReplace in the script or you can also use it as function library.

The code is menu based and will give you following as per your choice

1. Lowest Flight Price & Flight Number
2. Highest Flight Price & Flight Number
3. All Flight Prices & Flight Numbers


Please let me know if you need any further clarifications.

'Opening Flight Reservation Application
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Logging-in To Application
Dialog("Login").WinEdit("Agent Name:").Set "jojo"
Dialog("Login").WinEdit("Agent Name:").Type  micTab
Dialog("Login").WinEdit("Password:").SetSecure "4e8c90421854413368e315abb05e340ddfc4f975"
Dialog("Login").WinEdit("Password:").Type  micReturn
Window("Flight Reservation").Activate
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Entering Flight Details
Window("Flight Reservation").ActiveX("MaskEdBox").Type "101114"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Portland"
Window("Flight Reservation").WinButton("FLIGHT").Click
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Retrieving All the Available Flights
str_FlightsList = Window("Flight Reservation").Dialog("Flights Table").WinList("From").GetROProperty("all items")
arr_FlightsPriceList = Split(str_FlightsList,"$")
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Initializing Array Size Variable
int_size = 0
'Removing Unwanted WhiteSpaces/Tabs/CarriageReturn etc from the list
str_FlightsList = RegExMatchandReplace(str_FlightsList,"[ \t\r\n\s]"," ",True)
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'Declaring Arrays to store all the Flight Price and Flight Numbers
Dim arr_FlightNum(),arr_FlightPrice()
'------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
For int_Flight_List = 1 To UBound(arr_FlightsPriceList)
    'Resizing Arrays
    ReDim Preserve arr_FlightNum(int_size)
    ReDim Preserve arr_FlightPrice(int_size)
    arr_TempList = Split(arr_FlightsPriceList(int_Flight_List),Space(1))
   
    If int_Flight_List = UBound(arr_FlightsPriceList) Then
        int_Price_Final = arr_TempList(0)
    Else
        'Removing Unwanted WhiteSpaces/Tabs/CarriageReturn etc from the list
        int_Price_With_Spaces = RegExMatchandReplace(arr_TempList(0),"[ \t\r\n\s]"," ",True)
        int_Price_Final = Split(int_Price_With_Spaces," ")(0)
    End If
   
    If int_Flight_List = 1 Then
        int_Flight_Num = Trim(Split(arr_FlightsPriceList(int_size)," ")(0))
        arr_FlightNum(int_size) = int_Flight_Num
        arr_FlightPrice(int_size) = int_Price_Final
    Else
        'Removing Unwanted WhiteSpaces/Tabs/CarriageReturn etc from the list
        int_Flight_Num_With_Spaces = RegExMatchandReplace(Trim(Split(arr_FlightsPriceList(int_size)," ")(0)),"[ \t\r\n\s]"," ",True)
        int_Flight_Num_Final = Split(int_Flight_Num_With_Spaces," ")(1)
        arr_FlightNum(int_size) = int_Flight_Num_Final
        arr_FlightPrice(int_size) = int_Price_Final
    End If
    int_size = int_size + 1
Next

'Sorting the FlightNumber & FlightPrice Arrays
For int_Array_Index1 = 0 To UBound(arr_FlightPrice) - 1
    For int_Array_Index2 = int_Array_Index1 + 1 To UBound(arr_FlightPrice)
        If arr_FlightPrice(int_Array_Index1) > arr_FlightPrice(int_Array_Index2) Then
            'Sorting the FlightPrice Array
            int_Temp_Price = arr_FlightPrice(int_Array_Index2)
            arr_FlightPrice(int_Array_Index2) = arr_FlightPrice(int_Array_Index1)
            arr_FlightPrice(int_Array_Index1) = int_Temp_Price
            '-------------------------------------------------------------------------------------
            'Sorting the FlightNumber
            int_Temp_FlightNum = arr_FlightNum(int_Array_Index2)
            arr_FlightNum(int_Array_Index2) = arr_FlightNum(int_Array_Index1)
            arr_FlightNum(int_Array_Index1) = int_Temp_FlightNum
        End If
    Next
Next


'User Menu
input = InputBox ("Please Enter your choice from below menu: " & vbnewline &_
                                    "1.) 'L' or 'l' to get Lowest Price Flight Number & Flight Price" & vbnewline &_
                                    "2.) 'H' or 'h' to get Highest Price Flight Number & Flight Price"  & vbnewline &_
                                    "3.) 'A' or 'a' to get Complete List of Flights Available with Price & Numbers")

input = UCase(input)

Select Case input
    Case "L"
        Print    "a. Lowest Flight Number = " & arr_FlightNum(LBound(arr_FlightNum)) & VbNewline &_
                    "b. Lowest Flight Price = " & arr_FlightPrice(LBound(arr_FlightPrice))
    Case "H"
        Print    "a. Highest Flight Number = " & arr_FlightNum(UBound(arr_FlightNum)) & VbNewline &_
                    "b. Highest Flight Price = " & arr_FlightPrice(UBound(arr_FlightPrice))
    Case "A"
        num = 1
        For int_Array_Index = 0 To UBound(arr_FlightNum)
            Print    "Record " & num & vbnewline &"--------------------------------------------------------------------------" & vbnewline &_
                        "a. Flight Number = " & arr_FlightNum(int_Array_Index) & VbNewline &_
                        "b. Flight Price = " & arr_FlightPrice(int_Array_Index) & VbNewline & "#############################################################################################################" & VbNewline
            num  = num + 1
        Next
    Case Else
        MsgBox "Invalid Input"
End Select



Regards
Shalabh Dixit
RegExMatchandReplace.txt
Screenshots.doc
Get_FlightNumbers_and_FlightPrices.zip

G Thind

unread,
Nov 1, 2013, 4:03:05 PM11/1/13
to mercu...@googlegroups.com
Hi Shalab,

your code worked like charm. What I need to understand is there a way to learn this coding for QTP. As I didn't understand your function and half of your code.

Please help.

Garry
Reply all
Reply to author
Forward
0 new messages