![](/img/trans.png)
[英]How to import the methods of two different classes from the same python file in the Robot Framework?
[英]Import functions from python classes located in python file into Robot Framework
考虑我的项目有这个文件层次结构:
Resources
python_file.py
包含两个类: FirstClass
和SecondClass
Tests
test_suite.robot
这是它们的样子
class FirstClass:
def my_method:
pass
class SecondClass:
variable = {
key1: value1,
key2: value
}
首先,我想通过使用相对路径导入整个 class FirstClass
在.robot
文件中使用my_method
。
其次,我想通过以某种方式(也使用相对路径)导入这个 class 来使用SecondClass
中的字典。
这在射频中可能吗?
提前致谢。
虽然 class 可能无法直接访问,但可以使用 python 中的对象/实例访问其方法。 为此,在您的设置中,您必须添加 python 文件 -
*** Settings ***
Library ../Resources/python_file.py
现在在您的测试用例中,您可以像任何其他关键字一样调用 function,尽管建议使用文件名以及防止编译器混淆,如下所示
*** Test Cases ***
${result}= python_file.foo #Calls the new function foo that calls my_method
并在 python_file.py 中创建另一个方法 -
def foo():
obj = FirstClass()
return obj.my_method()
或者
def bar():
return SecondClass.variable
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.