QTP Using Regular Expressions to match object text dynamically
Let's say we're trying to match SSNs, so the regular expression would be: d{9}. But what if, at run time, I wanted to have, say, the third digit match to 3? So the regex would be d{2}3d{6}.
I know that in QTP, you can use regex to match the text property of an object in the Object Repository, but how do 开发者_运维百科I change that regex in QTP code?
Thanks for your help!
You can change the value of the property in the repository using SetTOProperty
this changes the value for the current run but not for next runs of the test. Also it changes the value in the stored test object and not in the corresponding control in the application being tested (to get the current value from the application use GetROProperty
there is no SetROProperty
).
''# Change button "5" to point to "And"
Window("Calculator").WinButton("5").SetTOProperty "text", "[Aa]nd"
Window("Calculator").WinButton("5").Click
Note that while you can change the value you can't change whether it's a regular expression (the case above will only work if 5
's text
property is already defined to use regular expressions).
Alternately you can use descriptive programming.
精彩评论