accessing static class variables with robotframework?

岁酱吖の 提交于 2019-12-07 05:09:27

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.

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
Tomasz

You should add ROBOT_LIBRARY_SCOPE = 'GLOBAL' to MyClass. If not Get Library Instance will create second instance of the MyClass.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!