【问题标题】:Use python keywords like dict, list, type inside robot framework在机器人框架内使用 dict、list、type 等 python 关键字
【发布时间】:2015-06-02 08:11:34
【问题描述】:
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 关键字视为字符串。那么,如何检查机器人内部变量的类型呢?

【问题讨论】:

    标签: testing robotframework


    【解决方案1】:
    ${type_obj}=    Evaluate    type(${a})
    Run Keyword If    'dict' in '${type_obj}'    DictHandler
    ...    ELSE    ListHandler
    

    【讨论】:

      猜你喜欢
      • 2013-11-08
      • 2016-01-03
      • 2015-10-14
      • 2019-06-11
      • 2017-12-19
      • 2020-11-06
      • 2020-08-30
      • 2021-01-02
      • 2021-08-15
      相关资源
      最近更新 更多