4. RF是什么
● Generic test automation framework
– Utilizes the keyword-driven testing approach
● Implemented with Python
– Jython supported fully and IronPython initially
– Can be extended natively using Python or Java
– Other languages supported via XML-RPC based remote
interface
● Open source
– Apache 2.0 license
– Sponsored by Nokia Siemens Networks
– Active development and growing community
– Hosted on Google Code
6. RF特性—测试用例组成
Table name Used for Aliases
Setting table 1) Importing test libraries, resource Setting, Settings, Metadata
files and variable files
2) Defining metadata for test suites and test
cases
Variable table Defining variables that can be used elsewhere Variable, Variables
in the test data
Test case table Creating test cases from available keywords Test Case, Test Cases
Keyword table Creating user keywords from existing lower- Keyword, Keywords, User
level keywords Keyword, User Keywords
7. RF特性—简单易用的表格语法
Test Case Action Argument Argument
Valid Login Open Login Page
Input Name demo
Input Password mode
Submit Credentials
Welcome Page Should
Be Open
Setting Variables Do Something first second argument
argument
${value} = Get Some
Value
Should Be Equal ${value} Expected value
8. RF特性—支持多种文件格式
html格式
Test Case Action Argument Argument
My Test [Documentation] Example test
Log ${MESSAGE}
My Keyword /tmp
Another Test Should Be Equal ${MESSAGE} Hello, world!
9. RF特性—支持多种文件格式
*Setting* *Value* *Value* *Value*
Library OperatingSystem
TSV 格式
*Variable* *Value* *Value* *Value*
${MESSAGE} Hello, world!
*Test Case* *Action* *Argument* *Argument*
My Test [Documentation] Example test
Log ${MESSAGE}
My Keyword /tmp
Another Test Should Be Equal ${MESSAGE} Hello, world!
*Keyword* *Action* *Argument* *Argument*
My Keyword [Arguments] ${path}
Directory Should ${path}
Exist
16. RF特性—支持多种用例风格
Behavior-driven style
Test Case Step
Valid Login Given login page is open
When valid username and
password are inserted
and credentials are
submitted
Then welcome page should
be open
20. RF特性—Variables
Variable types Scalar variables List variables Environment variables
${NAME} @{USER} %{USER}
${OBJ} @{USER}[0] %{JAVA_HOME}
@{items}
Using list variables as scalars
Test Case Action Argument Argument Argument
Example @{items} = Create List first second
Length Should Be ${items} 2
Append To List ${items} third
Length Should Be ${items} 3
Log Many @{items}
21. RF特性—Variables
Setting variables in command line
--variable EXAMPLE:value
--variable HOST:localhost:7272 --variable USER:robot
--variable ESCAPED:Qquotes_and_spacesQ --escape quot:Q --escape space:_
Built-in variables
Variable Explanation
${CURDIR} An absolute path to the directory where the test data file is located. This variable is
case-sensitive.
${TEMPDIR} An absolute path to the system temporary directory. In UNIX-like systems this is
typically /tmp, and in Windows c:Documents and Settings<user>Local
SettingsTemp.
${EXECDIR} An absolute path to the directory where test execution was started from. New in
Robot Framework 2.1.
${/} The system directory path separator. / in UNIX-like systems, in Windows.
${:} The system path element separator. : in UNIX-like systems and ; in Windows.
22. RF特性—Variables
Variable Priorities
1.Variables from the command line
2.Variable table in a test case file
3.Imported resource and variable files
4.Variables set during test execution
5.Built-in variables
23. RF特性—Variables
1. set from the command line
Variable Scopes 2. BuiltIn keyword Set Global Variable
3. Built-in variables
推荐大写
1. Global scope
2. Test suite scope 1. from the return values of keywords
3. Test case scope 2. BuiltIn keyword Set Test Variable
4. User keyword scope 推荐小写
User keywords get their own 1. created in Variable tables
variables 2. imported from resource and variable files
from arguments passed to them 3. BuiltIn keyword Set Suite Variable
and return values
from the keywords they use 4. test suite scope is not recursive
推荐小写 推荐大写
34. RF特性—循环
Test Case Action Argument Argument Argument Arguments
Example 1 :FOR ${animal} IN cat dog
Log ${animal}
Log 2nd
keyword
Log Outside
loop
Example 2 :FOR ${var} IN one two
... three four five six
... seven
Log ${var}
35. RF特性—循环
Test Case Action Argument Argument Argument Arguments
Example :FOR ${element} IN @{ELEMENTS}
Start Element ${element}
Test Case Action Argument Argument Argument
Exit Example :FOR ${var} IN @{SOME LIST}
Run Keyword If '${var}' == 'EXIT' Exit For Loop
Do Something ${var}
Test Case Action Argument Argument Argument Argument
Example Repeat Keyword 5 Some Keyword arg1 arg2
Repeat Keyword 42 times My Keyword
Repeat Keyword ${var} Another KW argument
47. pybot --argumentfile default_options.txt --name example my_tests.html
RF特性—创建自己的测试库
Setting Value Value Value Value
Library Remote http://localhost:8270 WITH NAME Example1
Library Remote http://10.0.0.42:7777 WITH NAME Example2
51. pybot --argumentfile default_options.txt --name example my_tests.html
For more information
http://code.google.com/p/robotframework/
http://robotframework.googlecode.com/hg/doc/quickstart/quickstart.html
http://www.virtuousprogrammer.com/?p=264
http://code.google.com/p/robotframework/wiki/UserGuide
http://code.google.com/p/robotframework/wiki/PythonTutorial