robotframework的学习笔记(十四)------学习Robot Framework必须掌握的库—-BuiltIn库

摘要:
如果用户想在测试用例中实现比较复杂的逻辑,那就需要对BuiltIn中的重要关键字有一些了解。BuiltIn库中还封装了很多常见方法和能够控制RF运行状态的关键字,如果想用好RF,一定要对BuiltIn库中的函数有一个比较全面的理解。下面就带着大家认识一下BuiltIn库中比较重要的关键字。Runkeyword系列关键字:RunKeywordIf------Arguments:[condition|name|*args]Runsthegivenkeywordwiththegivenarguments,ifconditionistrue.RunKeywordIfAllCriticalTestsPassedRunKeywordIfAllTestsPassedRunKeywordIfAnyCriticalTestsFailedRunKeywordIfAnyTestsFailedRunKeywordIfTestFailedRunKeywordIfTestPassedRun、KeywordIfTimeoutOccurred这些关键字能根据一个判断条件的真假来看是否执行关键字。我们就会用到这个关键字BuiltIn库里还有很多宝贝比如日期相关的关键字GetTime。

作为一门表格语言,为了保持简单的结构,RF没有像别的高级语言那样提供类似if else while等内置关键字来实现各种逻辑功能,而是提供给了用户BuiltIn库。如果用户想在测试用例中实现比较复杂的逻辑,那就需要对BuiltIn中的重要关键字有一些了解。BuiltIn库中还封装了很多常见方法和能够控制RF运行状态的关键字,如果想用好RF,一定要对BuiltIn库中的函数有一个比较全面的理解。下面就带着大家认识一下BuiltIn库中比较重要的关键字。

Evaluate关键字:

Arguments:[ expression | modules=None | namespace=None ]Evaluates the given expression in Python and returns the results.

如果你需要进行一些数值运算并得到结果,你就需要用到Evaluate关键字。Evaluate会把你想要计算的表达式直接传递给Python,并把Python的计算结果返回给你。这是最经常要用到的。
Should 系列关键字:
Should系列关键字是Should打头的一系列关键字。
Should Be Empty--------Verifies that the given item is empty.
Should BeEqual--------Fails if the given objects are unequal.
Should BeEqual As Integers--------Fails if objects are unequal after converting(转换) them to integers.
Should BeEqual AsNumbers--------Fails if objects are unequal after converting(转换) them to real numbers.
Should BeEqual AsStrings--------Fails if objects are unequal after converting(转换) them to strings.
Should BeTrue--------Fails if the given condition(状态) is not true.
Should Contain--------Arguments:[ container | item | msg=None | values=True | ignore_case=False ]Fails if container does not contain(包含) item one or more times.
Should ContainX Times--------Arguments:[ item1 | item2 | count | msg=None | ignore_case=False ]Fails if item1 does not contain item2 count times.
Should EndWith--------Arguments:[ str1 | str2 | msg=None | values=True | ignore_case=False ]Fails if the string str1 does not end with the string str2.
Should Match--------Arguments:[ string | pattern | msg=None | values=True | ignore_case=False ]Fails unless the given string matches the given pattern.
Should MatchRegexp--------Arguments:[ string | pattern | msg=None | values=True ]Fails if string does not match pattern as a regular expression(正则表达式).
Should StartWith--------Arguments:[ str1 | str2 | msg=None | values=True | ignore_case=False ]Fails if the string str1 does not start with the string str2.
Should NotBe Empty
Should NotBe Equal
Should NotBe Equal As Integers
Should NotBe Equal As Numbers
Should NotBe Equal As Strings
Should NotBe True
Should NotContain
Should NotEnd With
Should NotMatch
Should NotMatch Regexp
Should NotStart With
这些关键字都是用作判断时用的,每个用例都会用到,比如我们的执行结果得到了一个字符串,我们要判断这个字符串要与一个预期字符串相等,否则用例就无法通过,这时候,肯定会用上Should Be Equal As String关键字,其它关键字我们通过关键字的名字就能顾名思义,知道它的作用。
Convert To系列关键字:
Convert ToBinary
Convert ToBoolean
Convert ToHex
Convert ToInteger
Convert ToNumber
Convert ToOctal
Convert ToString
做类型转换,将某个值转换为相对应的类型。
Run keyword系列关键字:
Run KeywordIf------Arguments:[ condition | name | *args ]Runs the given keyword with the given arguments, if condition is true.
Run KeywordIf All Critical Tests Passed
Run KeywordIf All Tests Passed
Run KeywordIf Any Critical Tests Failed
Run KeywordIf Any Tests Failed
Run KeywordIf Test Failed
Run KeywordIf Test Passed
Run、KeywordIf Timeout Occurred
这些关键字能根据一个判断条件的真假来看是否执行关键字。一般使用这些关键字来实现高级语言中的ifelse功能。最常用的是Run Keyword If 和 Run Keyword unless他们俩实现的效果正好相反。
Exit For Loop关键字:
用作退出循环,一般和Run KeywordIf关键字联合使用,来实现条件退出。
Wait Until Keyword Succeeds关键字:
这是一个将异步调用变为同步调用的关键字。举一个例子:如果call某个WebService,并且需要得到返回结果才能做下一部操作。我们就会用到这个关键字
BuiltIn库里还有很多宝贝
比如日期相关的关键字GetTime。
让测试暂停的Sleep等。都相当有用。
RF目前仅有2个内置关键字:FOF 和 IN,来实现循环结构。功能还是比较弱的。

免责声明:文章转载自《robotframework的学习笔记(十四)------学习Robot Framework必须掌握的库—-BuiltIn库》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Unity 修改windows窗口的标题python--“re”详解下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

C# CheckedListBox控件的用法大全

checklistbox控件  1.添加项 checkedListBox1.Items.Add("蓝色"); checkedListBox1.Items.Add("红色"); checkedListBox1.Items.Add("黄色"); 2. 判断第i项是否选中,选中为true,否则为false if(checkedListBox1.GetItemC...

Winform TextBox中只能输入数字的几种常用方法(C#)

方法一: private void tBox_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 0x20) e.KeyChar = (char)0; //禁止空格键 if ((e.KeyChar ==...

Object之defineProperty

对象是由多个名/值对组成的无序的集合。对象中每个属性对应任意类型的值。定义对象可以使用构造函数或字面量的形式: var obj = new Object; //obj = {} obj.name = "张三"; //添加描述 obj.say = function(){}; //添加行为 除了以上添加属性的方式,还可以使用Object.definePr...

flowplayer网页视频播放器事例详解--包含各种参数说明(自译)

flowplayer网页视频播放器事例详解--包含各种参数说明(自译) <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server">     <title></title>     <meta http-eq...

ASP.NET MVC5开发记录

Request 和 Request.form 和 Request.QueryString 的区别: (参考:https://www.cnblogs.com/tianguook/p/3592531.html) Request.Form["key"] 获取对应key的value值,用于POST过来的数据,不限制数据大小 Request.QueryString[...

Duilib的圆环形 进度条 实现(网易云信版本)

/** @file CircleProgress.h* @brief 圆环型进度条控件,圆环中间可以有文本(如85%)* @copyright (c) 2019-2022, NetEase Inc. All rights reserved* @author Xuhuajie* @date 2019/8/14*/ #ifndef UI_CONTROL_CIR...