While reading the Putty output from QTP/UFT through "getVisibleText" method, it is observed sometime that it may not recognize the text properly due to various reasons. So to read the exact output of Putty here is the solution.
Choose the Logging option from putty, set to log to write "All session output". Store all the session output in a file and Search for the required text from this file. From putty, Also choose option "Always Overwrite it" to avoid popups while running our QTP script.
Here is the QTP/UFT code to do above settings, Login to putty, execute few commands and close the Putty and search for the required text from the saved file.
Note: Please add the below all properties to Object repository (Its simple, it won't take more than 10min)
Public Function startPutty()
Dim SettingsFile,strHost,strLoginUser,strPassword,strPort, strPuttyPath
strHost="10.11.12.13"
strLoginUser="User03"
strPassword = "Password"
strPort=22
'Here the Putty Path
strPuttyPath="C:\PuTTY\putty.exe"
'Start Putty
SystemUtil.Run strPuttyPath
Wait(2)
'Doing settings to save the PuTTY output to a file.
Window("PuttyConfig").WinTreeView("Category:").Select "Session;Logging"
Window("PuttyConfig").WinRadioButton("All session output").Set 'Provide Any Path, Use the same path while reading
Window("PuttyConfig").WinEdit("Log file name:").Set "C:\PuTTY\putty.log"
Window("PuttyConfig").WinRadioButton("Always overwrite it").Set
Window("PuttyConfig").WinTreeView("Category:").Select "Session"
Window("PuttyConfig").WinRadioButton("SSH").Set
Wait(2)
Window("PuttyConfig").WinEdit("HostName").Set strHost
Wait(1)
Window("PuttyConfig").WinEdit("Port").Set strPort
Window("PuttyConfig").WinButton("Open").Click
Wait(3)
Window("PuTTY").Maximize
Window("PuTTY").Type strLoginUser
Window("PuTTY").Type micReturn
Wait(3)
Window("PuTTY").Type strPassword
Window("PuTTY").Type micReturn
Window("PuTTY").Type "ls -lrt *.sh"
Window("PuTTY").Type micReturn
Window("PuTTY").Type "exit"
Window("PuTTY").Type micReturn
If window("PuTTY").Exist(0) Then
Window("PuTTY").Close
Window("PuTTY").Dialog("PuTTY Exit Confirmation").WinButton("OK").Click
End If
searchPuttyOutput "createSimulatorFiles.sh"
End Function
Public Function searchPuttyOutput(stringToBeSearched)
'In Debug mode if we stop the script without setting the below 2 parameters to Nothing, It gives error in next run. So Added below 2 lines to avoid unnecessary errors.
Set qfile=nothing
Set fso=nothing
Set fso=createobject("Scripting.FileSystemObject")
Set qfile=fso.OpenTextFile("C:\PuTTY\putty.log",1,True)
'Read the entire contents of priously written file
If Instr(qfile.ReadAll,stringToBeSearched) > 0 Then
MsgBox "String Found :)"
Else
MsgBox "String Not Found :("
End If
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing End Function
Choose the Logging option from putty, set to log to write "All session output". Store all the session output in a file and Search for the required text from this file. From putty, Also choose option "Always Overwrite it" to avoid popups while running our QTP script.
Here is the QTP/UFT code to do above settings, Login to putty, execute few commands and close the Putty and search for the required text from the saved file.
Note: Please add the below all properties to Object repository (Its simple, it won't take more than 10min)
Public Function startPutty()
Dim SettingsFile,strHost,strLoginUser,strPassword,strPort, strPuttyPath
strHost="10.11.12.13"
strLoginUser="User03"
strPassword = "Password"
strPort=22
'Here the Putty Path
strPuttyPath="C:\PuTTY\putty.exe"
'Start Putty
SystemUtil.Run strPuttyPath
Wait(2)
'Doing settings to save the PuTTY output to a file.
Window("PuttyConfig").WinTreeView("Category:").Select "Session;Logging"
Window("PuttyConfig").WinRadioButton("All session output").Set 'Provide Any Path, Use the same path while reading
Window("PuttyConfig").WinEdit("Log file name:").Set "C:\PuTTY\putty.log"
Window("PuttyConfig").WinRadioButton("Always overwrite it").Set
Window("PuttyConfig").WinTreeView("Category:").Select "Session"
Window("PuttyConfig").WinRadioButton("SSH").Set
Wait(2)
Window("PuttyConfig").WinEdit("HostName").Set strHost
Wait(1)
Window("PuttyConfig").WinEdit("Port").Set strPort
Window("PuttyConfig").WinButton("Open").Click
Wait(3)
Window("PuTTY").Maximize
Window("PuTTY").Type strLoginUser
Window("PuTTY").Type micReturn
Wait(3)
Window("PuTTY").Type strPassword
Window("PuTTY").Type micReturn
Window("PuTTY").Type "ls -lrt *.sh"
Window("PuTTY").Type micReturn
Window("PuTTY").Type "exit"
Window("PuTTY").Type micReturn
If window("PuTTY").Exist(0) Then
Window("PuTTY").Close
Window("PuTTY").Dialog("PuTTY Exit Confirmation").WinButton("OK").Click
End If
searchPuttyOutput "createSimulatorFiles.sh"
End Function
Public Function searchPuttyOutput(stringToBeSearched)
'In Debug mode if we stop the script without setting the below 2 parameters to Nothing, It gives error in next run. So Added below 2 lines to avoid unnecessary errors.
Set qfile=nothing
Set fso=nothing
Set fso=createobject("Scripting.FileSystemObject")
Set qfile=fso.OpenTextFile("C:\PuTTY\putty.log",1,True)
'Read the entire contents of priously written file
If Instr(qfile.ReadAll,stringToBeSearched) > 0 Then
MsgBox "String Found :)"
Else
MsgBox "String Not Found :("
End If
'Close the files
qfile.Close
'Release the allocated objects
Set qfile=nothing
Set fso=nothing End Function
No comments:
Post a Comment