繁体   English   中英

使用Robot Framework从Python中的方法返回值

[英]Return Value from Method in Python using Robot Framework

所以可以说我在python中有这个方法

def get_data(notificaition):
    print("Notification Recived: ", notificaition)

然后我有另一种方法来接收一个事件并获取该事件的值。

def verify_singal_r():
    with Session() as session:
        connection = Connection("http://example/signalr", session)
        print(connection)
        logging.info("got the connection")
        presenceservice = connection.register_hub('MyHub')
        connection.start()
        def print_error(error):
            print('error: ', error)


        connection.error += print_error

        # TODO: NEED TO ADD POST REQUEST HERE
        presenceservice.client.on('Notified', get_data)
        connection.wait(10)

关键字Verify_Signal运行后,我会得到所需的值并将其打印到控制台上

如何在机器人框架中使用get_data的值?

我试图简单地使用

*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data

但这不起作用,因为get_data需要一个参数。

你的职能

def get_data(notificaition):
    print("Notification Recived: ", notificaition)

期待一个论点

但是,当您在机器人框架中调用此命令时

*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data

您没有提供任何参数。

您可以尝试这样的事情

*** Variables ***
${notification}    Test
*** Test Cases ***

Get Event Back
     verify_singal_r
     get_data    ${notification}

这样可以解决您的问题。

你的方法

def get_data(notificaition):
    print("Notification Recived: ", notificaition)

不返回任何内容,因此robot框架关键字也不会返回任何内容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM