Working with Notepad in UFT/QTP – User friendly Tech help

Scenario:– Launching Notepad and writing data , saving and closing at the end.n

n

nSolution:– For understanding purposes I’ve used “Descriptive Programming“(We can easily use objects saved in Object Repository).

n

Copy the below code and run in UFT/QTP to understand the flow.
n
nFurther  we can also close all the notepad instances opened before launching the new instance through our script. We are closing it, so that previous notepad applications don’t interfere with script execution.

n

Code:-

n‘Launching the Notepad Application
nsystemutil.Run “notepad.exe”n

‘Fucntion call
nfnNotepad(“Help”)

n

Public Function fnNotepad(sFileName)
n‘Writing into Notepad
nSet objNotpad = Window(“regexpwndtitle:=Notepad”,“regexpwndclass:=Notepad”)
nobjNotpad.WinEditor(“nativeclass:=Edit”).Type “Welcome to uftHelp”

n

‘Saving and closing the notepad
nobjNotpad.WinEditor(“nativeclass:=Edit”).Type micCtrlDwn + “s” +micCtrlup

n‘Filling the filename 
nobjNotpad.Dialog(“text:=Save As”,“nativeclass:=#32770”).winEdit(“nativeclass:=Edit”,“attached text:=File &name:”).Set “C:Documents and SettingsdhesiDesktop”&sFileNamen

objNotpad.Dialog(“text:=Save As”,“nativeclass:=#32770”).winbutton(“text:=&save”,“nativeclass:=Button”).Click

n

‘Closing the notepad
nobjNotpad.Close

n‘Destroying the object
nSet objNotpad = nothingn

End Function

Was this article helpful?
YesNo

Similar Posts