UFT Scripts

 UFT Script Examples

1) Count how many times the word "UFT" appeared in a text file using Regular expression Object

Dim objFso, objTextstream, objRegEx, matches, myContent

Set objFso = CreateObject("Scripting.FileSystemObject")
Set objTextstream = objFso.OpenTextFile("C:\Users\SAMEE\Desktop\gcreddy.txt")

myContent = objTextstream.ReadAll

Set objRegEx = New RegExp
objRegEx.pattern = "UFT"

objRegEx.IgnoreCase = True 'To ignore cases

objRegEx.Global = True 'To find all matches

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

objTextstream.Close
Set objRegEx = Nothing
Set objTextstream = Nothing
Set objFso = Nothing
-----------------------------------------------------
2) Count how many times the word "UFT" appeared in a word document
Dim objWord, objDoc, objRegEx, matches, myContent

Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.open ("C:\Users\SAMEE\Desktop\gcreddy.doc")

myContent = objDoc.Content

Set objRegEx = New RegExp
objRegEx.pattern = "UFT"

objRegEx.IgnoreCase = True 'To ignore cases

objRegEx.Global = True 'To find all matches

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

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

-----------------------------------------------------
3) Find specific pattern without Regular Expression object and also irrespective of any specific delimiter pattern...

Dim objFSO, objTextStream, matches, myContent, match

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile("C:\Users\SAMEE\Desktop\gcreddy.txt")

myContent = objTextStream.ReadAll

mySplit = Split(myContent, " ")
match = 0
For i = LBound(mySplit) To UBound(mySplit)

If  InStr(1,UCase(mySplit(i)),"UFT",1) > 0 Then
match = match + 1
End If

Next

If match > 0 Then

    msgbox "Total no of matches found are: " & match
    Else
    msgbox "Total no of matches found are: 0"

End If

objTextStream.Close

Set objTextStream = Nothing
Set objFSO = Nothing

4) Verify the Total in Flight Reservation, where Total = Tickets * Price
and export the values to excel file


'*************************************************************
' Test Name: Verify the Total in Flight Reservation

'Author: abcd

'Date of Creation: 29th April 2014

'Date of Modification: NA

'Pre-requasites:
'login.tsr, abc.vbs

'Steps:
'launch the application
'Login Operation
'Open an Order and capture Tickets, price and Total values
'Form Loop structure in order to open 1 to 10 orders
'convert the values and compare if the Total = Tickets * price or not?
'Close Application
'*************************************************************
Option Explicit
Dim Tickets, price, Total, i, objExcel, objWorkbook, objWorksheet, Result
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\Users\SAMEE\Desktop\gcreddy.xls")
Set objWorksheet= objWorkbook.Worksheets(1)

objWorksheet.Cells(1, 1) = "OrderNo"
objWorksheet.Cells(1, 2) = "Tickets"
objWorksheet.Cells(1, 3) = "Price"
objWorksheet.Cells(1, 4) = "Total"
objWorksheet.Cells(1, 5) = "Result"
'Login Operation
If Not Dialog("Login").exist(3) Then
SystemUtil.Run "C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If

Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "asdf"
Dialog("Login").WinEdit("Password:").SetSecure "535f0a621f5e41566c612a7cd3ba0d7548aac750"
Dialog("Login").WinButton("OK").Click

For i = 1 To 10 Step 1
'Open Order
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

'capture the values
Tickets = Window("Flight Reservation").WinEdit("Tickets:").GetROProperty("text")
Price = Window("Flight Reservation").WinEdit("Price:").GetVisibleText()
Total = Window("Flight Reservation").WinEdit("Total:").GetROProperty("text")

'Convert the values and compare

If cdbl(Total) = Cint(Tickets) * Cdbl(Price) Then
    Reporter.ReportEvent 0, "Res1", "Total is Correct"
    Else
    Reporter.ReportEvent 1, "Res1", "Total is InCorrect"
