Customize the select method of winlist in qtp

Source: Internet
Author: User

In
Qtp
Custom test object
Winlist
Of
Select
Method, supports regular expressions and multiple choices. Similar ideas can be extended to other
List
Type Control.

 

The following script is taken from
Qtp
Of
Codesamplesplus
:

 

Function selectregexp (OBJ, patrn, button,
Offset)



Dim numofitems, I, currentvalue, RegEx, itemtoselect, oldfilter


'
Initialize the regular expression object with the pattern



Set RegEx = new Regexp



RegEx. pattern = patrn



RegEx. ignorecase = false

 



Oldfilter = Reporter. Filter 'Save the default setting



Reporter. Filter = 2 'send only errors



Itemtoselect =-1


'
Retrieve the number of items in the list



Numofitems = obj. getroproperty ("items count ")



For I = 0 to NumOfItems-1



Currentvalue = obj. getitem (I)



If RegEx. Test (currentvalue) then



If (itemtoselect <>-1) then


Selectregexp =-1 'item not
Unique


Reporter. Filter = oldfilter


Exit Function



End if



Itemtoselect = I



End if



Next



Reporter. Filter = oldfilter 'Restore the default setting


'
The actual selection



If (itemtoselect> = 0) then



Selectregexp = obj. Select (itemtoselect, button, offset)



Else



Selectregexp =-1



End if

End Function

 

Function selectitems (OBJ, items)



Dim idx, item



If (strcomp (obj. getroproperty ("type"), "select-multiple ",
1) = 0) then



For each item in items



OBJ. Select (item)



Next



Else



OBJ. Select (items (0 ))



End if

End Function

 

'Override the select function of
Winlist

Registeruserfunc "winlist ",
"Select", "selectregexp"

 

'Or add the selectregexp function to
Winlist object

Registeruserfunc "winlist ",
"Selectregexp", "selectregexp"

Registeruserfunc "winlist ",
"Selectitems", "selectitems"

 

'Example of usage:

Winlist ("mylist"). Select
"2002 .*"

Winlist ("mylist"). selectitems
Array ("Item1", "item3", "item6 ")

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.