【问题标题】:Expect - does not send text as desired期望 - 不按需要发送文本
【发布时间】:2013-09-19 05:50:57
【问题描述】:

我正在开发一个脚本,用于对软件安装进行回归测试。期望代码如下。在浏览并同意许可文件的情况下,前几行代码运行良好。但是,脚本在“请输入有效许可证文件的路径名:”处停止,并且不执行任何操作。 (注:手动安装顺利进行)。

另外,请注意所有输入的光标始终位于显示文本的右侧;但在最后一个提示(“请输入有效许可证文件的路径名:”)的情况下,光标位于文本下方和下面的行中。我不确定这是否与问题有关。

我做错了什么?我该如何调试这个问题?感谢大家的帮助。

谢谢 纳齐尔

代码如下:

#!/usr/bin/expect
spawn ./temp 
expect {
         "More--*" {
               send " "
                exp_continue
                }
"Do you accept this license agreement?*" {
                 send "yes\r"
                 }
}
expect "Do you want to use the default path?*" { send "yes\r" }
expect "This load path does not exist. Do you want to create it?*" { send "yes\r" }
expect "Please enter the pathname to a valid license file:*" { send "/path_to_file\r" }
interact

下面是输出的样子:

.....(license stuff)

Do you accept this license agreement? [no] yes

Please specify where the xxx software will be loaded.
The default location is /usr/local/aaa.
Do you want to use the default path? [yes] yes

The software will not run without a valid license file installed.
Please enter the pathname to a valid license file:

【问题讨论】:

  • 您在send "/path_to_file" 的末尾缺少\r。这是在真正的脚本中还是这里的复制错误?
  • 嗨 Barnar...谢谢指出...这是一个复制错误,我已更正。

标签: linux send expect


【解决方案1】:

您可以使用 -d 开关在 expect 中进行调试:

#!/usr/bin/expect -d

它非常冗长,帮助我确定了我在写期望时犯的无数小错别字。

【讨论】:

  • 谢谢,我做了类似的事情...我使用了 autoexpect 并比较了生成的代码!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多