来自机器人框架的内部嵌套类访问 [英] Inner nested class access from robot framework
问题描述
机器人 - 3.1.1Python - 3.7.3
Robot - 3.1.1 Python - 3.7.3
我想从机器人框架访问嵌套内部类中编写的方法.
I wanted to access method that are written in nested inner class from robot framework.
机器人:
*** Settings ***
Library ../***/***/***/OrderList.py
*** Keywords ***
Click from order
click_order
Python:
class OrderList():
pass
class Ordertable(OrderList):
def click_order(self):
foo
我在运行上述机器人套件时遇到以下错误.
I am getting below error while running the above robot suite.
No keyword with name 'click_order' found.
如果我将 click_order 方法移动到父类 (OrderList) 下,如下所示,那么机器人可以识别.
If I move the click_order method under parent class (OrderList) like below, then robot could recognize.
class OrderList():
def click_order(self):
foo
class Ordertable(OrderList):
pass
有人可以帮助我了解机器人套件需要哪些更改才能调用嵌套的内部类方法吗?
Could someone help me as to what changes required at robot suite to make a call to nested inner class methods?
推荐答案
这里是一个关于如何将类作为库而不是整个 python 文件导入的示例:
Here is an example about how to import a class as a library and not the whole python file:
- 在名为
tests
的文件夹中有一个 test.robot 和一个 OrderList.py 文件. OrderList.py:
- In a folder named
tests
there is a test.robot and an OrderList.py file. OrderList.py:
class OrderList():
pass
class Ordertable(OrderList):
def click_order(self):
print('foo')
test.robot:
test.robot:
*** Settings ***
Library OrderList.Ordertable
*** Test Cases ***
AA
click order
使用以下命令从 tests
文件夹的父文件夹启动它:robot --pythonpath .\tests\ --test AA .\tests\test.robot
Launch it with the following command from the parent folder of the tests
folder: robot --pythonpath .\tests\ --test AA .\tests\test.robot
结果:
PS prompt> robot --pythonpath .\tests\ --test AA .\tests\test.robot
==============================================================================
Test
==============================================================================
AA | PASS |
------------------------------------------------------------------------------
Test | PASS |
1 critical test, 1 passed, 0 failed
1 test total, 1 passed, 0 failed
==============================================================================
Output: C:\Users\myuser\output.xml
Log: C:\Users\myuser\log.html
Report: C:\Users\myuser\report.html
这篇关于来自机器人框架的内部嵌套类访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!