gpt4 book ai didi

robotframework - 机器人框架 : BuiltIn library : Should Match : How to pass a pattern parameter correctly?

转载 作者:行者123 更新时间:2023-12-04 10:40:07 24 4
gpt4 key购买 nike

鉴于以下代码:

*** 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* .第一颗星将匹配“我”这个词之前的所有内容,第二颗星将匹配后面的所有内容。

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

*** 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*

关于robotframework - 机器人框架 : BuiltIn library : Should Match : How to pass a pattern parameter correctly?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59967941/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com