QTP的描述性程式設計與正規表示式

TIB發表於2010-03-22

在使用QTP描述性程式設計的方式進行指令碼編寫時,通常需要應用到正規表示式,relevantcodes.com的這篇文章《Descriptive Programming (DP) Concepts – 2 {Regular Expressions}》詳細描述了正規表示式(尤其是萬用字元)在DP中的使用:

http://relevantcodes.com/descriptive-programming-dp-concepts-2-regular-expressions/

 

例如萬用字元的用法:

Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours").Image("file name:=banner2.gif").Highlight

 

Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours").Image("file name:=banner2.*").Highlight

 

Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours").Image("file name:=banner.*").Highlight

 

Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours").Image("file name:=ban.*gif").Highlight

 

Browser("title:=Welcome: Mercury Tours").Page("title:=Welcome: Mercury Tours").Image("file name:=ban.*f").Highlight

 

 

文中以Mercury Tours為例介紹了一些正規表示式的使用方法,例如:

' Using the first few characters of the title and the first few characters of the image

Browser("title:=Welc/w+/D+/w+").Page("title:=Welc/w+/D+/w+").Image("file name:=ban/w+/d+/./w+").Highlight

 

' Using the last few characters of the title with first and last characters of the image

Browser("title:=/w+/D+/w+ours").Page("title:=/w+/D+/w+ours").Image("file name:=b/w+2/.gif").Highlight

 

' Same as above for Browser and Page, but '...' for image

Browser("title:=/w+/D+/w+ours").Page("title:=/w+/D+/w+ours").Image("file name:=b/w+2/....").Highlight

 

' Same as above, but replaced 'b' with a '.'

Browser("title:=/w+/D+/w+ours").Page("title:=/w+/D+/w+ours").Image("file name:=./w+2/....").Highlight

 

 

文中推薦了一個學習正規表示式的網站:

http://www.regular-expressions.info/

 

 

相關文章