• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Rf介绍
 

Rf介绍

on

  • 495 views

 

Statistics

Views

Total Views
495
Views on SlideShare
495
Embed Views
0

Actions

Likes
1
Downloads
13
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Rf介绍 Rf介绍 Presentation Transcript

    • An introduction toRobot Framework 李亚飞/louieli 00185421 2012.09.06 v2.0
    • 目录RF是什么RF特性介绍DEMO
    • 好的测试框架应具备1.易用2.稳定3.方便扩展4.可以很好的组织用例5.测试执行6.灵活性7.调试8.日志9.报告10.框架支持工具
    • 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 remoteinterface● Open source – Apache 2.0 license – Sponsored by Nokia Siemens Networks – Active development and growing community – Hosted on Google Code
    • RF框架
    • RF特性—测试用例组成Table name Used for AliasesSetting table 1) Importing test libraries, resource Setting, Settings, Metadata files and variable files 2) Defining metadata for test suites and test casesVariable table Defining variables that can be used elsewhere Variable, Variables in the test dataTest case table Creating test cases from available keywords Test Case, Test CasesKeyword table Creating user keywords from existing lower- Keyword, Keywords, User level keywords Keyword, User Keywords
    • RF特性—简单易用的表格语法Test Case Action Argument ArgumentValid Login Open Login Page Input Name demo Input Password mode Submit Credentials Welcome Page Should Be OpenSetting Variables Do Something first second argument argument ${value} = Get Some Value Should Be Equal ${value} Expected value
    • RF特性—支持多种文件格式html格式Test Case Action Argument ArgumentMy Test [Documentation] Example test Log ${MESSAGE} My Keyword /tmpAnother Test Should Be Equal ${MESSAGE} Hello, world!
    • RF特性—支持多种文件格式 *Setting* *Value* *Value* *Value* Library OperatingSystemTSV 格式 *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
    • RF特性—支持多种文件格式文本格式
    • RF特性—支持多种文件格式reStructuredText format 可以方便的用python读取,不常用
    • RF特性—支持多种用例风格Keyword-driven style 前面已经讲过了
    • RF特性—支持多种用例风格Data-driven styleTest Case User Name PasswordInvalid Password [Template] Login with invalid credentials should fail invalid ${VALID PASSWORD} ${VALID USER} invalid invalid whatever ${EMPTY} ${VALID PASSWORD} ${VALID USER} ${EMPTY} ${EMPTY} ${EMPTY}
    • RF特性—支持多种用例风格Data-driven style
    • RF特性—支持多种用例风格Behavior-driven styleTest Case StepValid Login Given login page is open When valid username and password are inserted and credentials are submitted Then welcome page should be open
    • RF特性—灵活的用例组织目录是Test Suite文件是Test Suite文件中Test Cases部分才是真正的Test Case
    • RF特性—灵活的用例组织Initialization files
    • RF特性—Variables1.用例中的测试数据经常变动2.用例需要跨平台、跨浏览器3.需要更复杂的对像,而不仅仅是数字或字符串4.不同关键字之间、测试库之间、用例之间的通信5.用例中需要操作的值很长很复杂
    • RF特性—VariablesVariable 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}
    • 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 variablesVariable 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.
    • RF特性—VariablesVariable 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
    • 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 tablesvariables 2. imported from resource and variable filesfrom arguments passed to them 3. BuiltIn keyword Set Suite Variableand return valuesfrom the keywords they use 4. test suite scope is not recursive推荐小写 推荐大写
    • RF特性—自定义关键字
    • RF特性—Resource and Variable files 通过Resource files 可以很方便的共享测试设置、公 共变量、用户自定义关键字。 Variable files 提供了更强大的机制,复杂变量的创 建变得如此简单。Variable files被视为python 代码, 所以想创建什么就创建什么。
    • RF特性—Resource filesImporting resource filesSetting Value ValueResource myresources.htmlResource ../data/resources.htmlResource ${RESOURCES}/common.tsvResource ../common_resource.txt
    • RF特性—Resource files
    • RF特性—Variable filesImporting a variable fileSetting Value Value ValueVariables myvariables.pyVariables ../data/variables.pyVariables ${RESOURCES}/common.pyVariables taking_arguments.py arg1 ${ARG2}Command line--variablefile myvariables.py--variablefile path/variables.py--variablefile /absolute/path/common.py--variablefile taking_arguments.py:arg1:arg2
    • RF特性—Variable files 导入这段代码就会得到 AREA1和AREA2两个变量
    • RF特性—Variable filesExtended variable syntax
    • RF特性—Variable filesExtended variable syntax 1.搜索全名变量(OBJECT.name),若没找到则启用扩展变量语法 2.创建一个基本变量${OJBECT} 3.搜索变量OBJECT,若没找到,抛异常,用例失败 4.大括号中的内容作为python代码执行,若执行出错, 抛异常,用例失败 5.设置扩展变量的值python代码的执行结果
    • RF特性—Variable filesExtended variable assignment
    • RF特性—Variable filesExtended variable assignment 1.要赋值的变量(${OBJECT.age})必须是标量,变量名字必须包含至少一个点。 否则按普通赋值处理 2.如果要赋值的变量(${OBJECT.age})已经存在,用新值覆盖旧值 3.创建基本变量${OBJECT} 4.创建属性变量name 5.搜索变量OBJECT,若没找到,${OBJECT.age}按普通赋值处理 6.如果找到的OBJECT变量是string或number,扩展语法不启用, ${OBJECT.age}按普通赋值处理 7.如果以上6步全部满足,设置属性变量。如果设置失败,抛异常,用例失败
    • RF特性—循环Test Case Action Argument Argument Argument ArgumentsExample 1 :FOR ${animal} IN cat dog Log ${animal} Log 2nd keyword Log Outside loopExample 2 :FOR ${var} IN one two ... three four five six ... seven Log ${var}
    • RF特性—循环Test Case Action Argument Argument Argument ArgumentsExample :FOR ${element} IN @{ELEMENTS} Start Element ${element}Test Case Action Argument Argument ArgumentExit Example :FOR ${var} IN @{SOME LIST} Run Keyword If ${var} == EXIT Exit For Loop Do Something ${var}Test Case Action Argument Argument Argument ArgumentExample Repeat Keyword 5 Some Keyword arg1 arg2 Repeat Keyword 42 times My Keyword Repeat Keyword ${var} Another KW argument
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—测试执行pybot [options] datasourcesjybot [options] datasourcesinterpreter /path/to/robot/runner.py [options] datasourcesjava -jar robotframework-<version>.jar [options] datasourcesjybot --include smoke --variable HOST:10.0.0.42 path/to/tests/pybot --variable BROWSER:IE --name IE --log none --report none --output out/ie.xml loginpybot --argumentfile default_options.txt --name examplemy_tests.html
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—测试执行--test Example--test mytest --test yourtest--test example*--test mysuite.mytest--test *.suite.mytest--suite example-??--suite mysuite --test mytest --test your*--suite parent.child --suite myhouse.myhousemusic --test jack*--include example--exclude not_ready--include regression --exclude long_lasting
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—测试执行--xunitfile 生成Xunit compatiable result file加时间戳pybot --timestampoutputs --log mylog.html --report NONE tests.html设置titlepybot --logtitle Smoke_Test_Log --reporttitle Smoke_Test_Report --include smoke my_tests/设置颜色--reportbackground blue:red--reportbackground green:yellow:red--reportbackground #00E:#E00
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—RIDE
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—丰富的测试库
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—创建自己的测试库 Python Java Remote library Any languages Static API Hybrid API Dynamic API
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—创建自己的测试库
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—创建自己的测试库
    • 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
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—Listener Interface
    • pybot --argumentfile default_options.txt --name example my_tests.html RF特性—活跃的社区
    • pybot --argumentfile default_options.txt --name example my_tests.html DEMO
    • 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