Robot Framework - 查询返回的关键字类型

时间:2017-01-20 15:28:56

标签: python types robotframework keyword

是否有查询返回的关键字变量类型的方法? 尝试调试一些脚本,对于像Python type(my_variable)这样的东西非常有用吗?

1 个答案:

答案 0 :(得分:2)

假设您使用的是机器人版本2.9或更高版本,您可以使用Evaluate关键字来利用评估variable substitution来使用python的type(myvariable)

例如:

*** Keywords ***
keyword that returns an int
    ${result}=  set variable  ${42}
    [return]    ${result}

keyword that returns a list
    ${result}=    create list   one  two  three
    [return]    ${result}

keyword that returns a string
    ${result}=    set variable  foo
    [return]    ${result}

*** Test Cases ***
Example
    ${result1}=    keyword that returns an int
    @{result2}=    keyword that returns a list
    ${result3}=    keyword that returns a string

    ${type1}=    evaluate    type($result1)
    ${type2}=    evaluate    type($result2)
    ${type3}=    evaluate    type($result3)

    should be equal as strings    ${type1}    <type 'int'>
    should be equal as strings    ${type2}    <type 'list'>
    should be equal as strings    ${type3}    <type 'unicode'>