【发布时间】:2020-05-06 19:34:53
【问题描述】:
需要有编写期望脚本经验的人的帮助。我无法找到正确的解决方案来处理期望脚本中返回的多种类型的消息。我正在尝试测试 2 个场景,其中返回的最终消息可能有两种不同类型的响应。除了处理该响应之外,不期望为最终的回显消息发送任何响应。我该如何做到这一点?
test_script.sh
---------------
#!/bin/bash
echo "Session Name ?"
read $REPLY
echo "First Name ?"
read $REPLY
echo "Last Name ?"
read $REPLY
echo "Op# ?"
read $REPLY
echo "Password ?"
read $REPLY
echo "Password again?"
read $REPLY
echo "Session Name: RajP"
echo "First Name : Raj"
echo "Last Name : P"
echo "OP# : Arch"
echo "Continue? (y|n)"
read $REPLY
echo "row count = 1"
test_script2.sh
---------------
#!/bin/bash
echo "Session Name ?"
read $REPLY
echo "First Name ?"
read $REPLY
echo "Last Name ?"
read $REPLY
echo "Op# ?"
read $REPLY
echo "Password ?"
read $REPLY
echo "Password again?"
read $REPLY
echo "Session Name: RajP"
echo "First Name : Raj"
echo "Last Name : P"
echo "OP# : Arch"
echo "Continue? (y|n)"
read $REPLY
echo "You already have a ses_data record for OP_NBR=Arch"
expect_test_script.sh
---------------------
#!/usr/bin/expect -f
set timeout -1
spawn ./test_script.sh
expect "Session Name ?\r"
send "RajP\r"
expect "First Name ?\r"
send "Raj\r"
expect "Last Name ?\r"
send "P\r"
expect "Op# ?\r"
send "Arch\r"
expect "Password ?\r"
send "Pass123\r"
expect "Password again?\r"
send "Pass123\r"
expect "Session Name: RajP\r"
expect "First Name : Raj\r"
expect "Last Name : P\r"
expect "OP# : Arch\r"
expect "Continue? (y|n)\r"
send "y\r"
expect {
"You already have a ses_data record for OP_NBR=Arch"{exp_continue}
"row count = 1"{exp_continue}
}
expect eof
My expect script is trying to test 2 different shell scripts : test_script.sh and test_script2.sh ...
It fails with this message
expect: spawn id exp7 not open
while executing
"expect eof"
(file "./expect_test_script.sh" line 26)
如何编码我的期望脚本,以便它可以处理两个测试脚本( test_script.sh 和 test_script2.s )的最后一个 Echo?
【问题讨论】: