可以在 python 方法中多次使用 @keyword 装饰器,以便在机器人框架中使用

Is is possible to use the @keyword decorator more than once on a python method for use in the robot framework

是否可以在外部 python 库中设置超过 1 个 @keyword 装饰器以用于机器人框架 例如

from robot.api.deco import keyword
class TestLib:

    @keyword(name = 'Keyword1 check ${expected_data}')
    @keyword(name = 'This is keyword2 ${expected_data}')
    def check_returns_expected_data(self, expected_data):
        '''
        :param expected_data: string
        '''
        print expected_data

不,你不能调用它两次。或者更准确地说,您可以调用它两次,但最终仍然只有一个关键字。这个装饰器不创建关键字,它只是在被装饰的函数上设置元数据。

尝试以下操作:

from robot.api.deco import keyword
class TestLib:

    @keyword(name = 'Keyword1 check ${expected_data}')
    def check_returns_expected_data1(self, expected_data):
        self._check_returns_expected_data(expected_data)

    @keyword(name = 'This is keyword2 ${expected_data}')
    def check_returns_expected_data2(self, expected_data):
        self._check_returns_expected_data(expected_data)

    def _check_returns_expected_data(self, expected_data):
        '''
        :param expected_data: string
        '''
        print expected_data