- Robot Framework 自动化测试框架核心指南
- 张永清
- 598字
- 2021-03-30 23:35:45
1.3 Robot Framework断言关键字
1.3.1 Should Be Equal关键字的使用
Should Be Equal关键字一般用来判断实际结果是否和预期结果相等。例如,我们将变量${value}的值设置为1,使用Should Be Equal关键字来判断${value}是否等于2,若断言失败,则输出实际值为${value},和预期不符合,如图1-3-1所示。

图 1-3-1
执行结果如图1-3-2所示。

图 1-3-2
1.3.2 Should Be True关键字的使用
Should Be True关键字用来判断返回值是否为True,例如我们将变量${value}的值同样设置为1,使用Should Be True关键字对表达式'${value}'=='2' 进行True和False的判断,由于我们设置的值为1,因此很明显会判断失败,如图1-3-3所示。

图 1-3-3
执行结果如图1-3-4所示。

图 1-3-4
1.3.3 Should Contain关键字的使用
Should Contain 关键字用来判断某个字符串中是否包含了我们预期需要的字符或者字符串,例如我们将变量${str}的值设置为Robot Framework,使用Should Contain关键字来判断${str}是否包含“Hello”这个字符串。很明显,我们执行的结果肯定会判断失败,如图1-3-5所示。

图 1-3-5
执行结果如图1-3-6所示。

图 1-3-6
1.3.4 Should End With关键字的使用
Should End With关键字用来判断某个字符串是否以我们预期指定的字符串来结束,例如我们同样将变量${str}的值设置为RobotFramework,使用Should End With来判断${str}是不是以“Hello”这个字符串来结束。很明显,我们执行的结果肯定会失败,如图1-3-7所示。

图 1-3-7
执行结果如图1-3-8所示。

图 1-3-8
当我们将“Hello”字符串换成“work”后,再执行一下,会发现执行成功,因为
RobotFramework是以work来结尾的,如图1-3-9所示。

图 1-3-9
执行结果如图1-3-10所示。

图 1-3-10
1.3.5 其他常用断言关键字
除了我们上面列出的关键字外,Robot Framework中还提供了大量其他的断言关键字,如表1-3-1所示。
表1-3-1 其他常用断言关键字

(续表)
