QTP使用正则表达式动态匹配对象文本

发布于 2024-09-11 04:56:07 字数 168 浏览 3 评论 0原文

假设我们正在尝试匹配 SSN,因此正则表达式为:d{9}。但是,如果在运行时我想让第三位数字与 3 匹配怎么办?因此正则表达式将为 d{2}3d{6}。

我知道在 QTP 中,您可以使用正则表达式来匹配对象存储库中对象的文本属性,但是如何在 QTP 代码中更改该正则表达式?

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜宝宝 2024-09-18 04:56:08

您可以使用 SetTOProperty 更改存储库中的属性值,这会更改当前运行的值,但不会更改下一次测试运行的值。它还更改存储的测试对象中的值,而不是正在测试的应用程序中相应控件中的值(要从应用程序中获取当前值,请使用 GetROProperty ,没有 SetROProperty ) )。

''# Change button "5" to point to "And"
Window("Calculator").WinButton("5").SetTOProperty "text", "[Aa]nd"
Window("Calculator").WinButton("5").Click

请注意,虽然您可以更改该值,但无法更改它是否为正则表达式(上述情况仅在 5text 属性已定义为使用时才有效正则表达式)。

或者,您可以使用描述性编程

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文