Small Cheese

Some Simple QTP Scripts

This blog may helpful for QTP (HP QuickTest Professional) beginner, of course you can get more useful/detail information from Google according to your request, but some forum or blog may not provide a good instruction of how to execute the script and it may trouble the beginner. But, to be frankly, it gives a very good explanation.

My objective to write out this blog is to convenient the QTP beginner who has a little programming knowledge to apply the script into QTP and run with minor editing. If you would like to get more detail information of the command then you may do another search from Google. Script below are some simply validation and command that may more frequently apply to our daily test script.

To detect the file exist in folder:
If (createobject("scripting.filesystemobject").FileExists("c:\temp\deletelement.txt")) Then
   msgbox ("true")
else
   msgbox ("false")
End if

To delete file that exist in folder:
If (createobject("scripting.filesystemobject").FileExists("c:\temp\deletelement.txt")) Then
   CreateObject("scripting.FileSystemObject").DeleteFile ("c:\temp\deletelement.txt") 
End if

To display a message box and automatic close within a time:
If (createobject("scripting.filesystemobject").FileExists("c:\temp\deletelement.txt"))
  createobject("WScript.shell").Popup "true",1
else
  createobject("WScript.shell").Popup "false",1
End if

The value ‘1’ above refer to time (how long the message box appear)

To check whether the checkbox/radiobutton is checked:
If not (SwfWindow("").SwfWindow("").SwfCheckBox("").GetROProperty ("Checked")) then
  SwfWindow("").SwfWindow("").SwfCheckBox("").Set "ON"
else
  SwfWindow("").SwfWindow("").SwfCheckBox("").Set "OFF"
End if

If not (SwfWindow("").SwfWindow("").SwfRadioButton("").GetROProperty ("Checked")) then
  SwfWindow("").SwfWindow("").SwfRadioButton("").Set
else
  SwfWindow("").SwfWindow("").SwfRadionVutton("").Set
End if

* You can use QTP recorder to record the object then replace it into the script above.

To check whether the item is enabled:
If (SwfWindow("").SwfToolbar("").IsItemEnabled ("Commit")) then
  SwfWindow("").SwfToolbar("SwfToolbar").Press "Commit"
End if

The value ‘Commit’ is the item name display on front-end or the name you will click. you can change to meet your testing.


Custom Search