使用机器人框架访问静态类变量? [英] accessing static class variables with robotframework?
问题描述
是否可以从加载到机器人框架中的库中访问静态类变量?
Is it possible to access static class variables from a library loaded into robot framework?
例如,假设我在我的 .robot 文件中包含以下 python 库:
For example, say I include the following python library in my .robot file:
foo = 'value'
class MyClass(self):
bar = 'value'
在包含它的 .robot 文件中有没有办法引用 foo 或 bar?
Is there a way in the .robot file that included it to refer to foo or bar?
推荐答案
您可以通过使用 获取库实例,然后使用 扩展变量语法 以获取值.
You can get at these by getting a reference to the raw python module with Get Library Instance, and then use extended variable syntax to get the values.
例如,考虑一个名为 MyLibrary.py 的库:
For example, consider a library named MyLibrary.py:
# MyLibrary.py
foo = "this is foo"
class MyClass(object):
bar = "this is bar"
您可以使用获取库实例 获取库的句柄:
You can access foo and bar by using Get Library Instance to get a handle to the library:
*** Settings ***
| Library | MyLibrary.py
*** Test Cases ***
| Example of accessing variables in a library
| | ${lib}= | Get Library Instance | MyLibrary
| |
| | Should be equal as strings | ${lib.foo} | this is foo
| | Should be equal as strings | ${lib.MyClass.bar} | this is bar
这篇关于使用机器人框架访问静态类变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!