机器人框架:telnet执行命令“提示未设置”

时间:2017-08-16 18:28:34

标签: robotframework

尝试运行这段代码,但在Execute Command行中仍然出现“Prompt is not set”错误。

*** Settings ***
Library    Telnet
Library    Telnet  ${out}
Library    Collections
Library    Collections  ${y}
Library    Collections  ${x}

*** Variables ***
${ip}    0.0.0.0
${port}    0

*** Test Cases ***
telnet to server
    Open Connection    ${ip}  ${port}

verify something
    ${out}=  Execute Command  ls
    ${y}=  Get From List  ${out}  0
    Should Match Regexp  ${y}  /^ID$/

Exit Test
    Close All Connections

我还尝试删除“Library Telnet $ {out}”并替换“$ {out} =   执行命令ls“与以下行匹配,但收到相同的错误。

Write  ls
Set Prompt  ${out}
${out}=  Read Until Prompt

语法有问题吗?或者,“提示”的使用是完全错误的? (如果是这样,我该如何解决这个问题?)

(注意:这是机器人框架的第一次尝试,所以请随时评论任何其他问题!)

2 个答案:

答案 0 :(得分:0)

一切都在Telnet文档中。我使用RED Robot Editor,它可以通过在编辑器中悬停在Telnet条目上向我显示Telnet和Telnet KW的文档,这也可以通过命令行生成:

python -m robot.libdoc Telnet show

有一部分是关于提示:

== Prompt ==

Often the easiest way to read the output of a command is reading all
the output until the next prompt with `Read Until Prompt`. It also makes
it easier, and faster, to verify did `Login` succeed.

Prompt can be specified either as a normal string or a regular expression.
The latter is especially useful if the prompt changes as a result of
the executed commands. Prompt can be set to be a regular expression
by giving ``prompt_is_regexp`` argument a true value (see `Boolean
arguments`).

Examples:
| `Open Connection` | lolcathost | prompt=$              |
| `Set Prompt`      | (> |# )    | prompt_is_regexp=true |

查看Telnet文档以获取更多帮助和示例。

PS。我没有看到使用参数导入Telnet的原因:

Library    Telnet  ${out}

答案 1 :(得分:0)

虽然我回答的太晚了,但我没有看到确切的预期答案,因此现在回答这个问题。 您需要在 Open Connection 中设置 2 项。

  1. prompt_is_regexp=yes
  2. prompt=#{Your expected prompt}