如何检查字符串是否包含机器人框架中的其他字符串(子字符串)?

时间:2017-06-12 09:56:55

标签: string robotframework

如何检查字符串是否包含机器人框架中的其他字符串?

这样的东西
public function activitiesSummaryAction()
{
    $classes = array();

    for($i = 1; $i <=10; $i++)
    {
        array_push($classes, new Classroom($i, 'myCallback'));
    }


    return $this->render('teacher/activitiesSummary.html.twig', [
        'classes' => $classes,
    ]);
}

Get Substring没有帮助,因为它需要一个起始索引。

3 个答案:

答案 0 :(得分:13)

${source}=    Set Variable    this is a string

# ${contains} will be True if "is a" is a part of the ${source} value
${contains}=  Evaluate   "is a" in """${source}"""

# will fail if "is a" is not a part of the ${source} value
Should Be True      "is a" in """${source}"""

# using a robotframework keyword from the String library
# it is actually a wrapper of python's "var_a in var_b" - the previous approaches
Should Contain    ${source}    is a

# as last alternative - an approach that will store 
# the result in a boolean, with RF standard keywords
# ${contains} will be True if "is a" is a part of the ${source} value
${contains}=    Run Keyword And Return Status    Should Contain    ${source}    is a

希望这个例子不言自明

答案 1 :(得分:4)

从字符串库中使用Get Lines Containing Stringdoc here。然后检查结果。

答案 2 :(得分:2)

我找到了另一个解决方案

${match} | ${value} | Run Keyword And Ignore Error | Should Contain | full string    | substring
${RETURNVALUE} | Set Variable If | '${match}' == 'PASS' | ${True} | ${False}