【发布时间】:2017-06-05 15:32:46
【问题描述】:
有没有办法查询返回的关键字变量类型?
尝试调试一些脚本,如果有像 Python type(my_variable) 这样可用的东西真的很有用吗?
【问题讨论】:
标签: python types robotframework keyword
有没有办法查询返回的关键字变量类型?
尝试调试一些脚本,如果有像 Python type(my_variable) 这样可用的东西真的很有用吗?
【问题讨论】:
标签: python types robotframework keyword
假设您使用的是机器人版本 2.9 或更高版本,您可以使用 Evaluate 关键字通过利用 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'>
【讨论】:
type 命令返回信息,这正是您在问题中要求的信息。当然,您可以在使用type 或其他任何内容的python 中编写自己的关键字,并将结果转换为您的测试可用的内容。