Expect=Keyword 可让您弹性接受可变响应,并利用特殊控制字符和正则表达式找出重要信息。若您不需要弹性或才刚开始撰写自定义的 TCP/UDP 脚本,可使用 SimpleExpect 关键词。

Expect 关键词有 4 种变化:

  • Expect:符合预期值时返回 true。
  • Expect(MatchCase):只在大小写符合预期值时返回 true。
  • DontExpect:找不到值时返回 true。
  • DontExpect(MatchCase):找不到值时返回 true。

Expect 语法是 Expect=Response,其中 Response 不是指定的完整文字字符串,就是混合正则表达式规则和文字。“加入预期值规则”/“编辑预期值规则” 按钮可让您建构、测试正则表达式响应字符串。系统会根据您选择的选项,自动选择 Expect 的变化。

注: 添加/编辑预期规则无法协助生成 SimpleExpect 关键词。

WhatsUp Gold v7 或 v8 用户:~^!= = 代码已经被 Expect 关键词的变化所取代。系统会自动转换已经移转的定义。

示例 1:## Note: script comments start with a # character## Send a simple text command#Send = Hello There## Expect a nice response that begins with, "Hi, How are you"#Expect=^Hi, How are you

示例 2:## Send a command followed by CR/LF#Send=Select * from Accounts\r\n## Expect a large response, but we only care to check that somewhere# in the response John Doe is mentioned#Expect=John Doe

示例 3:## Send a binary escape (27) and an x y and z and then a nak (21)#Send=\x1Bxyz\x15## Expect something that does *not* contain 123 escape (27)#DontExpect=123\x1B