1.0. 文档
https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#String representations
1.1. str
使用“人类可读”的字符串表示。 相当于在 Python 3 中使用 str() 和在 Python 2 中使用 unicode()。这是默认设置。
1.2. repr(representation表示)
1.使用“机器可读”的字符串表示。 与在 Python 中使用 repr() 类似,这意味着像 Hello 这样的字符串被记录为 'Hello',换行符和不可打印的字符被转义为
和 x00,等等。
非 ASCII 字符在 Python 3 中像 ä 一样按原样显示,在 Python 2 中以像 xe4 这样的转义格式显示。使用 ascii 始终获取转义格式。
2.与标准 repr() 相比,还有一些增强:
更大的列表、字典和其他容器被漂亮地打印出来,所以每行有一个项目。
在 Python 2 中,Unicode 字符串省略了 u 前缀,而将 b 前缀添加到字节字符串中。
1.3. ascii
1.与在 Python 3 中使用 ascii() 或在 Python 2 中使用 repr() 相同。
2.与上面解释的使用 repr 类似,但有以下区别:
在 Python 3 上,非 ASCII 字符像 xe4 一样被转义,而不是像 ä 那样按原样显示。 这使得更容易看到看起来相同但不相等的 Unicode 字符之间的差异。 这就是 repr() 在 Python 2 中的工作方式。
在 Python 2 上只使用标准的 repr() 意味着 Unicode 字符串获得 u 前缀并且没有 b 前缀添加到字节字符串。
3.容器不是印刷精美的。
2.1. 空字符串相关
# 判断字符串是否None(没获取到)
# 1
${pc2} = Get Variable Value ${GNB${BTS_ID}.RRU2_PC_IP}
Run Keyword If '${pc2}'!='${null}' log OK
# 2
${has_value}= Run Keyword And Return Status Should Not Be Empty ${pc2}
log ${has_value}
# ${None}和${null}
${i am none} Set Variable ${None}
${i am null} Set Variable ${null}
Should Be Equal ${i am none} ${None}
Should Be Equal ${i am null} ${null}
Run Keyword If '${i am none}'=='${None}' log to console 123
... ELSE log to console 456
Run Keyword If '${i am null}'=='${null}' log to console 123
... ELSE log to console 456
Run Keyword If '${i am none}'=='${null}' log to console 123
... ELSE log to console 456
2.2. 字符串对比查找
# 1.正则表达
coam.Assert ${class_name} ${bts_class_id} parameters=proceduralState=regex"[Oo]n[Aa]ir" timeout=${timeout} connection=${connection}
# 2.直接对比
Should be equal as strings ${cell_operational_state} ${expected_Operational_status} msg=The state in Cell_${global_cell_id} isn't expected, Current state is ${cell_operational_state} ignore_case=True