首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >机器人框架中的模式匹配: python

机器人框架中的模式匹配: python
EN

Stack Overflow用户
提问于 2020-12-10 05:23:10
回答 1查看 2.3K关注 0票数 0

有一个代码,它将比较使用机器人框架访问url时产生的cookie模式,并使用字符串变量。

代码语言:javascript
复制
REGMATCH
     ${string}=  set variable   hgf
     ${matches}=  get regexp matches  ${string}  asdfhgfpoyrjgrrhkjhoolk
     should be equal as strings  ${matches}  hgf

但这是假的,

我试过下面这个,

代码语言:javascript
复制
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}

有人能帮我这个忙吗。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-12-10 07:06:05

代码语言:javascript
复制
${actual} =    Get Lines Matching Pattern    ${input}    ${pattern}    ${case-insensitive}

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

asdfhgfpoyrjgrrhkjhoolk可以用这么多“?”是什么?请使用glob格式的一个字符,您可以使用

代码语言:javascript
复制
${actual} =    Get Lines Matching Pattern    ${input}    *    ${case-insensitive}

意思是整个字符串

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

代码语言:javascript
复制
Should Match Regexp    hithsihdisdh hsdaasidh 123 dfsdfdsf   123

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

代码语言:javascript
复制
Library    BuiltIn

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

代码语言:javascript
复制
*** 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}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65228946

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档