Robot 测试框架

从 github 上可知 robotframework 是一个自动化测试的框架。在计算机科学中,框架是帮助方便实现一类事情的软件。所以 robotframework 就是帮助我们实现测试自动化的软件。
https://github.com/robotframework/robotframework

安装方法
# pip install robotframework

所以 robotframework 被实现为一个 python 的软件模块。

例 Hello world
#cat a.robot
*** Settings ***
Library    HelloWorld.py

*** Test Cases ***
HelloWorld
    hello_world
#cat HelloWorld.py
def hello_world():
    print("HELLO WORLD!")
# robot a.robot
==============================================================================
A
==============================================================================
HelloWorld                                                            | PASS |
------------------------------------------------------------------------------
A                                                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  /opt2/foo/robot-example/helloworld/output.xml
Log:     /opt2/foo/robot-example/helloworld/log.html
Report:  /opt2/foo/robot-example/helloworld/report.html
例 1+2 = 3
# cat a.robot
*** Test Cases ***
Example 1
    ${a} =   Evaluate    1+2
    ${b} =   Convert To Integer    3
    Should Be Equal    ${a}    ${b}
# robot a.robot
==============================================================================
A
==============================================================================
Example 1                                                             | PASS |
------------------------------------------------------------------------------
A                                                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  /opt2/foo/robot-example/buildin1/output.xml
Log:     /opt2/foo/robot-example/buildin1/log.html
Report:  /opt2/foo/robot-example/buildin1/report.html
例 run command
# cat a.robot
*** Settings ***
Library    OperatingSystem

*** Test Cases ***
Example
    ${out} =     Run     ls
# robot a.robot
==============================================================================
A
==============================================================================
Example                                                               | PASS |
------------------------------------------------------------------------------
A                                                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  /opt2/foo/robot-example/run/output.xml
Log:     /opt2/foo/robot-example/run/log.html
Report:  /opt2/foo/robot-example/run/report.html

在log.html中,可以看到:


Robot 测试框架_第1张图片
image.png
例 if-else
# cat a.robot
*** Test Cases ***
Example
    ${rc} =    Set Variable    ${0}
    Run Keyword If    ${rc} == 0    LOG   "Equal ZERO"
    ...    ELSE IF    ${rc} > 0    LOG   "More than ZERO"
    ...    ELSE    LOG    "Less than ZERO"
# robot a.robot
==============================================================================
A
==============================================================================
Example                                                               | PASS |
------------------------------------------------------------------------------
A                                                                     | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output:  /opt2/foo/robot-example/if-else/output.xml
Log:     /opt2/foo/robot-example/if-else/log.html
Report:  /opt2/foo/robot-example/if-else/report.html

试着给rc赋值 1, -1,看看log.html有什么不同?

例 string
# cat a.robot
*** Settings ****
Library    String

*** Test Cases ***
Example 1
    ${str1} =    Catenate    Hello    World
    Should Be Equal As Strings    ${str1}    Hello World

    ${str1} =    Replace String    ${str1}    Hello    Hi
    Should Be Equal    ${str1}    Hi World

Example 2
    ${str2} =    Set Variable    hello
    Should Be True    '${str2}' == 'hello'
# robot a.robot
==============================================================================
A
==============================================================================
Example 1                                                             | PASS |
------------------------------------------------------------------------------
Example 2                                                             | PASS |
------------------------------------------------------------------------------
A                                                                     | PASS |
2 critical tests, 2 passed, 0 failed
2 tests total, 2 passed, 0 failed
==============================================================================
Output:  /opt2/foo/robot-example/string/output.xml
Log:     /opt2/foo/robot-example/string/log.html
Report:  /opt2/foo/robot-example/string/report.html
参考

http://hereberobots.blogspot.fi/2010/10/hello-world-robot-framework-library.html

https://github.com/maartenvds/robot-framework-examples/blob/master/examples/arguments_in_keyword_names.txt

https://github.com/jspringbot/sample-standard/blob/master/src/test/robotframework/acceptance/built-in-samples.txt

你可能感兴趣的:(Robot 测试框架)