51Testing软件测试论坛

标题: 使用QTP的键盘操作 [打印本页]

作者: lq1107    时间: 2009-5-1 22:36
标题: 使用QTP的键盘操作
''使用QTP的键盘操作
'
''运行CMD
SystemUtil.Run "cmd.exe","","C:\WINDOWS\system32","open"
''输入 ping 51testing.com 字段
Window( "object class:=ConsoleWindowClass" ).Type "Ping www.163.com"
''输入回车
Window( "object class:=ConsoleWindowClass" ).Type micreturn
Window( "object class:=ConsoleWindowClass" ).Type "exit"
''退出
Window( "object class:=ConsoleWindowClass" ).Type  micreturn
txt= Window( "object class:=ConsoleWindowClass" ).GetVisibleText()
''在LOG打印出CMD里面的内容
print txt

Objectives
The objectives of this article are :
Learn how to use DOS command lines in QTP.
Alternative complex tasks.
Alternative .NET methods.
The following content is viewable because you are logged-in.
Thanks for registering!
cmd.exe allows access to the Microsoft Windows Command Prompt, also known as Microsoft DOS.
To-date, cmd.exe is a 32-bit command prompt used in Windows NT, 2000, and XP and offers disk and file maintenance functions to your computer as well as network functions. cmd.exe can be found under System32 folder.
SystemUtil.Run "cmd.exe","","C:\WINDOWS\system32″,"open"

Capture the window by QTP


Window( "object class:=ConsoleWindowClass" )
Print Window( "object class:=ConsoleWindowClass" ).GetROProperty( "title" )
Typing to DOS window
The Type method types the specified string in the window.
Syntax: object.Type KeyboardInput.
KeyboardInput : A String value. The text string and/or constants representing non-alphanumeric keys.

Window( "object class:=ConsoleWindowClass" ).Type "Ping advancedqtp.com"
Window( "object class:=ConsoleWindowClass" ).Type micReturn

Catching the Response
The GetVisibleText method returns the text from the specified area. The text to capture must be visible in the application window when the step runs. The area is defined by pairs of coordinates that designate two diagonally opposite corners of a rectangle.
Syntax : object.GetVisibleText ([Left], [Top], [Right], [Bottom])
txt = Window( "object class:=ConsoleWindowClass" ).GetVisibleText()
print txt

Problems…




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2