End If
Result = Cint(Tickets) * Cdbl(Price)
objWorksheet.Cells(i + 1, 1) = i
objWorksheet.Cells(i + 1, 2) = Cint (Tickets)
objWorksheet.Cells(i + 1, 3) = Cdbl (Price)
objWorksheet.Cells(i + 1, 4) = Cdbl (Total)
objWorksheet.Cells(i + 1, 5) = Result
Next
Window("Flight Reservation").Close
objWorkbook.Save
objexcel.Quit
Set objWorksheet = Nothing
Set objWorkbook = Nothing
Set objExcel = nothing
--------------------------------------------
5) Verify the Cancel operation in Flight Reservation Application (* It is UFT Tool sample Application)

'Before entering any data, After entering Agent name, and After entering Agent name
'and Password, if user selects "Cancel" button then Login Dialog box should be dissapeared.
'---------------------------------------------------------------------
'Before enter any Data
SystemUtil.Run "C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinButton("Cancel").Click

If Not Dialog("Login").Exist(3) Then
    Reporter.ReportEvent micPass, "Res1", "Login Dialog Dissappeared"
    Verify1 = "Passed"
    Else
    Reporter.ReportEvent 1, "Res1", "Login Exist"
End If

If Not Dialog("Login").Exist (3) Then
SystemUtil.Run "C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If

'After entering Agent name
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinButton("Cancel").Click

If Not Dialog("Login").Exist(3) Then
    Reporter.ReportEvent micPass, "Res2", "Login Dialog Dissappeared"
    Verify2 = "Passed"
    Else
    Reporter.ReportEvent 1, "Res2", "Login Exist"
End If

If Not Dialog("Login").Exist (3) Then
SystemUtil.Run "C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
End If

'After entering Agent name and password
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "536045abedefbc3ab3e5aa2ad9e035efafcf609d"
Dialog("Login").WinButton("OK").Click

If Not Dialog("Login").Exist(3) Then
    Reporter.ReportEvent micPass, "Res3", "Login Dialog Dissappeared"
    Verify3 = "Passed"
    Else
    Reporter.ReportEvent 1, "Res3", "Login Exist"
End If

If Verify1 = "Passed"  And Verify2 = "Passed" And Verify3 ="Passed" Then
    Reporter.ReportEvent 0, "TestResult", "Test Passed"
    Else
    Reporter.ReportEvent 1, "TestResult", "Test Failed"
End If

Window("Flight Reservation").Close
----------------------------------------------------------
6) Verify "Fly From:" and "Fly To:" Combo boxes in Flight Reservation (Many to many Comparison)

'Select items one by one from "Fly From:" Combo box and verify weather that item available or not in "Fly To:" Combo box

Dim From_Item, To_Item, From_Count, To_Count, i, j

If Not Window("Flight Reservation").exist(3) Then
SystemUtil.Run "C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4a.exe"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set "abcd"
Dialog("Login").WinEdit("Password:").SetSecure "53604b7fda78f02f1d0d736d3c971a1098157e1f"
Dialog("Login").WinButton("OK").Click
End If

Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").ActiveX("MaskEdBox").Type "111115"

From_Count= Window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount
'Msgbox From_Count
Steps=0
For i = 0 To From_Count -1 Step 1
    Window("Flight Reservation").WinComboBox("Fly From:").Select(i)
    From_Item= Window("Flight Reservation").WinComboBox("Fly From:").GetROProperty("text")

To_Count = Window("Flight Reservation").WinComboBox("Fly To:").GetItemsCount
For j = 0 To To_Count-1 Step 1
    Window("Flight Reservation").WinComboBox("Fly To:").Select(j)
    To_Item = Window("Flight Reservation").WinComboBox("Fly To:").GetROProperty("text")
  
If From_Item <> To_Item Then
    Reporter.ReportEvent micPass, "Res1","Step Passed"
    Steps= Steps + 1
    TestResult = 0
    Else
    Reporter.ReportEvent micFail, "Res1","Step failed"
    TestResult = 1
    Exit For
End If  
Next
Next

If TestResult = 0 Then
    Reporter.ReportEvent micPass, "Steps Result  " & Steps &" Passed" & "  Testresult","  Test Passed"
    else
    Reporter.ReportEvent micFail, "Testresult","Test Failed"
End If

Window("Flight Reservation").Close
-----------------------------------------

0 comments:

Post a Comment