Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Articles On Testing

Wecome to http://www.articlesontesting.com !!!

Showing posts with label regular expression. Show all posts
Showing posts with label regular expression. Show all posts

Regular Expression In QTP

How to Use regular Expression in QTP programming

Here our objective is to figure out the frequency of occurance of any string.

Set re = New RegExp
re.Global = True
re.Pattern = "Viplav"
s = "Viplav is a wonderful guy and has all the more Viplav in him, I have not come acros  any other Viplav like human in my whole Viplav"
Set strMatch = re.Execute(s)
MsgBox strMatch.count

For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP

Regular expression In QTP :

How To Use : Regular expression to make our search globalize.

To execute the test in QTP every object is searched in the object repository (OR). In
real time applications some object's properties always keep changing so at the
time of execution script fails. To overcome it we use "regular expression " for
that particular object's property. For example:

1) Record a test where you are inserting one order and than faxing the same order.
2) The order number that is generated during recording may 21 and Fax Order window title is generated and saved into OR as Fax Order No. 21
3) Now execute the same test the script will fail because this time order no is modified as 22 and accordingly Fax Order window title is modified as Fax Order No. 22 .
4) This time the object Fax Order No. 22 is not identified or you can understand object is not matched (find) into OR.

5) To make this search better we modify the text property of object into OR as Fax Order No.* this will search all the
occurrences of window that has text as Fax Order No

6) We can also write it as Fax Order No. [0-9] because fax order no is a numerical value and this will search only numbers after Fax Order No.

So this is the purpose of regular expression in QTP.
To handle the dynamics objects either window/web based application. To handle the objects those name having string along with number the number may change in every execution or every particular time. To handle these objects we can use regular expression.
It have 5 types
1. Dot - .
2. regular expression
3. Star - *
4. Carat - ^
5. Range - [ ]
Also Regular Exp is used for pattern matching and replacing of a string.

* : Matches the preceding character zero or more times.
. : Matches any single character except a newline character.

For gaining more insights in the automation using QTP log on to below url :

Automation Testing Using QTP

Automating Using QTP Day5 Some VbScripting Techniques

Synchronization of the application load with the Script execution :
Wait and WaitRoproperty.
In scenarios wherein the properties of the object changes after some time we use waitproperty.

Object Recognition Mechanism in QTP :

  • Add object in the Object Repository using Object Spy 
  • Creating the same using Descriptive programming.
  • Using the active screen or going into the application and clicking insert new object.
Regular Expression Usage Effectively in the scripting :
After having gone through the Book Ticket scenario in the Flight application . just go into the File menu for Fax order scenario.
Go to file and select Fax the booked tickets.
Select for regular expression option so that the fax order number gets recognised each time on the basis
of this very regular expression
Just put a .* after the point from where the characters is expected to be changed.

Text Checkpoint :
Checked text, Text Before, After text
Match CAse, exact match,

Text Area checkpoint
is for tabular display for any specific row.
namespace standards in xml.
XML Addins
is required for the XML checkpoints.

Test Objects used by web services.
Strat Transaction end transactionm...
Time frames get retunrned
Generally used foir query time out features related to databasae interactions.
Colon is used to combine multiple statement in one line

Important conecpts in Advanced QTP workaround :

  • Parameterization
  • Checkpoint
  • Synchronization
  • Object Repository
Descriptive Programming  is a technique used when an object property changes frequently.
No Object Repository method is used for object identification.

Static are the necessary properties of an objects.
Methods like SET are used for creating references to the objects actually present in the application.

Let us look into describing the Objects in the application. Do remember the hierarchy of the Parent and child objects. Generally  the approach we follow for the description programming  is coding in the hierarchial manner that an object is recognized by the QTP tool during the course of object identification.

 Login Box Which is a dialog box
 Keep your appplication open, Object Spy tool can be useed to spy onto the objects and highlight and  copy the properties of the required objects.
 Individually search for each of the objects associated properties.
 Always use the two things, class name and the text name genuinely very relevant.

 Below we spy for the Login dialog page properties

Parent Objects :
Set oLogin=Description.Create()oLogin("Class Name").Value="Dialog"
oLogin("text").Value="Login"

 Child Objects :
 For Login Fileds Textbox

Set oUserNam=Description.Create() oUserNam("Class Name").Value="WinEdit"
 oUserNam("attached text").Value="Agent Name:"

 For Password Fields Textbox Set opassword=Description.Create()
 opassword("Class Name").Value="WinEdit"
 opassword("attached text").Value="Password:"

For Button to log on OKSet oOKButton=Description.Create() oOKButton("Class Name").Value="WinButton"
oOKButton("text").Value="OK"

 For Button to log on CancelSet oCanButton=Description.Create() oCanButton("Class Name").Value="WinButton"
