【问题标题】:Pattern Matching in robot framework : python机器人框架中的模式匹配:python
【发布时间】:2020-12-10 15:14:12
【问题描述】:

有一个代码可以比较使用机器人框架点击 url 时产生的 cookie 的模式, 带有字符串变量。

REGMATCH
     ${string}=  set variable   hgf
     ${matches}=  get regexp matches  ${string}  asdfhgfpoyrjgrrhkjhoolk
     should be equal as strings  ${matches}  hgf

但这会返回 False ,

我在下面尝试了这个,

Get Lines Matching Pattern Matching Some Lines
    Test Get Lines Matching Pattern    asdfhgfpoyrjgrrhkjhoolk    ??????   hgf
 
 ***KEYWORD***
Test Get Lines Matching Pattern
    [Arguments]    ${input}    ${pattern}    ${expected}    ${case-insensitive}=no
    ${actual} =    Get Lines Matching Pattern    ${input}    ${pattern}    ${case-insensitive}
    Should Be Equal    ${actual}    ${expected}

谁能帮帮我。

【问题讨论】:

    标签: python string cookies robotframework


    【解决方案1】:
    ${actual} =    Get Lines Matching Pattern    ${input}    ${pattern}    ${case-insensitive}
    

    您的模式是 ?????,这意味着输入的字符数超过 5 个字符正好是 5 个字符

    asdfhgfpoyrjgrrhkjhoolk 可以使用那么多 '?' 来检索。作为 ?表示 glob 格式的一个字符,您可以使用

    ${actual} =    Get Lines Matching Pattern    ${input}    *    ${case-insensitive}
    

    表示整个字符串

    对于您的 y=用例,您可以使用

    Should Match Regexp    hithsihdisdh hsdaasidh 123 dfsdfdsf   123
    

    这将检查字符串是否有 "123" 。此关键字来自 Builin 库

    Library    BuiltIn
    

    以下示例显示了每个关键字的正确用法:

    *** Setting ***
    Library    String
    Library    BuiltIn
    Library  Selenium2Library
    
    
    *** Test Cases ***
    Example Search
        [Tags]    you    probably    do    not    have    this    many    tags    in    real    life
        ${first} =  Catenate    SEPARATOR=\n    Not in second   Same stuff  Differs Same
        #this is use ful to find line the pattern       
        ${a}=    Get Lines Matching Pattern     ${first}   Same*    case_insensitive=true
    
        #this match the entire multi line string has any match
        ${b}=    Should Match Regexp    ${first}   Same
    
        #this gives a list of all matches
        ${c}=    Get Regexp Matches    ${first}   Same
    
        Log    ${a}
        Log    ${b}
        Log    ${c}
    

    【讨论】:

      猜你喜欢
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 2021-04-07
      • 2019-08-11
      • 1970-01-01
      • 2018-03-13
      • 2014-11-28
      • 2018-04-25
      相关资源
      最近更新 更多