简单介绍了TCL脚本调用STAF的方法。Software Test Automation Framework (STAF) 是由IBM开发的开源、跨平台、支持多语言并且基于可重用的组件来构建的自动化测试框架。TCL是一种常见的脚本语言。
TCL安装目录
D:\Tcl 的目录
2016-04-03 18:24 <DIR> .
2016-04-03 18:24 <DIR> ..
2016-03-28 22:19 <DIR> bin
2016-03-28 22:20 <DIR> demos
2016-04-03 18:24 254,044 dirtcl.txt
2016-03-28 22:19 <DIR> doc
2016-03-28 22:19 <DIR> include
2016-04-03 13:21 <DIR> lib
2011-02-04 17:23 17,250 license-at8.5-thread.terms
2016-03-28 22:20 <DIR> licenses
2011-02-05 00:32 64,225 manifest_at8.5.txt
2011-02-05 00:14 2,818 readme-8.5-thread.txt
STAF
2016-04-03 13:21 <DIR> .
2016-04-03 13:21 <DIR> ..
2016-04-03 12:08 <DIR> bin
2016-04-03 12:08 <DIR> codepage
2016-04-03 12:16 <DIR> data
2016-04-03 12:08 <DIR> docs
2016-04-03 13:21 <DIR> event
2016-04-03 12:08 <DIR> include
2016-04-03 12:08 139 install.properties
2016-04-03 12:08 <DIR> jre
2016-04-03 12:08 <DIR> lib
2016-01-06 17:50 17,029 LICENSE.htm
2016-01-06 17:50 8,516 NOTICES.htm
2016-03-28 22:19 <DIR> ppm
2016-04-03 12:08 <DIR> samples
2016-04-03 12:08 287 STAFEnv.bat
2016-04-03 12:16 74,769 STAFInstall.log
2016-04-03 12:08 21 STAFReg.inf
2016-04-03 12:08 153 startSTAFProc.bat
2016-04-03 12:08 2,238 startSTAFProc.ico
2016-03-28 22:19 <DIR> tcl8
2016-03-28 22:20 <DIR> tcl8.5
2011-02-04 19:16 174,232 tcl85.lib
2016-03-28 22:20 7,299 tclConfig-shared.sh
2016-03-28 22:20 7,299 tclConfig.sh
2011-02-04 19:16 5,112 tclstub85.lib
2016-03-28 22:20 <DIR> teapot
2016-03-30 22:36 <DIR> test1.0
2016-03-28 22:20 <DIR> tk8.5
2011-02-04 18:30 122,622 tk85.lib
2016-03-28 22:20 3,609 tkConfig-shared.sh
2016-03-28 22:20 3,609 tkConfig.sh
2011-02-04 18:30 5,418 tkstub85.lib
2011-02-04 18:31 3,198 ttkstub.lib
2016-04-03 12:16 <DIR> Uninstall_STAF
2016-03-30 22:55 <DIR> zqgSTAF
17 个文件 435,550 字节
19 个目录 87,581,335,552 可用字节
C:\>staf local service list
Response
--------
Name Library Executable
--------- ---------- ------------------------------
CONFIG <Internal> <None>
DELAY <Internal> <None>
DIAG <Internal> <None>
ECHO <Internal> <None>
EVENT JSTAF d:/Tcl/lib/event/STAFEvent.jar
FS <Internal> <None>
HANDLE <Internal> <None>
HELP <Internal> <None>
LIFECYCLE <Internal> <None>
MISC <Internal> <None>
PING <Internal> <None>
PROCESS <Internal> <None>
QUEUE <Internal> <None>
SEM <Internal> <None>
SERVICE <Internal> <None>
SHUTDOWN <Internal> <None>
TRACE <Internal> <None>
TRUST <Internal> <None>
VAR <Internal> <None>
lib\bin目录下pkgIndex.tcl文件的内容如下
package ifneeded TCLSTAF 1.0 "load [list [file join $dir TCLSTAF.dll]]"
package ifneeded STAF 3.0 "source [list [file join $dir STAFUtil.tcl]]"
package ifneeded STAFMon 1.0 "source [list [file join $dir STAFMon.tcl]]"
package ifneeded STAFLog 1.0 "source [list [file join $dir STAFLog.tcl]]"
实例脚本
1、执行testTCL.tcl的结果
% source testTCL.tclUsing handle 19
Test basic functionality
Machine nickname is ZHANGHAO-PC
all tests successful
testTCL.tcl实例脚本如下:
package require STAF
if {[STAF::Register "Tcl Test"]!=$STAF::kOk} {
puts "Error Registering with STAF,RC: STAF::RC"
exit $STAF::RC
}
puts "Using handle $STAF::Handle"
#Submit some STAF requests
puts "Test basic functionality"
STAF::Submit local PING PING
if {$STAF::Result!="PONG"} {
puts "Wrong output for PING Request"
exit 1
}
if {[STAF::Submit local VAR "RESOLVE STRING {STAF/Config/MachineNickname}"]!=$STAF::kOk} {
puts "Error resoving machine nickname, RC:$STAF::RC, Result:$STAF:Result"
exit $STAF::RC
}
puts "Machine nickname is $STAF::Result"
#Unregister with STAF to remove the handle
if {[STAF::UnRegister ]!=$STAF::kOk} {
puts "Error unRegistering with STAF,RC: STAF::RC"
exit $STAF::RC
}
puts "all tests successful"
exit 0
STAF::kOk在STAFUtil.tcl中定义
把STAF::Register注释掉后,执行testTCL.tcl失败,提示:
can't read "STAF::Handle": no such variable
在使用其他STAF相关API之前,必须通过STAF::Register在STAF注册。返回值0表示注册成功。注册成功后,会生成一个值赋给变量STAF::Handle,该值不能改变。