【问题标题】:accessing robot variables inside custom functions访问自定义函数中的机器人变量
【发布时间】:2020-08-03 03:21:42
【问题描述】:

我使用正常工作的机器人框架创建了一个非常简单的自定义库,我想在机器人测试和自定义库中的函数之间传递数据

是否可以将机器人框架测试文件 test 中的值发送到自定义 python 函数?

目前我有以下:

关键字

Get Name and Send Email
  ${n}  get text  id=name
  run my code

然后:

自定义库

def run_my_code(self):
    name = "insert name from robot var"

我想使用 ${n} 中存储的值作为函数内部的 name 变量名

非常感谢任何帮助 谢谢 詹姆斯

【问题讨论】:

    标签: python robotframework


    【解决方案1】:

    如果你想传入它,最简单的解决方案是让它成为一个参数:

    Get Name and Send Email
      ${n}  get text  id=name
      run my code  ${n}
    

    和python代码:

    def run_my_code(self, n):
        name = f"n is {n}"
    

    或者,您可以使用内置关键字Get Variable Value

    from robot.libraries.BuiltIn import BuiltIn
    ...
    def run_my_code(self):
        value = BuiltIn().get_variable_value("${the variable}")
        ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      • 2011-06-23
      • 2014-02-10
      • 2017-05-07
      • 2018-07-31
      • 2015-05-15
      • 1970-01-01
      相关资源
      最近更新 更多