Automation One By One - Robot Framework - User Keywords
来源:互联网 发布:淘宝2016促销活动时间 编辑:程序博客网 时间:2024/06/03 22:03
在Automation One By One - Robot Framework -Test Case这一章中已经简单介绍了keywords相关概念,我们知道keywords分为2大类,一类是Librarykeywords,另一类是userkeywords。对于Librarykeywords我们不在这边做详细的介绍了,本章主要介绍如何创建userkeywords.
1. userkeywords的语法(syntax)- 与test case的语法类似,唯一不同在于存放的位置不同,test case放在test case table中,keyword放在keywords table中
***keywords***
userkeywords_name [Arguments]
Examples
Example without arguments
***keywords***
Open Login Page
Open Browser http://www.baidu.com
Title Should Be 百度知道
Example with arguments
***keywords***
Title Should Start With [Arguments] ${expected_value}
${title} = Get Title
Should Start With ${title} ${expected_value}
2. keywords table中可以加入settings命令
为了与keywords的name区分,keywords table中的命令使用[settings]格式。
可以使用的settings命令如下:
3. userkeywords中的arguments格式
*** Settings ***
Library Selenium Library 15
Test Setup Start Selenium Server
Test Teardown Stop Selenium Server
*** Testcases ***
TC1 [Documentation] embedded arguments
Open Browser http://news.baidu.com/advanced_news.html
Select 最近一年 from list
Select 最近一周 from list
Select 最近一小时 from list
comment 上述的值应该在下拉列表范围内,如果不在,系统会报错
*** Keywords ***
Select ${date} from list
Sleep 3s
Select From List name=mt ${date}
5. 定义一个可以返回值的userkeywords - 实现这个功能,可以借助settings-[Return]命令实现
*** Keywords ***
Return Value keyword
[Return] pass
Return One Value [Arguments] ${arg}
Do Something ${arg}
${value} = Get Some Value
[Return] ${value}
6. 调用userkeywords
从开发的角度讲,userkeywords及Librarykeywords相当于一个个封装好的函数,在test case中使用这些keywords时与调用函数的方法一样。
调用keywords
***Test Cases***
Open Login Page
Title Should Start 百度
1. userkeywords的语法(syntax)- 与test case的语法类似,唯一不同在于存放的位置不同,test case放在test case table中,keyword放在keywords table中
***keywords***
userkeywords_name [Arguments]
Examples
Example without arguments
***keywords***
Open Login Page
Open Browser http://www.baidu.com
Title Should Be 百度知道
Example with arguments
***keywords***
Title Should Start With [Arguments] ${expected_value}
${title} = Get Title
Should Start With ${title} ${expected_value}
2. keywords table中可以加入settings命令
为了与keywords的name区分,keywords table中的命令使用[settings]格式。
可以使用的settings命令如下:
- [Documentation]
- Used for setting auser keyword documentation.
- [Arguments]
- Specifiesuser keyword arguments.
- [Return]
- Specifiesuser keyword return values.
- [Timeout]
- Sets the possibleuser keyword timeout.Timeoutsare discussedin a section of their own.
3. userkeywords中的arguments格式
- 参见:Automation One By One - Robot Framework - Test Case
- 语法:在userkeyword名中嵌入argument后不能再使用[arguments]添加其它的参数了。
- 在userkeyword名中的arguments依赖于调用userkeyword时传递的值,如下例子
*** Settings ***
Library Selenium Library 15
Test Setup Start Selenium Server
Test Teardown Stop Selenium Server
*** Testcases ***
TC1 [Documentation] embedded arguments
Open Browser http://news.baidu.com/advanced_news.html
Select 最近一年 from list
Select 最近一周 from list
Select 最近一小时 from list
comment 上述的值应该在下拉列表范围内,如果不在,系统会报错
*** Keywords ***
Select ${date} from list
Sleep 3s
Select From List name=mt ${date}
- 需要注意的事,如果传递的值是带有空格的,如 最近 一年, 在调用函数时必须用引号引起来,说明要传递的是一个参数,否则,系统会认为是2个值。
5. 定义一个可以返回值的userkeywords - 实现这个功能,可以借助settings-[Return]命令实现
*** Keywords ***
Return Value keyword
[Return] pass
Return One Value [Arguments] ${arg}
Do Something ${arg}
${value} = Get Some Value
[Return] ${value}
6. 调用userkeywords
从开发的角度讲,userkeywords及Librarykeywords相当于一个个封装好的函数,在test case中使用这些keywords时与调用函数的方法一样。
调用keywords
***Test Cases***
Open Login Page
Title Should Start 百度
- Automation One By One - Robot Framework - User Keywords
- Automation One By One - Robot Framework - 数据类型
- Automation One By One - Robot Framework - Test Suite
- Automation One By One - Robot Framework - Keyword/Variable Files
- Automation One By One - Robot Framework - 优化Test Case
- Automation One By One - Robot Framework - 变量及赋值
- one by one note
- COPY CHAR ONE BY ONE
- Robot Framework User Guide
- Angular2 (One framework 概要)
- Robot Framework For Mobile Test Automation
- off-by-one error
- off by one
- Leetcode One by One----Two Sum
- Workplan Structure Locked By One User, Can be Unlocked By Another
- One
- one
- one:
- Automation One By One - Robot Framework - 数据类型
- ALV中fieldcat,layout常设字段
- 三星:Galaxy Nexus从设计之初就避免和苹果打专利战
- 名企笔试真题精选(三)
- Automation One By One - Robot Framework - 变量及赋值
- Automation One By One - Robot Framework - User Keywords
- shell脚本基础
- NTDDI_VERSION,_WIN32_WINNT,WINVER,_WIN32_IE定义宏的含义
- Tomcat7.0 在Windows7下的安装
- CPU的大端模式和小端模式
- 关于释放指针引发的一个错误
- Shell脚本编程详解
- delphi中处理OleVariant和TStream
- 产品经理的知识结构是什么