Hi luasaigon,
Bạn có thể giúp mình solution cho phần "Regular Expression" được hok ?
Thanks bạn nhiều,
Thắc mắc về Regular Expression trong QTP
Forum rules
Thảo luận về phần mềm Quick Test Pro QTP
Thảo luận về phần mềm Quick Test Pro QTP
-
- Fresher Tester
- Posts: 23
- Joined: Mon 21 May, 2012 10:54 pm
- Contact:
-
- Fresher Tester
- Posts: 36
- Joined: Thu 27 Oct, 2011 10:50 pm
- Contact:
Re: Thắc mắc về Regular Expression trong QTP
Hi bạn,quangdovan8x wrote:Chào các bạn,
P/s: mình cũng có thắc mắc về "Regular Expression" trong QTP, chẳng hạn mình có câu lệnh
VbWindow("frmABTInventory").VbComboBox("cboProducts").Select "Nails"
Mình sẽ dùng "Regular Expression" như thế nào để có thể thay thế "Nails" chỉ bằng "N" thôi.
Bạn có thể sửa như vậy:
VbWindow("frmABTInventory").VbComboBox("cboProducts").Select "N.*"
thân.
-
- Fresher Tester
- Posts: 23
- Joined: Mon 21 May, 2012 10:54 pm
- Contact:
Re: Thắc mắc về Regular Expression trong QTP
Hi luasaigon,
Mình đã thử Select "N.*", nhưng QTP báo error
"Cannot identify the specified item of the cboProducts object. Confirm that the specified item is included in the object's item collection.
Line (1): "VbWindow("ABTInventory").VbComboBox("cboProducts").Select "N.*"".
Trong khi item "Nails" đang tồn tại trong "Products" combobox.
Có phải do mình viết sai cấu trúc của Regular Expression trong QTP hok ?
Regards,
Mình đã thử Select "N.*", nhưng QTP báo error
"Cannot identify the specified item of the cboProducts object. Confirm that the specified item is included in the object's item collection.
Line (1): "VbWindow("ABTInventory").VbComboBox("cboProducts").Select "N.*"".
Trong khi item "Nails" đang tồn tại trong "Products" combobox.
Có phải do mình viết sai cấu trúc của Regular Expression trong QTP hok ?
Regards,
You do not have the required permissions to view the files attached to this post.
-
- Fresher Tester
- Posts: 36
- Joined: Thu 27 Oct, 2011 10:50 pm
- Contact:
Re: Thắc mắc về Regular Expression trong QTP
Hi quangdovan8x,
Xin lỗi vì mình trả lời hơi trễ, mình đã thử với app FLIGHT trường hợp giống như bạn miêu tả, đây là code của mình:
Bạn viết thêm 1 function RegexSelectQTP trước script của bạn sau đó ở dưới testcase bạn sử dụng nó, trong trường hợp của mình thì mình sử dụng "D.*" thay cho "Denver"
Đây là dòng mình sử dụng:
thân.
Xin lỗi vì mình trả lời hơi trễ, mình đã thử với app FLIGHT trường hợp giống như bạn miêu tả, đây là code của mình:
Code: Select all
Function RegexSelectQTP(Object, sPattern)
Dim oRegExp, arrAllItems, ix
'Create RegExp Object
Set oRegExp = New RegExp
oRegExp.IgnoreCase = False
oRegExp.Pattern = sPattern
'Split Object's all_items property
arrAllItems = Split(Object.GetROProperty("all items"), ";")
For ix = LBound(arrAllItems) To UBound(arrAllItems)
'If RegExp pattern matches list item, we're done!
If oRegExp.Test(arrAllItems(ix)) Then
Object.Select ix
Set oRegExp = Nothing
Exit Function
End If
Next
'Select Item #1 by default
Object.Select "#0"
End Function
RegisterUserFunc "WinComboBox", "RegexSelectQTP", "RegexSelectQTP"
Window("Flight Reservation").WinObject("Date of Flight:").Click 1,5
Window("Flight Reservation").WinObject("Date of Flight:").Type "121215"
' Using function RegexSelectQTP
Window("Flight Reservation").WinComboBox("Fly From:").RegexSelectQTP "D.*"
Window("Flight Reservation").WinComboBox("Fly To:").Select "London"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Đây là dòng mình sử dụng:
Code: Select all
Window("Flight Reservation").WinComboBox("Fly From:").RegexSelectQTP "D.*"
-
- Fresher Tester
- Posts: 23
- Joined: Mon 21 May, 2012 10:54 pm
- Contact:
Re: Thắc mắc về Regular Expression trong QTP
Hi luasaigon,
Mình chân thành cám ơn sự nhiệt tình giúp đỡ của bạn,
Về phần code, mình đã viết 1 function cho RegEx. Nhưng thay vì mình select "Denver", mình đã thay bằng "Los.*" thay cho Los Angeles" (vì mình thấy value default là #0 - "Denver"), tuy nhiên QTP chỉ select "Denver" trong tất cả các lần run.
Chi tiết script của mình như sau:
1. Function:
Function RegexSelectQTP(Object, sPattern)
Dim oRegExp, arrAllItems, ix
'Create RegExp Object
Set oRegExp = New RegExp
oRegExp.IgnoreCase = False
oRegExp.Pattern = sPattern
'Split Object's all_items property
arrAllItems = Split(Object.GetROProperty("all items"), ";")
For ix = LBound(arrAllItems) To UBound(arrAllItems)
'If RegExp pattern matches list item, we're done!
If oRegExp.Test(arrAllItems(ix)) Then
Object.Select ix
Set oRegExp = Nothing
Exit Function
End If
Next
'Select Item #1 by default
Object.Select "#0"
End Function
RegisterUserFunc "WinComboBox", "RegexSelectQTP", "RegexSelectQTP"
2.Test case:
Window("Flight Reservation").WinObject("Date of Flight:").Click 1,5
Window("Flight Reservation").WinObject("Date of Flight:").Type "121215"
Window("Flight Reservation").WinComboBox("Fly From:").RegexSelectQTP "Los.*"
p/s: mình hok hiểu đoạn code RegisterUserFunc "WinComboBox", "RegexSelectQTP", "RegexSelectQTP" nên đã làm 2 trường hợp:
1. đặt code này trong function
2. đặt code trong test case
trong cả 2 trường hợp, QTP đều select "Denver".
Liệu mình có thiếu phần nào hok.
Mong nhận được feedback của bạn.
Chân thành cám ơn,
Mình chân thành cám ơn sự nhiệt tình giúp đỡ của bạn,
Về phần code, mình đã viết 1 function cho RegEx. Nhưng thay vì mình select "Denver", mình đã thay bằng "Los.*" thay cho Los Angeles" (vì mình thấy value default là #0 - "Denver"), tuy nhiên QTP chỉ select "Denver" trong tất cả các lần run.
Chi tiết script của mình như sau:
1. Function:
Function RegexSelectQTP(Object, sPattern)
Dim oRegExp, arrAllItems, ix
'Create RegExp Object
Set oRegExp = New RegExp
oRegExp.IgnoreCase = False
oRegExp.Pattern = sPattern
'Split Object's all_items property
arrAllItems = Split(Object.GetROProperty("all items"), ";")
For ix = LBound(arrAllItems) To UBound(arrAllItems)
'If RegExp pattern matches list item, we're done!
If oRegExp.Test(arrAllItems(ix)) Then
Object.Select ix
Set oRegExp = Nothing
Exit Function
End If
Next
'Select Item #1 by default
Object.Select "#0"
End Function
RegisterUserFunc "WinComboBox", "RegexSelectQTP", "RegexSelectQTP"
2.Test case:
Window("Flight Reservation").WinObject("Date of Flight:").Click 1,5
Window("Flight Reservation").WinObject("Date of Flight:").Type "121215"
Window("Flight Reservation").WinComboBox("Fly From:").RegexSelectQTP "Los.*"
p/s: mình hok hiểu đoạn code RegisterUserFunc "WinComboBox", "RegexSelectQTP", "RegexSelectQTP" nên đã làm 2 trường hợp:
1. đặt code này trong function
2. đặt code trong test case
trong cả 2 trường hợp, QTP đều select "Denver".
Liệu mình có thiếu phần nào hok.
Mong nhận được feedback của bạn.
Chân thành cám ơn,
You do not have the required permissions to view the files attached to this post.