UFT Class 37

UFT Class 37

(Recovery Scenarios Part-2, Regular Expressions)

‘Handle Test Run Error

On Error Resume Next
VbWindow(“Form1”).Activate
VbWindow(“Form1”).VbComboBox(“Combo1”).Select “Chennai”
VbWindow(“Form1”).VbComboBox(“Combo1”).Select “Goa”
VbWindow(“Form1”).VbComboBox(“Combo1”).Select “Hyderabad”
VbWindow(“Form1”).VbComboBox(“Combo1”).Select “New Delhi”
VbWindow(“Form1”).VbComboBox(“Combo1”).Select “Mumbai”

‘Handle Object state

Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinButton(“Button”).Click
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set DataTable(1, 1)
OrdNo = Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).GetROProperty(“text”)
If OrdNo =”” Then
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set 1
End If
wait 2
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click
————————————————–
If Application Crash scenario is there then use Restart MS Windows recovery operation.

Regular Expressions in UFT

Regular Expressions

It is a formula for matching patterns.

Constant matching

india.doc – india.doc

Pattern matching

i*.
ia……..
ib……….
.
.
india.doc
———————–
Usage of Regular expressions in UFT:

i) To handle dynamic objects

If it is Object Repository based Test then open the object repository, select the object
and provide Regular expression.

If it is Descriptive programming provide Regular expression directly in the Test script.
————————————–
Example:

For i = 1 To 5
Window(“Flight Reservation”).Activate
Window(“Flight Reservation”).WinButton(“Button”).Click
Window(“Flight Reservation”).Dialog(“Open Order”).WinCheckBox(“Order No.”).Set “ON”
Window(“Flight Reservation”).Dialog(“Open Order”).WinEdit(“Edit”).Set i
Window(“Flight Reservation”).Dialog(“Open Order”).WinButton(“OK”).Click
Window(“Flight Reservation”).WinMenu(“Menu”).Select “File;Fax Order…”
Window(“Flight Reservation”).Dialog(“text:=Fax Order No. [1-5]”).Activate
Window(“Flight Reservation”).Dialog(“text:=Fax Order No. [1-5]”).ActiveX(“progid:=MSMask.MaskEdBox.1”).Type “1111111111”
Window(“Flight Reservation”).Dialog(“text:=Fax Order No. [1-5]”).WinButton(“text:=&Send”).Click
Next

ii) For search operations

Regular Expression Object

Using New and RegExp we can create Regular Expression Object.

Syntax:

Set Variable = New RegExp

‘Count how many times the word “UFT” appeared in a text file.

Dim objFso, objTextstream, objRegEx, myContent, matches
Set objFso = CreateObject(“Scripting.FileSystemObject”)
Set objTextstream = objFso.OpenTextFile(“C:\Users\gcreddy\Desktop\xyz.txt”)
Set objRegEx = New RegExp
myContent = objTextstream.ReadAll
‘Msgbox myContent

objRegEx.pattern =”UFT”
objRegEx.IgnoreCase = True ‘To consider upper and lower case values
objRegEx.Global = True ‘To find all matches

Set matches = objRegEx.execute(myContent)
msgbox matches.count

Set objRegEx = Nothing
objTextstream.Close
Set objTextstream = Nothing
Set objfso = Nothing

‘Count how many times the word “UFT” appeared in a word document.

Dim objWord, objDoc, objRegEx, myContent, matches
Set objWord = CreateObject(“Word.Application”)
Set objDoc= objWord.Documents.Open (“C:\Users\gcreddy\Desktop\abc.docx”)
Set objRegEx = New RegExp
myContent = objDoc.content
‘Msgbox myContent

objRegEx.pattern =”UFT”
objRegEx.IgnoreCase = True ‘To consider upper and lower case values
objRegEx.Global = True ‘To find all matches

Set matches = objRegEx.execute(myContent)
msgbox matches.count

Set objRegEx = Nothing
objDoc.Close
objWord.Quit
Set objDoc = Nothing
Set objWord = Nothing

‘Create Word document

Dim objWord
Set objWord = CreateObject(“Word.Application”)
objWord.Documents.Add
objWord.Visible = True
objWord.ActiveDocument.SaveAs “C:\Users\gcreddy\Desktop\Sample.docx”
objWord.Quit
Set objWord = Nothing
————————————-
Error handling in UFT,
On Error Resume Next,
Regular expression object,
Regular expressions in UFT,
Software Testing using UFT,
VBScript for UFT,
VBScript Word Application object

Follow me on social media: