Small Cheese

Use QTP To Execute Command In Windows Command Prompt

QTP tool is really a useful automation tool for application testing, it’s not only allowing you to capture front-end objects but you can also use it to execute a command in Windows command prompt.

Here is the sample of code
SystemUtil.Run "cmd.exe","","C:\WINDOWS\system32","open" 
Window( "object class:=ConsoleWindowClass" ).Type “C:\Program Files\Java\jdk1.5.0_02\bin”
Window( "object class:=ConsoleWindowClass" ).Type micReturn

If you hit syntax error, please check the command that inserted by QTP.

I experienced one scenario that return error where QTP11 inserting a long command into the windows command prompt. I got no idea why the command is breaking by adding an unexpected “space”. This problem may not happen in your environment but it’s good to know.

Unexpected Space Is Added To The Command
Unexpected Space Is Added To The Command

Workaround to overcome this by cropping the command into two input in stead of one.
Window( "object class:=ConsoleWindowClass" ).Type “C:\Program Files\Java\”
Window( "object class:=ConsoleWindowClass" ).Type “jdk1.5.0_02\bin”

Custom Search