51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 8315|回复: 6
打印 上一主题 下一主题

TCL 自动化测试求助

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2007-8-28 14:55:10 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
任务:要求自动完成所有菜单和子菜单的测试(类似cmd操作的那种,输入一个命令后会跳出结果)

测试思想:设计TCL/Expect脚本一个,用来读取需要执行的命令文件cmd.txt和需要比较的标准结果文件result.txt,每次程序读取命令文件的一行然后执行就读取结果文件的一行然后以匹配的方式进行比较,如果匹配正确则再执行第二行的命令并读取第二行的标准结果进行比较,以此类推,cmd.txt和result.txt 已经事先写好 ,类似于testcase)

现要求程序进行精确匹配(原来是关键字匹配,也就是只匹配命令结果的一行),目前想法是在result.txt中定义一个类似于结束标志的字符串,然后程序读到result.txt的结束标志再停止,然后对命令的输出结果进行精确匹配,请问哪位有经验的前辈能帮我修改一下我的程序啊,万分感谢!也欢迎TCL高手和爱好者和我交流:zhangjiayi3399@hotmail.com

我的程序如下:



#!/usr/local/bin/expect -f
set host [lindex $argv 0]
set user [lindex $argv 1]
set passwd [lindex $argv 2]
set cmdfile [lindex $argv 3]
set resultfile [lindex $argv 4]

if { $argc != 5 } {
puts "Usage: ./console host user passwd cmdfile resultfile"
exit 1
}

proc start { } {
global cmdfile
global resultfile
set readcmdfile [open $cmdfile r]
set readresultfile [open $resultfile r]
set n 0
while { ![eof $readcmdfile] } {
gets $readcmdfile line1
if { ![eof $readresultfile] } {
    gets $readresultfile line2
} else {
    break
}

incr n
send "$line1\r"
expect {
  $line2 {}
  timeout {
  send_user "\nCommand $line1 Failed excuted\n"
  exit 1
  }
}
}
puts "\r"
puts "\n$cmdfile Test Passed\n"
close $readcmdfile
close $readresultfile
}
spawn telnet $host
expect "login:"
send "$user\r"
expect "Password:"
send "$passwd\r"
expect "Starting Console"
send "\r"
expect "MAIN MENU"
start
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-13 12:53 , Processed in 0.088302 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表