SimpleExpect 关键词可让您指定服务发送的正常回应。响应甚至可以是二进制 (即隐形 ASCII 字符) 回应。若您明确知道 (或大致知道) 正常响应的内容,即可编写简易的正常响应字符串供匹配之用。

此关键词可让您弹性接受可变响应,并只找出重要信息。若需要更大的弹性,最好使用 Expect 关键词提供的正则表达式语法。

SimpleExpect 脚本语法是 SimpleExpect=Response ,这里的响应指服务应该返回的一连串字符。下表列出的关键词可匹配逻辑和通配符,进而比较响应的每个字节,同时展开转义码。

命令选项:

关键词

描述

\x##

二进制值( 十六进制 格式),例如 \x00 是 Null

匹配任何字符

\%

“%”字符

\.

. ”字符

\\

“\”字符

注: 匹配响应时,只能使用您在 Expect 字符串中指定的字符数。正常响应必须以这些字符开头。系统会忽略所有尾随的其他字符。

示例 1: # # Note: script comments start with a # character # # Send=Hello There # # Expect a nice response # SimpleExpect=Hi, how are you?

示例 2: # # Send a command followed by CR/LF # Send=Select * from Accounts\r\n # # Expect a large response, be we only care to check that first word # received is "Customer" # SimpleExpect=Customer

示例 3: # # Send a binary escape (27) an x y and z and then a nak (21) # Send=\x1B\x15 # # Expect any byte (we don't care) then an abc and an ack (6) # SimpleExpect=.abc\x06