robot framework断言关键字

时间:2020-02-01 00:21:20   收藏:0   阅读:143

should  be   equal关键字,一般用来判断实际结果和预期结果是否相等。

 

示例:我们将变量${value}的值设为1,使用should  be   equal关键字来判断${value}是否等于2,若断言失败,则输出实际值为${value},和预期不符。

 

${value}                                                 set  variable                                                         1

should  be  equal                                   ${value}                                                               2                                                        实际值为${value},和预期不符

 

=============================================================================================================================

 

should  be   true关键字,用来判断返回值是否为true。

 

示例:我们将变量${value}的值同样设置为1,使用should  be   true关键字对表达式‘${value}‘==‘2‘进行true和false的判断,

           由于我们设置的值为1,因此很明显判断失败。

 

${value}                                                 set  variable                                                         1

should  be   true                                    ‘${value}‘==‘2‘                                                       判断失败

 

===============================================================================================

 

should   contain关键字,用来判断某个字符串中,是否包含了我们预期需要的字符或者字符串。

 

示例:我们将变量${str}的值设置为robotframework,使用should   contain关键字,来判断${str}是否包含“hello”这个字符,很明显,判断失败。

 

${str}                                                 set  variable                                                        robotframework

should   contain                                ‘${str}‘                                                                   hello                                                       字符串${str}中不包含hello

 

 

==========================================================================================================================

 

should  end   with关键字,用来判断某个字符串是否以我们预期指定的字符串来结束。

 

示例:我们将变量${str}的值设置为robotframework,使用should  end   with关键字,来判断${str}是不是以“hello”这个字符来结束,很明显,判断失败。

 

${str}                                                 set  variable                                                         robotframework

should  end   with                             ‘${str}‘                                                                   hello                                                       字符串${str}中不以hello来结束

 

=======================================================================================================================

123

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!