使用Tcl扩展包cwind进行界面自动化测试

cwind是一个控制界面操作的Tcl扩展包,它可以模拟键盘、鼠标的操作,捕获界面信息,控制界面窗口等,类似于QARUN等软件,通过cwind库可以利用tcl脚本方便的实现QARUN的功能,因此可以用于各种GUI测试。
[@more@]

cwind扩展包命令介绍:

to simulate a left click on the mouse
::cwind::lclick

to simulate a right click on the mouse
::cwind::rclick

to simulate a middle click on the mouse
::cwind::mclick

to set the mouse position
::cwind::setpos
where the starting position (0 0) is the upper left corner

to get the mouse position
::cwind::getpos

to get the cursor postion based on the position of the foreground window
::cwind::getwpos

to set the cursor postion based on the position of the foreground window
::cwind::setwpos

In version 1.3

to send a message to the foreground window.
::cwind::sendmessage ?? ??
Message name is the windows's message to be sent.
Wparam and lparam are additional value.

to post a message to the foreground window.
::cwind::postmessage ?? ??
Message name is the windows's message to be posted.
Wparam and lparam are additional value.

In version 1.2

I've expanded the specification of some commands for MDI.

to put in active a window.
::cwind::show ?-exact?
Search into the list of active window's name and set in foreground this window.
Window's name is treated as a glob-style pattern.
Window's name is specified in list form,
The first element is a parent window name and the optional second element is a MDI child window name.

to get the status of a window (Maximized, Minimized or Normal).
::cwind::state ?-exact?
Window's name is treated as a glob-style pattern.
Window's name is specified in list form,
The first element is a parent window name and the optional second element is a MDI child window name.

to have a list of all opened windows.
::cwind::wlist ?-exact? ??
If Window's name is omitted, Will show you a Tcl list with all the window's name.
If Window's name is specified, Will show you a Tcl list with all the MDI child window's name.
Window's name is treated as a glob-style pattern.

In version 1.1

Due to confilcts with the Tcl command "list",
I've renamed the command ::cwind::list to ::cwind::wlist.
::cwind::wlist

to get the status of a window (Maximized, Minimized or Normal).
::cwind::state ?-exact?
Window's name is treated as a glob-style pattern.

to restore the foreground window at the original size.
::cwind::restore

to minimize the foreground window.
::cwind::minimize

to maximize the foreground window.
::cwind::maximize

to minimize all the windows.
::cwind::minimizeAll

to wait a specific window on the foreground.
::cwind::waitwind ??
Max wait is in seconds and the default value is 5.
Window's name is treated as a glob-style pattern.

In version 1.0

to send a text to the foreground window.
::cwind::send ...
Send the arguments, separated by spaces.
If you want send the spaces, enclose your text into { and }.

to put in active a window.
::cwind::show ?-exact?
Search into the list of active window's name and set in foreground this window.
Window's name is treated as a glob-style pattern.

to get the active window name.
::cwind::gettext
Get the test of the foreground window.

to get the content of the clipboard.
::cwind::getcb

to put strings into the clipboard.
::cwind::putcb

to have a list of all opened windows.
::cwind::list
Will show you a Tcl list with all the window's name.

to set the sleep time.
::cwind::sleeptime ??
Time is to ask to the system to wait before each character sent.
A sort of delay in milliseconds.

一些特殊键的用法:

如果要使用像ctrl + c这样的特殊键,必须用下面的字符串序列来表示

"|CTRL+| c |CTRL-|"

特殊键的名字对应关系如下:

"ALT+"
	press ALT "ALT-"	release ALT "ALTL+"	press left ALT key "ALTL-"	release
 left ALT key "ALTR+" press right ALT key "ALTR-"	release right ALT key 
"CTRL+"	press CTRL "CTRL-"	release CTRL "CTRLL+" press left CTRL key 
"CTRLL-"	release left CTRL key "CTRLR+"	press right CTRL key "CTRLR-"	
release right CTRL key "SHIFT+"	press SHIFT "SHIFT-"	release SHIFT 
"SHIFTL+"	press left SHIFT key "SHIFTL-" release left SHIFT key 
"SHIFTR+"	press right SHIFT key "SHIFTR-"	release right SHIFT key "TAB" 
press the tabulation key "RET"	press the return key "ESC"	press the 
escape key "BACK"	press the backward key "DEL"	press the delete key 
"INS"	press the insert key "HELP"	press the help key "LEFT" send the 
cursor to the left "RIGHT"	send the cursor to the right "UP"	send the 
cursor to up "DOWN" send the cursor to down "PGUP"	press the page up key
 "PGDN"	press the page down key "HOME"	press the home key "END"	press 
the end key "F1"	press the function key F1 "F2"	press the function key 
F2 "F3"	press the function key F3 "F4"	press the function key F4 "F5"	
press the function key F5 "F6" press the function key F6 "F7"	press the 
function key F7 "F8"	press the function key F8 "F9"	press the function 
key F9 "F10"	press the function key F10 "F11"	press the function key F11
 "F12"	press the function key F12 "NUM0"	press the 0 on the key pad 
"NUM1"	press the 1 on the key pad "NUM2" press the 2 on the key pad 
"NUM3"	press the 3 on the key pad "NUM4"	press the 4 on the key pad 
"NUM5"	press the 5 on the key pad "NUM6"	press the 6 on the key pad 
"NUM7"	press the 7 on the key pad "NUM8"	press the 8 on the key pad 
"NUM9"	press the 9 on the key pad "NUM*"	press the * on the key pad 
"NUM+"	press the + on the key pad "NUM-"	press the - on the key pad 
"NUM,"	press the , on the key pad "NUM/"	press the / on the key pad 
"SNAP"	press the print key "APPS"	press the application key "KANJI"	
press the kanji key "CONV"	press the convert key "NCONV"	press the 
nonconvert key

下面是一段演示程序,演示了打开一个记事本,输入hello world,打开about窗口,然后拷贝窗口到剪贴板,打开画笔,把界面抓图复制到画图程序。下面程序中使用的窗口名是按照英文操作系统的,对于中文操作系统,需要修改其中的窗口名,例如*WordPad修改为记事本的窗口名,*Paint修改为画笔的中文窗口名。

package require cwind exec $env(COMSPEC) /c start wordpad.exe & ::cwind::waitwind {*WordPad} 10::cwind::send {Hello World!} |RET| after 1000 ::cwind::send |CTRL+| a |CTRL-| after 1000::cwind::send |CTRL+| c |CTRL-| after 1000 set clip [::cwind::getcb] after 1000 ::cwind::send |END| |CTRL+| v |CTRL-| after 1000 ::cwind::send |ALT+| h |ALT-| a after 1000 ::cwind::send |ALT+| |SNAP| |ALT-| exec $env(COMSPEC) /c start mspaint.exe & ::cwind::waitwind {*Paint} 10 ::cwind::send |ALT+| e |ALT-| p exit
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值