Robotframework 入门教程(三)

来源:互联网 发布:湖南纳米娱乐网络 编辑:程序博客网 时间:2024/05/20 11:25
==关键字==

RF中很关键的概念keyword,其实就是类似python中的方法。修改我们的demo.robot如下,
*** Settings ***[Documentation]    Example test cases using the keyword-driven testing approach.*** Variables ***${var1}          1+2+3@{list1}           a    b    c    ${var1}&{dict1}          key1=sf   key2=${list1}*** Test Cases ***First Case    Log to console    ${var1}        Log to console    ${list1}        Log to console    ${dict1}   Second Case    Calculate and Check Equals    ${var1}    ${6}Third Case    Calculate and Check Equals    ‘i’*3    iii*** Keywords ***Calculate and Check Equals    [Arguments]    ${expression}    ${expected}    ${res}=    Evaluate     ${expression}    Should Be Equal    ${res}     ${expected}

这个很好理解,就是定义一个Calcalate and Check方法两个参数,
相当于python中这样的一个方法:
def calculate_and_check_equals(expression, expected):    res = eval(expression)    assert res==expected

second case中调用这个方法。关键字中如果有返回值,用[return] 关键字来表示,比如我们的关键字需要返回表达式的计算结果,就在最后加一行
[return]    ${res}
这就是一个完整的testcase file了,包含了Settings,Variables,Test CasesKeywords四个表。
Setting表用来导入Library,Resource, Variables,还有一些测试流程相关的东西,后面讲。

0 0
原创粉丝点击