使用python关键字,如dict,list,在机器人框架内键入

时间:2015-03-29 08:29:55

标签: testing robotframework

a  = {}
if type(a) == dict:
    #read using dictionary keys.
else:
    #treat it as a list   

如何将python代码迁移到机器人框架。我试过这个,

${type_obj}=     Evaluate   type(${a})
${type_bool}=    Evaluate   ${type_obj} == dict 
Run Keyword If   ${type_bool}==1    DictHandler
Run Keyword If   ${type_bool}==0    ListHandler

但它刚刚因语法错误而崩溃,

Evaluating expression '<type 'dict'> == dict' failed: SyntaxError: invalid syntax (<string>, line 1)

问题是,机器人将python的dict关键字视为字符串。那么,我如何在机器人内检查变量的类型?

1 个答案:

答案 0 :(得分:0)

${type_obj}=    Evaluate    type(${a})
Run Keyword If    'dict' in '${type_obj}'    DictHandler
...    ELSE    ListHandler