Robot Framework : BuiltIn library : Should Match : 如何正确传递模式参数?

Robot Framework : BuiltIn library : Should Match : How to pass a pattern parameter correctly?

给定以下代码:

*** Test Cases ***
Use "Should Match"
[Documentation]     Should Match    string, pattern, msg=None, values=True, ignore_case=False
...                 Fails if the given string does not match the given pattern.
...                 Pattern matching is similar as matching files in a shell with *, ? and [chars] acting as
...                 wildcards. See the Glob patterns section for more information.

Should Match        string=Can find me here   pattern=me   msg='The overwriting error'  # fails unexpectedly
Should Match        string='Will match with star'   pattern=*
Should Match        string='Will match this'        pattern=[atx]his      # fails unexpectedly
Should Match        string='Will match with keyword'    pattern=?eyword   # fails unexpectedly

目标是让测试用例中的所有语句都通过。目前,第一个语句失败并出现错误:

'The overwriting error': 'Can find me here' does not match 'me'

当使用 Should Match 时,模式需要匹配整个字符串,而不仅仅是字符串的一部分。如果你想让第一个模式通过,你需要把它改成*me*。第一颗星将匹配单词 "me" 之前的所有内容,第二颗星将匹配之后的所有内容。

其他图案也是如此。如果您要在较大的字符串中查找模式,则需要在模式的任一侧添加 * 以匹配所有其他字符。

*** Test Cases ***
Use "Should Match"
    Should Match        Can find me here           pattern=*me*
    Should Match        'Will match with star'     pattern=*
    Should Match        'Will match this'          pattern=*[atx]his*
    Should Match        'Will match with keyword'  pattern=*?eyword*