Robot Framework (转)
上一篇 /
下一篇 2012-08-01 22:42:25
/ 个人分类:Robot framework
Robot Framework组成TestCase的要素:
(1)Action(步骤) - Keyword, 存在2大类Keyword
- Librarykeywords - 通常来自标准类库或第三方类库
- External Libraries
- SeleniumLibrary
- SwingLibrary
- 自定义的libraries - http://robotframework.googlecode.com/svn/tags/robotframework-2.5.6/doc/userguide/RobotFrameworkUserGuide.html#creating-test-libraries
- User keywords - 通过Keyword table创建,来源是Library keywords, user keywords可以与test case位于同一文件内或是作为单独的一个文件导入到test case的文件中;
- 这类的Keyword可以想像成把若干Library keywords集合到一起,形成一个新的keyword,新keyword可以完成一步或几步action,其作用类似于编程中的函数或类。
- 在接下来的文章中,主要是针对SeleniumLibrary及BuiltinLibrary进行介绍。
(2)Argument - 可以是变量或常量
- Argument与任何语言中的参数作用是一样的,其主要的目的就是为keywords传递数据。
- 一个keyword可以有0个或多个Arguments。
- Robot中参数类型有以下几种,这种分类是从Python中借鉴而来的:
- Required Argument =(Positional Arrangement位置参数)以正确的定位顺序及数量来传入函数的,顺序改变了或数量不正确就不能完成参数的传递
***Test Case*** TC1 [Documentation] User can create an account and log in Create Valid User username1 password123 Attempt to Input with Credentials username1 password123 Status Should Be Logged In |
- username1/password123/Logged In 都是位置参数
- 有些Keyword也可以没有参数
- Named Argument(关键字参数)- 如果命名了参数,可以不按顺序传递参数
***Test Case*** TC2 [Documentation] Named Argument Example Keyword arg2=xxx arg3=yyy |
- Default Argument - 默认参数是一个已经赋值的关键字参数,如果在函数调用时没有给出值,那么这个赋值就会被传递。
如:OperatingSystemlibrary中有一个关键字Create File,这个关键字有3个参数path, content=,encoding=UTF-8 当使用这个关键字时,path参数必须存在,content及enconding可以不输入,如果不输入则意味着content为空,encoding是UTF-8;如果输入了则按输入的值传递
***Test Case*** TC3 [Documentation] Default Argument Create File ${TEMPDIR}/empty.txt Create File ${TEMPDIR}/utf-8.txt Hyvä esimerkki Create File ${TEMPDIR}/iso-8859-1.txt Hyvä esimerkki ISO-8859-1 |
如上述 Create File Keyword, encoding可以是常量如ISO-8859-1,也可是使用变量。 假设我现在有一个encoding的列表,列表中的值有ISO-8859-1,UTF-8,GBK等等,每次取值都是不一样的。 在Robot中,我们可以将encodning定义为列表 @{encoding}=ISO-8859-1 UTF-8 GBK 当调用Create File这个Keyword时,我们需要传一个变量,即@{encoding}[0],@{encoding}[1] |
- Argument接收的变量可以是一个值,也可是一个对象
Python及C中均有*varargs概念 Robot中的Join Paths keyword,其Argument有2个,分别是*paths,base *path意味可以传递任意数量的变量; base只是传递一个变量
|
- 以上类型的参数可以同时存在,但是有一定规则:
- Required Argument(位置参数)必须放在Named Argument(关键字参数)之前
- Required Argument(位置参数)必须出现在任何一个默认参数之前
- 如果参数一个对象(即列表或元组),则其必须放在Required Argument(位置参数)和Default Argument(默认参数)之后
收藏
举报
TAG: