Showing posts with label QTP - Regular Expressions - Complete Reference. Show all posts
Showing posts with label QTP - Regular Expressions - Complete Reference. Show all posts
9:13 AM
GAReddy
1
QTP - Regular Expressions - Complete Reference
QTP @ VBScript (Part 4)
Regular Expressions
Regular Expression is a string that describes or matches a set of strings
A regular expression is a way of expressing a text pattern for the purpose of matching a string or part of a string. Regular expressions are often used either to extract information from a string or to verify that a string is of the correct format
A regular expression is a string that specifies a complex search phrase.
Regular expressions enable QTP to identify objects and text strings with varying values
By using special characters you define the conditions of the search.
We can use this regular expression when we want to test for specific range of object properties
Test for a pattern within a string. For example, you can test an input string to see if a telephone number pattern or a credit card number pattern occurs within the string. This called data validation.
Replace text. You can use a regular expression to identify specific text in a document and either remove it completely or replace it with other text.
Extract a substring from a string based upon a pattern match. You can find specific text within a document or input field
In QTP , Regular Expressions can be used in 4 places:
· Object Repository
· CheckPoints
· RegExp object.
· Data Validations
Eleven characters with special meanings: the opening square bracket [, the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening round bracket ( and the closing round bracket ). These special characters are often called "metacharacters".
If you want to use any of these characters as a literal in a regex, you need to escape them with a backslash. If you want to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign will have a special meaning
Character Classes or Character Sets
A "character class" matches only one out of several characters. To match an a or an e, use [ae]. You could use this in gr[ae]y to match either gray or grey.
A character class matches only a single character. gr[ae]y will not match graay, graey or any such thing. The order of the characters inside a character class does not matter.
You can use a hyphen inside a character class to specify a range of characters. [0-9] matches a single digit between 0 and 9. You can use more than one range. [0-9a-fA-F] matches a single hexadecimal digit, case insensitively. You can combine ranges and single characters. [0-9a-fxA-FX] matches a hexadecimal digit or the letter X.
Typing a caret after the opening square bracket will negate the character class.
The result is that the character class will match any character that is not in the character class. q[^x] matches qu in question. It does not match Iraq since there is no character after the q for the negated character class to match.
Shorthand Character Classes
\d matches a single character that is a digit, \w matches a "word character“ (alphanumeric characters plus underscore), and \s matches a whitespace character (includes tabs and line breaks). The actual characters matched by the shorthands depends on the software you're using. Usually, non-English letters and numbers are included.
The Dot Matches (Almost) Any Character
The dot matches a single character, except line break characters. It is short for [^\n] (UNIX regex flavors) or [^\r\n] (Windows regex flavors). Most regex engines have a "dot matches all" or "single line" mode that makes the dot match any single character, including line breaks. gr.y matches gray, grey, gr%y, etc. Use the dot sparingly. Often, a character class or negated character class is faster and more precise.
Anchors
Anchors do not match any characters. They match a position. ^ matches at the start of the string, and $ matches at the end of the string. Most regex engines have a "multi-line" mode that makes ^ match after any line break, and $ before any line break. E.g. ^b matches only the first b in bob. \b matches at a word boundary. A word boundary is a position between a character that can be matched by \w and a character that cannot be matched by \w. \b also matches at the start and/or end of the string if the first and/or last characters in the string are word characters. \B matches at every position where \b cannot match
Alternation
Alternation is the regular expression equivalent of "or". cat|dog will match cat in About cats and dogs. If the regex is applied again, it will match dog. You can add as many alternatives as you want, e.g.: cat|dog|mouse|fish.
Alternation is also good to test multilingual applications i.e. We a button Yes in English, Si in Spanish, Oui in French, Ja in Denish or German, we can use the next regular expression Yes|Si|Oui|Da|Ja
Repetition
The question mark makes the preceding token in the regular expression optional. E.g.: colou?r matches colour or color
The asterisk or star tells the engine to attempt to match the preceding token zero or more times. The plus tells the engine to attempt to match the preceding token once or more.
<[A-Za-z][A-Za-z0-9]*> matches an HTML tag without any attributes. <[A-Za-z0-9]+> is easier to write but matches invalid tags such as <1>.
Use curly braces to specify a specific amount of repetition. Use [1-9][0-9]{3} to match a number between 1000 and 9999. [1-9][0-9]{2,4} matches a number between 100 and 99999.
Regexp Object
The RegExp object provides support for regular expression matching; for the ability to search strings for substrings matching general or specific patterns.
In order to conduct a pattern search, you must first instantiate the regular expression object, with code like the following:
Dim oRegExp ' Instance of RegExp object
Set oRegExp = New RegExp
'Execute Method
'####################################################
' @ Executing a regular expression to find text within a string.
'####################################################
MsgBox RegularExpExample("QTP.", "QuickTestQTP, by GAReddy and QuickTestQTP is qtp's blog")
' =============================================================
' @Function:RegularExpExample
' @Desc : Using regular expression to find text within a string
' @Params : strPattern is the regular expression
' strString is the string to use the expression on
' @Returns : An example string showing the results of the search
' =============================================================
Function RegularExpExample(strPattern, strString)
Dim objRegEx, strMatch, strMatches
Dim strRet
' create regular expression object
Set objRegEx = New RegExp
' set the pattern
objRegEx.Pattern = strPattern
' set it be not case sensitive
objRegEx.IgnoreCase = True
' set global flag =true sothat we search all of the string, instead of just searching for the first occurrence
objRegEx.Global = True
' execute search
Set strMatches = objRegEx.Execute(strString)
' for each match
For Each strMatch in strMatches
strRet = strRet & "Match found at position '" & _
strMatch.FirstIndex & "' - Matched Value is '" & _
strMatch.Value & "'" & vbCRLF
Next
RegularExpExample = strRet
End Function ' RegularExpExample
'Test Method
'#################################################################
' @Using Locate to determine if specific text exists within a string.
'#################################################################
MsgBox LocateText("www.QuickTestQTP.blogpsot.com", "QTP")
MsgBox LocateText("www.QuickTestQTP.blogpsot.com", "QTP.*.com")
' =============================================================
' @Function:LocateText
' @Desc : Uses a regular expression to locate text within a string
' @Params : strString is the string to perform the search on
' strPattern is the regular expression
' @Returns : True if the pattern was found, False otherwise
' =============================================================
Function LocateText(strString, strPattern)
Dim objRegEx
' create the regular expression
Set objRegEx = New RegExp
' set the pattern
objRegEx.Pattern = strPattern
' ignore the casing
objRegEx.IgnoreCase = True
' perform the search
LocateText = objRegEx.Test(strString)
' destroy the object
Set objRegEx = Nothing
End Function ' LocateText
'Replace Method
'#################################################################
'@Using the replace method to find and replace text in a string.
'#################################################################
MsgBox ReplaceText("QuickTest QTP: Learning QTP is easy .", "easy.", "easiest")
MsgBox ReplaceText("QTP seems to be easy .Just look here, everything else about QTP exists: but implementation is HARD...!","but.*","!")
' =============================================================
' @Function: ReplaceText
' @Desc : Uses a regular expression to replace text within a string
' @Params : strString is the string to perform the replacement on
' strPattern is the regular expression
' strReplacement is the replacement string
' @Returns : The finished string
' =============================================================
Function ReplaceText(strString, strPattern, strReplacement)
Dim objRegEx
' create the regular expression
Set objRegEx = New RegExp
' set the pattern
objRegEx.Pattern = strPattern
' ignore the casing
objRegEx.IgnoreCase = True
' make the replacement
ReplaceText = objRegEx.Replace(strString, strReplacement)
' destroy the object
Set objRegEx = Nothing
End Function ' ReplaceText
Thank you.
QTP – VBScript Part4 - Done.
Thank you.
For QTP and More:
Contact:
G A Reddy
http://QuickTestQTP.blogspot.com
QTP – VBScript (Part 1)
QTP – VBScript (Part 2)
QTP – VBScript (Part 3)
QTP – VBScript (Part 4)
QTP – VBScript (Part 5)
QTP – VBScript (Part 6)
QTP – VBScript (Part 7)
QTP – VBScript (Part 8)
QTP – VBScript Examples (Part9)
QTP – VBScript Examples (Part10)
QTP – Arrays
QTP – Error Handling
QTP – Functions
QTP – Frameworks
QTP – MORE….
To be Continued…
For more info
Contact@
G A Reddy
QuickTest QTP
http://QuickTestQTP.BlogSpot.com
GAReddy @ OneTestingCenter @ All Articles
- Ad-hoc Testing
- Automation Framework
- Basics of QTP
- Core Testing FAQs
- Download QTP - Preseenations
- Framework Guide
- Introduction to Testing
- ISTQB Foundation Level Exam Papers
- ISTQB Foundation Level Exam Sample Paper - I
- ISTQB Foundation Level Exam Sample Paper - II
- ISTQB Foundation Level Exam Sample Paper - III
- Keyword Driven Framework
- Keyword Driven Framework Complete Guide
- Keyword Framework Complete Guide
- Load
- Load Runner - Components
- Load Runner - Load Testing Process
- Load Testing - LoadRunner Correlation
- Load Testing Process
- Monkey Testing and Exploratory Testing
- Most Relevant Features and Benefits
- OneTestingCenter - Manual Testing - Learning Table
- Performance
- Performance Test - Short Notes
- Practical Guide to Keyword Driven Framework
- Programming Language / Scripting language / Markup languages / Operating Systems
- QTP QTP Learning Let's Learn QTP QTP Easy Learning QTP Guide QTP Book QTP Learning PDF QTP - Fundamentals QTP - Advanced QTP - Topic by Topic QTP Lessons GAReddy - QTP
- QTP - ActionDriven Framework Demo1
- QTP - Actions
- QTP - Application Relationship - Video
- QTP - Array Library Functions
- QTP - Automation Startup - Video
- QTP - Certification Q's1
- QTP - Certification Q's2
- QTP - Certification Q's3
- QTP - Data Tables
- QTP - DataTables - Video
- QTP - Descriptive Programing - Dynamic Object Repository Creation
- QTP - Descriptive Programming
- QTP - Descriptive Programming - Any Web App - Working with all Objects
- QTP - Descriptive Programming - Any Web App - Working with Web List-boxes
- QTP - Descriptive Programming - Broken Link Checking
- QTP - Descriptive Programming - Working with Any Web App
- QTP - Dictionary Object - Creating a Dictionary Object
- QTP - Dictionary Object - Add Method
- QTP - Dictionary Object - Items
- QTP - Dictionary Object - KeyExists
- QTP - Dictionary Object - Keys
- QTP - Dictionary Object - Remove Method
- QTP - Dictionary Object - RemoveAll Method
- QTP - Dictionary Object - Using Dictionary Values As Variables
- QTP - Environment Variables
- QTP - Excel - Excel Comparison
- QTP - Excel Comparision
- QTP - Files - Files Comparison
- QTP - Files Comparision
- QTP - Files Comparison
- QTP - FSO (PART A)
- QTP - FSO (PART B)
- QTP - Getting Object Properties Dynamically
- QTP - GetTOProperties / GetTOProperty / SetTOProperty Demo
- QTP - GetTOProperties Script Demo
- QTP - GetTOProperty Script Demo
- QTP - InputBox
- QTP - Keyword Driven Automation Framework - Video
- QTP - Keyword Driven Framework - Complete Guide
- QTP - Keyword Driven Framework - Complete Guide - Video
- QTP - Keyword Driven Framework - Step by Step Guide
- QTP - Microsoft Office - Word
- QTP - MsgBox
- QTP - Objects Classifications
- QTP - Overview
- QTP - Pass ByRef and Pass ByVal
- QTP - PDFs
- QTP - Recording Modes
- QTP - Recovery Scenario Manager
- QTP - Regular Expressions - Complete Reference
- QTP - Regular Expressions - Scripts
- QTP - Reporter Utility
- QTP - Reporter Utility - Scripts
- QTP - SetTOProperty Script Demo
- QTP - Synchronization
- QTP - Synchronization - Script Demo
- QTP - Synchronization Methods
- QTP - Synchronization Script
- QTP - Test / Action Template
- QTP - VBScript - Array Sorting
- QTP - VBScript - Dictionary Object
- QTP - VBScript and Data Types
- QTP - VBScript Functions - One Reference
- QTP - Videos
- QTP - Ways to synchronize
- QTP – Descriptive Programing – Any Web App - Working with Web Check Boxes
- QTP – Descriptive Programing – Examples
- QTP – Outlook Application
- QTP – Regular Expressions
- QTP – Web Tables
- QTP 10 Supports Windows 7 and IE8
- QTP Basics
- QTP Boks
- QTP Books
- QTP Complete Learning Table
- QTP Easy Learning
- QTP for Beginners
- QTP Info
- QTP Introduction
- QTP Learning
- QTP Learning MadeEasy. QTP QTP Learning Let's Learn QTP QTP Easy Learning QTP Guide QTP Book QTP Learning PDF QTP - Fundamentals QTP - Advanced QTP - Topic by Topic QTP Lessons GAReddy - QTP
- QTP Learning Materials
- QTP Simple
- QTP Videos
- Requirements Flow
- Roles and Responsibilities of Testers
- Software Testing - Core Testing Definitions
- Software Testing - FAQs
- Software Testing - Testing Methodologies
- Software Testing - Testing Process
- Software Testing Glossary : QA - Testing All in One
- Software Testing Process
- Stress Testing Requirements
- Stress testings
- Stress Testings - Why
- Test Case - Test Case Design Techniques
- Test Case - What is Test Case
- Test Case - What should a Test Case contain
- Test Case Designing Techniques
- Testing - Daily Status Report
- Testing - Defect - Defect Documenting
- Testing - Defect - Defect Life Cycle
- Testing - Defect - What is a Bug (Defect)
- Testing - Defect – Metrics
- Testing - Defect – Priority Levels
- Testing - Defect – Severity Levels
- Testing - Important FAQs
- Testing - Load Testing - Performance Testing - Stress Testing
- Testing - Requirements Flow
- Testing - UAT - Alpha Testing and Beta Testing
- Testing - Verification and Validation
- Testing Definitions
- Testing Methodologies
- Testing Terminologies
- VB Script Features
- What is Testing?
- When does the Testing begin?
- When does the Testing end?
- Why do we need Testing?
- Why does software have bugs?