oCanButton("text").Value="Cancel"

 Now , let us code using VBScript  to execute the events in the application which is expected to be performed for logging into the application.

InvokeApplication
"D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight3a"
Dialog(oLogin).WinEdit(oUserNam).Type"employee"
Dialog(oLogin).WinEdit(oUserNam).Set "employee"
Dialog(oLogin).WinEdit(oPassword).Set "mercury"
Dialog(oLogin).WinButton(oOKButton).Click


Dynamic Descriptive programming :
InvokeApplication  "D:\Program Files\HP\QuickTest Professional\samples\flight\app\flight3a"
Dialog("Class Name:= Dialog","text:=Login").Winedit("Class Name:=WinEdit","attached text:=Agent Name:").Set "2039"
Dialog("Class Name:= Dialog","text:=Login").Winedit("Class Name:=WinEdit","attached text:=Password:").Setsecure "4ceb5e5216db248fd801b9d8e2364301e4bafec6"


This is how we do descriptive programming to automate the stable working features of an application. Do always take care of the hierarchy of the application.

Handling Regular Expression In QTP

What is : A regular expression is a pattern of text that consists of ordinary characters (for example, letters a through z) and special characters, known as metacharacters. The pattern describes one or more strings to match when searching a body of text. The regular expression serves as a template for matching a character pattern to the string being searched.
Here are some examples of regular expression you might encounter:
JScript VBScript Matches
/^\[ \t]*$/ "^\[ \t]*$" Match a blank line.
/\d{2}-\d{5}/ "\d{2}-\d{5}" Validate an ID number consisting of 2 digits, a hyphen, and another 5 digits.
/<(.*)>.*<\/\1>/ "<(.*)>.*<\/\1>" Match an HTML tag.
The following table contains the complete list of metacharacters and their behavior in the context of regular expressions:
Character Description
\ Marks the next character as either a special character, a literal, a backreference, or an octal escape. For example, 'n' matches the character "n". '\n' matches a newline character. The sequence '\\' matches "\" and "\(" matches "(".
^ Matches the position at the beginning of the input string. If the RegExp object's Multiline property is set, ^ also matches the position following '\n' or '\r'.
$ Matches the position at the end of the input string. If the RegExp object's Multiline property is set, $ also matches the position preceding '\n' or '\r'.
* Matches the preceding subexpression zero or more times. For example, zo* matches "z" and "zoo". * is equivalent to {0,}.
+ Matches the preceding subexpression one or more times. For example, 'zo+' matches "zo" and "zoo", but not "z". + is equivalent to {1,}.
? Matches the preceding subexpression zero or one time. For example, "do(es)?" matches the "do" in "do" or "does". ? is equivalent to {0,1}
{n} n is a nonnegative integer. Matches exactly n times. For example, 'o{2}' does not match the 'o' in "Bob," but matches the two o's in "food".
{n,} n is a nonnegative integer. Matches at least n times. For example, 'o{2,}' does not match the "o" in "Bob" and matches all the o's in "foooood". 'o{1,}' is equivalent to 'o+'. 'o{0,}' is equivalent to 'o*'.
{n,m} m and n are nonnegative integers, where n <= m. Matches at least n and at most m times. For example, "o{1,3}" matches the first three o's in "fooooood". 'o{0,1}' is equivalent to 'o?'. Note that you cannot put a space between the comma and the numbers.
? When this character immediately follows any of the other quantifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible. For example, in the string "oooo", 'o+?' matches a single "o", while 'o+' matches all 'o's.
. Matches any single character except "\n". To match any character including the '\n', use a pattern such as '[.\n]'.
(pattern) Matches pattern and captures the match. The captured match can be retrieved from the resulting Matches collection, using the SubMatches collection in VBScript or the $0$9 properties in JScript. To match parentheses characters ( ), use '\(' or '\)'.
(?:pattern) Matches pattern but does not capture the match, that is, it is a non-capturing match that is not stored for possible later use. This is useful for combining parts of a pattern with the "or" character (|). For example, 'industr(?:y|ies) is a more economical expression than 'industry|industries'.
(?=pattern) Positive lookahead matches the search string at any point where a string matching pattern begins. This is a non-capturing match, that is, the match is not captured for possible later use. For example 'Windows (?=95|98|NT|2000)' matches "Windows" in "Windows 2000" but not "Windows" in "Windows 3.1". Lookaheads do not consume characters, that is, after a match occurs, the search for the next match begins immediately following the last match, not after the characters that comprised the lookahead.
(?!pattern) Negative lookahead matches the search string at any point where a string not matching pattern begins. This is a non-capturing match, that is, the match is not captured for possible later use. For example 'Windows (?!95|98|NT|2000)' matches "Windows" in "Windows 3.1" but does not match "Windows" in "Windows 2000". Lookaheads do not consume characters, that is, after a match occurs, the search for the next match begins immediately following the last match, not after the characters that comprised the lookahead.
x|y Matches either x or y. For example, 'z|food' matches "z" or "food". '(z|f)ood' matches "zood" or "food".
[xyz] A character set. Matches any one of the enclosed characters. For example, '[abc]' matches the 'a' in "plain".
[^xyz] A negative character set. Matches any character not enclosed. For example, '[^abc]' matches the 'p' in "plain".
[a-z] A range of characters. Matches any character in the specified range. For example, '[a-z]' matches any lowercase alphabetic character in the range 'a' through 'z'.
[^a-z] A negative range characters. Matches any character not in the specified range. For example, '[^a-z]' matches any character not in the range 'a' through 'z'.
\b Matches a word boundary, that is, the position between a word and a space. For example, 'er\b' matches the 'er' in "never" but not the 'er' in "verb".
\B Matches a nonword boundary. 'er\B' matches the 'er' in "verb" but not the 'er' in "never".
\cx Matches the control character indicated by x. For example, \cM matches a Control-M or carriage return character. The value of x must be in the range of A-Z or a-z. If not, c is assumed to be a literal 'c' character.
\d Matches a digit character. Equivalent to [0-9].
\D Matches a nondigit character. Equivalent to [^0-9].
\f Matches a form-feed character. Equivalent to \x0c and \cL.
\n Matches a newline character. Equivalent to \x0a and \cJ.
\r Matches a carriage return character. Equivalent to \x0d and \cM.
\s Matches any whitespace character including space, tab, form-feed, etc. Equivalent to [ \f\n\r\t\v].
\S Matches any non-white space character. Equivalent to [^ \f\n\r\t\v].
\t Matches a tab character. Equivalent to \x09 and \cI.
\v Matches a vertical tab character. Equivalent to \x0b and \cK.
\w Matches any word character including underscore. Equivalent to '[A-Za-z0-9_]'.
\W Matches any nonword character. Equivalent to '[^A-Za-z0-9_]'.
\xn Matches n, where n is a hexadecimal escape value. Hexadecimal escape values must be exactly two digits long. For example, '\x41' matches "A". '\x041' is equivalent to '\x04' & "1". Allows ASCII codes to be used in regular expressions.
\num Matches num, where num is a positive integer. A reference back to captured matches. For example, '(.)\1' matches two consecutive identical characters.
\n Identifies either an octal escape value or a backreference. If \n is preceded by at least n captured subexpressions, n is a backreference. Otherwise, n is an octal escape value if n is an octal digit (0-7).
\nm Identifies either an octal escape value or a backreference. If \nm is preceded by at least nm captured subexpressions, nm is a backreference. If \nm is preceded by at least n captures, n is a backreference followed by literal m. If neither of the preceding conditions exists, \nm matches octal escape value nm when n and m are octal digits (0-7).
\nml Matches octal escape value nml when n is an octal digit (0-3) and m and l are octal digits (0-7).
\un Matches n, where n is a Unicode character expressed as four hexadecimal digits. For example, \u00A9 matches the copyright symbol (©).

Handle Escape characters In QTP

What are  metacharacters that require special treatment when trying to match them. To match these special characters, you must first escape those characters, that is, precede them with a backslash character (\). The following table shows those special characters and their meanings:

Special Character Comment
$ Matches the position at the end of an input string. If the RegExp object's Multiline property is set, $ also matches the position preceding '\n' or '\r'. To match the $ character itself, use \$.
( ) Marks the beginning and end of a subexpression. Subexpressions can be captured for later use. To match these characters, use \( and \).
* Matches the preceding subexpression zero or more times. To match the * character, use \*.
+ Matches the preceding subexpression one or more times. To match the + character, use \+.
. Matches any single character except the newline character \n. To match ., use \.
[ Marks the beginning of a bracket expression. To match [, use \[.
? Matches the preceding subexpression zero or one time, or indicates a non-greedy quantifier. To match the ? character, use \?.
\ Marks the next character as either a special character, a literal, a backreference, or an octal escape. For example, 'n' matches the character 'n'. '\n' matches a newline character. The sequence '\\' matches "\" and '\(' matches "(".
^ Matches the position at the beginning of an input string except when used in a bracket expression where it negates the character set. To match the ^ character itself, use \^.
{ Marks the beginning of a quantifier expression. To match {, use \{.
| Indicates a choice between two items. To match |, use \|.