2015-07-09 32 views
0

我运行机器人框架内的以下测试:如何使用Robot Framework检查'Result'对象中是否存在子字符串?

*** Settings *** 
    Documentation   This initializes testrun.robot 
    Library     Process 
    Library     OperatingSystem 
    Library     XML 
    Library     Collections 

    Output Is A Valid XML File Against JATS format 
     Start Process   xmllint --dtdvalid http://jats.nlm.nih.gov/archiving/1.1d3/JATS-archivearticle1.dtd ./output/nlm/out.xml  shell=True 
     ${result}=   Wait For Process  timeout=45 secs 
     Log     ${result.stdout} 
     Log     ${result.stderr} 
     Run Keyword Unless  '${result.stderr} == ${EMPTY}'  Should Contain  ${result.stderr} element xref: validity error : IDREFS attribute rid references an unknown 

变量$ {} result.stderr是包含子字符串“元素的外部参照:有效性错误:IDREFS属性去掉引用未知”。据我所知,我没有处理任何空白错误或报价问题,虽然我可能是错的。 (我一直在摆弄这一段时间。)

感谢您的帮助!

编辑:该机器人框架生成告诉我,该过程完成日志(这就是我怎么知道是什么result.stderr包含的内容。)

回答

1

此声明:

Run Keyword Unless  '${result.stderr} == ${EMPTY}' ... 

该关键字永远不会运行是因为你没有比较两个变量,你只是简单地检查字符串文字字符串'${result.stderr} == ${EMPTY}'是否为空(而不是,因为它有28个字符)。

这是一样的,如果你在Python这样做:

if len('${result.stderr} == ${EMPTY}') > 0: 
    ... 

需要分别把周围每个变量的单引号,这样你是通过一个有效的表达式if语句,而不是字符串看起来像有效的表达式:

Run Keyword Unless  '${result.stderr}' == '${EMPTY}' ... 
+0

报价会需要在条件语句周围的每一个变量放?应该引用字符串文字吗?如果字符串文字中有引号,我该怎么办? –

+0

@JosephNicolls:机器人用它们的值替换变量后,结果需要是有效的Python代码。从文档:_“如果condition是一个字符串(例如$ {rc} <10),它将使用内置的eval函数作为Python表达式进行评估,并根据结果确定关键字状态。字符串项被给出,状态直接从它的真值获得。“_ –

+0

@JosephNicolls:请注意,如果你的变量有单引号,你可能需要使用双引号。如果您的变量是您正在与另一个数字比较的数字,则不需要引号。 –

相关问题